39 template <timestamp_type T>
42 template <timestamp_type T>
104 template <timestamp_type T>
176 template <
class... Args>
179 :
base_type(create_proxy(std::forward<Args>(args)...))
180 , m_timezone(get_timezone(this->get_arrow_proxy()))
181 , m_data_access(this->get_arrow_proxy(), DATA_BUFFER_INDEX)
185 template <input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
187 const date::time_zone* timezone,
188 std::initializer_list<inner_value_type> init,
189 std::optional<std::string_view> name = std::nullopt,
190 std::optional<METADATA_RANGE> metadata = std::nullopt
192 :
base_type(create_proxy(timezone, init,
std::move(name),
std::move(metadata)))
193 , m_timezone(timezone)
194 , m_data_access(this->get_arrow_proxy(), DATA_BUFFER_INDEX)
215 template <input_metadata_container METADATA_RANGE>
217 const date::time_zone* timezone,
219 std::optional<std::string_view> name = std::nullopt,
220 std::optional<METADATA_RANGE> metadata = std::nullopt
226 [[nodiscard]]
static auto create_proxy(
227 const date::time_zone* timezone,
230 std::optional<std::string_view> name = std::nullopt,
231 std::optional<METADATA_RANGE> metadata = std::nullopt
235 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
236 requires std::convertible_to<std::ranges::range_value_t<R>, T>
237 [[nodiscard]]
static auto create_proxy(
238 const date::time_zone* timezone,
240 std::optional<std::string_view> name = std::nullopt,
241 std::optional<METADATA_RANGE> metadata = std::nullopt
244 template <
typename U, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
245 requires std::convertible_to<U, T>
247 const date::time_zone* timezone,
249 const U& value = U{},
250 std::optional<std::string_view> name = std::nullopt,
251 std::optional<METADATA_RANGE> metadata = std::nullopt
256 std::ranges::input_range VALUE_RANGE,
257 validity_bitmap_input VALIDITY_RANGE,
258 input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
259 requires(std::convertible_to<std::ranges::range_value_t<VALUE_RANGE>, T>)
260 [[nodiscard]]
static arrow_proxy create_proxy(
261 const date::time_zone* timezone,
264 std::optional<std::string_view> name = std::nullopt,
265 std::optional<METADATA_RANGE> metadata = std::nullopt
269 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
270 requires std::is_same_v<std::ranges::range_value_t<R>, nullable<T>>
271 [[nodiscard]]
static arrow_proxy create_proxy(
272 const date::time_zone* timezone,
274 std::optional<std::string_view> name = std::nullopt,
275 std::optional<METADATA_RANGE> metadata = std::nullopt
284 template <mpl::iterator_of_type<typename timestamp_array<T>::inner_value_type> InputIt>
287 const auto input_range = std::ranges::subrange(first, last);
288 const auto values = input_range
289 | std::views::transform(
292 return v.get_sys_time().time_since_epoch();
295 const size_t idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
296 m_data_access.insert_values(idx, values.begin(), values.end());
302 void assign(
const T& rhs,
size_type index);
305 [[nodiscard]]
static const date::time_zone* get_timezone(
const arrow_proxy& proxy);
307 const date::time_zone* m_timezone;
308 details::primitive_data_access<inner_value_type_duration> m_data_access;
319 template <timestamp_type T>
322 , m_timezone(rhs.m_timezone)
323 , m_data_access(this->get_arrow_proxy(), DATA_BUFFER_INDEX)
327 template <timestamp_type T>
331 m_timezone = rhs.m_timezone;
332 m_data_access.reset_proxy(this->get_arrow_proxy());
336 template <timestamp_type T>
339 , m_timezone(rhs.m_timezone)
340 , m_data_access(this->get_arrow_proxy(), DATA_BUFFER_INDEX)
344 template <timestamp_type T>
348 m_timezone = rhs.m_timezone;
349 m_data_access.reset_proxy(this->get_arrow_proxy());
353 template <timestamp_type T>
354 const date::time_zone* timestamp_array<T>::get_timezone(
const arrow_proxy& proxy)
356 const std::string_view timezone_string = proxy.
format().substr(4);
357 return date::locate_zone(timezone_string);
360 template <timestamp_type T>
363 , m_timezone(get_timezone(this->get_arrow_proxy()))
364 , m_data_access(this->get_arrow_proxy(), DATA_BUFFER_INDEX)
368 template <timestamp_type T>
369 template <val
idity_bitmap_input R, input_metadata_container METADATA_RANGE>
370 auto timestamp_array<T>::create_proxy(
371 const date::time_zone* timezone,
374 std::optional<std::string_view> name,
375 std::optional<METADATA_RANGE> metadata
378 const auto size = data_buffer.size();
383 format += timezone->name();
399 std::vector<buffer<uint8_t>> buffers(2);
400 buffers[0] = std::move(bitmap).extract_storage();
401 buffers[1] = std::move(data_buffer).extract_storage();
405 static_cast<std::int64_t
>(size),
406 static_cast<int64_t
>(null_count),
414 return arrow_proxy(std::move(arr), std::move(schema));
417 template <timestamp_type T>
418 template <std::ranges::input_range VALUE_RANGE, val
idity_bitmap_input VALIDITY_RANGE, input_metadata_container METADATA_RANGE>
419 requires(std::convertible_to<std::ranges::range_value_t<VALUE_RANGE>, T>)
421 const date::time_zone* timezone,
422 VALUE_RANGE&& values,
423 VALIDITY_RANGE&& validity_input,
424 std::optional<std::string_view> name,
425 std::optional<METADATA_RANGE> metadata
428 const auto range = values
429 | std::views::transform(
432 return v.get_sys_time().time_since_epoch().count();
440 std::move(data_buffer),
441 std::forward<VALIDITY_RANGE>(validity_input),
447 template <timestamp_type T>
448 template <
typename U, input_metadata_container METADATA_RANGE>
449 requires std::convertible_to<U, T>
451 const date::time_zone* timezone,
454 std::optional<std::string_view> name,
455 std::optional<METADATA_RANGE> metadata
460 return create_proxy(timezone, std::move(data_buffer), std::move(name), std::move(metadata));
463 template <timestamp_type T>
464 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE>
465 requires std::convertible_to<std::ranges::range_value_t<R>, T>
467 const date::time_zone* timezone,
469 std::optional<std::string_view> name,
470 std::optional<METADATA_RANGE> metadata
474 const auto iota = std::ranges::iota_view{std::size_t(0), n};
475 std::ranges::transform_view iota_to_is_non_missing(
482 return self_type::create_proxy(
484 std::forward<R>(range),
485 std::move(iota_to_is_non_missing),
492 template <timestamp_type T>
493 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE>
494 requires std::is_same_v<std::ranges::range_value_t<R>,
nullable<T>>
496 const date::time_zone* timezone,
498 std::optional<std::string_view> name,
499 std::optional<METADATA_RANGE> metadata
503 | std::views::transform(
509 auto is_non_null = range
510 | std::views::transform(
513 return v.has_value();
516 return self_type::create_proxy(timezone, values, is_non_null, std::move(name), std::move(metadata));
519 template <timestamp_type T>
520 void timestamp_array<T>::assign(
const T& rhs, size_type index)
523 m_data_access.value(index) = rhs.get_sys_time().time_since_epoch();
526 template <timestamp_type T>
527 void timestamp_array<T>::assign(T&& rhs, size_type index)
530 m_data_access.value(index) = rhs.get_sys_time().time_since_epoch();
533 template <timestamp_type T>
534 auto timestamp_array<T>::value(size_type i) -> inner_reference
537 return inner_reference(
this, i);
540 template <timestamp_type T>
541 auto timestamp_array<T>::value(size_type i)
const -> inner_const_reference
544 const auto& val = m_data_access.value(i);
545 using time_duration =
typename T::duration;
546 const auto sys_time = std::chrono::sys_time<time_duration>{val};
547 return T{m_timezone, sys_time};
550 template <timestamp_type T>
551 auto timestamp_array<T>::value_begin() -> value_iterator
553 return value_iterator(functor_type(
this), 0);
556 template <timestamp_type T>
557 auto timestamp_array<T>::value_end() -> value_iterator
559 return value_iterator(functor_type(
this), this->
size());
562 template <timestamp_type T>
563 auto timestamp_array<T>::value_cbegin() const -> const_value_iterator
565 return const_value_iterator(const_functor_type(
this), 0);
568 template <timestamp_type T>
569 auto timestamp_array<T>::value_cend() const -> const_value_iterator
571 return const_value_iterator(const_functor_type(
this), this->
size());
574 template <timestamp_type T>
575 void timestamp_array<T>::resize_values(size_type new_length, inner_value_type value)
577 m_data_access.resize_values(new_length, value.get_sys_time().time_since_epoch());
580 template <timestamp_type T>
581 auto timestamp_array<T>::insert_value(const_value_iterator pos, inner_value_type value, size_type count)
585 const size_t idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
586 m_data_access.insert_value(idx, value.get_sys_time().time_since_epoch(), count);
587 return value_iterator(functor_type(
this), idx);
590 template <timestamp_type T>
591 auto timestamp_array<T>::erase_values(const_value_iterator pos, size_type count) -> value_iterator
594 const size_t idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
595 m_data_access.erase_values(idx, count);
596 return value_iterator(functor_type(
this), idx);
typename base_type::const_bitmap_range const_bitmap_range
typename base_type::bitmap_iterator bitmap_iterator
array_bitmap_base_impl & operator=(const array_bitmap_base_impl &)
typename base_type::iterator_tag iterator_tag
typename base_type::const_bitmap_iterator const_bitmap_iterator
std::conditional_t< is_mutable, mutable_array_base< D >, array_crtp_base< D > > base_type
typename base_type::bitmap_const_reference bitmap_const_reference
typename base_type::bitmap_type bitmap_type
typename base_type::difference_type difference_type
Proxy class over ArrowArray and ArrowSchema.
SPARROW_API const std::string_view format() const
constexpr size_type null_count() const noexcept
The nullable class models a value or a reference that can be "null", or missing, like values traditio...
A view that repeats a value a given number of times.
timestamp_array(Args &&... args)
Construct a timestamp array with the passed range of values and an optional bitmap.
timestamp_array self_type
typename base_type::bitmap_range bitmap_range
nullable< inner_value_type > value_type
inner_value_type_duration::rep buffer_inner_value_type
mutable_array_bitmap_base< self_type > base_type
timestamp_array(const timestamp_array &rhs)
typename base_type::size_type size_type
typename base_type::bitmap_type bitmap_type
typename inner_types::inner_reference inner_reference
typename base_type::difference_type difference_type
timestamp_array & operator=(const timestamp_array &rhs)
timestamp_array(timestamp_array &&rhs)
array_inner_types< self_type > inner_types
timestamp_array & operator=(timestamp_array &&rhs)
timestamp_array(arrow_proxy)
typename base_type::const_bitmap_iterator const_bitmap_iterator
typename base_type::const_iterator const_iterator
typename base_type::iterator_tag iterator_tag
typename base_type::const_value_iterator const_value_iterator
typename inner_types::functor_type functor_type
timestamp_array(const date::time_zone *timezone, std::initializer_list< inner_value_type > init, std::optional< std::string_view > name=std::nullopt, std::optional< METADATA_RANGE > metadata=std::nullopt)
pointer_iterator< const buffer_inner_value_type * > buffer_inner_const_value_iterator
typename base_type::iterator iterator
typename base_type::bitmap_const_reference bitmap_const_reference
pointer_iterator< buffer_inner_value_type * > buffer_inner_value_iterator
typename base_type::const_bitmap_range const_bitmap_range
typename base_type::bitmap_iterator bitmap_iterator
nullable< inner_const_reference, bitmap_const_reference > const_reference
typename inner_types::inner_const_reference inner_const_reference
inner_value_type::duration inner_value_type_duration
typename base_type::value_iterator value_iterator
nullable< inner_reference, bitmap_reference > reference
typename base_type::bitmap_reference bitmap_reference
typename inner_types::const_functor_type const_functor_type
typename inner_types::inner_value_type inner_value_type
Implementation of reference to inner type used for layout L.
This buffer class is use as storage buffer for all sparrow arrays.
#define SPARROW_ASSERT_TRUE(expr__)
constexpr std::size_t size(typelist< T... >={})
constexpr bool excludes_copy_and_move_ctor_v
array_bitmap_base_impl< D, true > mutable_array_bitmap_base
Convenient typedef to be used as a crtp base class for arrays using a mutable validity buffer.
ArrowSchema make_arrow_schema(F format, N name, std::optional< M > metadata, std::optional< std::unordered_set< ArrowFlag > > flags, ArrowSchema **children, const CHILDREN_OWNERSHIP &children_ownership, ArrowSchema *dictionary, bool dictionary_ownership)
Creates an ArrowSchema owned by a unique_ptr and holding the provided data.
timestamp< std::chrono::microseconds > timestamp_microsecond
constexpr std::string_view data_type_to_format(data_type type)
timestamp< std::chrono::nanoseconds > timestamp_nanosecond
constexpr InputIt next(InputIt it, Distance n)
timestamp_array< timestamp_second > timestamp_seconds_array
date::zoned_time< Duration, TimeZonePtr > timestamp
constexpr bool is_timestamp_array_v
ArrowArray make_arrow_array(int64_t length, int64_t null_count, int64_t offset, B buffers, ArrowArray **children, const CHILDREN_OWNERSHIP &children_ownership, ArrowArray *dictionary, bool dictionary_ownership)
Creates an ArrowArray.
dynamic_bitset< std::uint8_t > validity_bitmap
timestamp_array< timestamp_nanosecond > timestamp_nanoseconds_array
timestamp< std::chrono::seconds > timestamp_second
validity_bitmap ensure_validity_bitmap(std::size_t size, R &&validity_input)
std::size_t range_size(R &&r)
timestamp< std::chrono::milliseconds > timestamp_millisecond
timestamp_array< timestamp_microsecond > timestamp_microseconds_array
timestamp_array< timestamp_millisecond > timestamp_milliseconds_array
functor_index_iterator< functor_type > value_iterator
functor_index_iterator< const_functor_type > const_value_iterator
timestamp_array< T > self_type
detail::layout_value_functor< self_type, inner_reference > functor_type
detail::layout_value_functor< const self_type, inner_const_reference > const_functor_type
timestamp_reference< self_type > inner_reference
std::random_access_iterator_tag iterator_tag
Base class for array_inner_types specialization.
Traits class that must be specialized by array classes inheriting from array_crtp_base.
Provides compile-time information about Arrow data types.