41 template <timestamp_type T>
44 template <timestamp_type T>
106 template <timestamp_type T>
178 template <
class... Args>
181 :
base_type(create_proxy(std::forward<Args>(args)...))
183 , m_data_access(this->get_arrow_proxy(), DATA_BUFFER_INDEX)
187 template <input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
189 const date::time_zone* timezone,
190 std::initializer_list<inner_value_type> init,
191 std::optional<std::string_view> name = std::nullopt,
192 std::optional<METADATA_RANGE> metadata = std::nullopt
194 :
base_type(create_proxy(timezone, init,
std::move(name),
std::move(metadata)))
195 , m_timezone(timezone)
196 , m_data_access(this->get_arrow_proxy(), DATA_BUFFER_INDEX)
217 template <input_metadata_container METADATA_RANGE>
219 const date::time_zone* timezone,
221 std::optional<std::string_view> name = std::nullopt,
222 std::optional<METADATA_RANGE> metadata = std::nullopt
228 [[nodiscard]]
static auto create_proxy(
229 const date::time_zone* timezone,
232 std::optional<std::string_view> name = std::nullopt,
233 std::optional<METADATA_RANGE> metadata = std::nullopt
237 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
238 requires std::convertible_to<std::ranges::range_value_t<R>, T>
239 [[nodiscard]]
static auto create_proxy(
240 const date::time_zone* timezone,
243 std::optional<std::string_view> name = std::nullopt,
244 std::optional<METADATA_RANGE> metadata = std::nullopt
247 template <
typename U, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
248 requires std::convertible_to<U, T>
250 const date::time_zone* timezone,
252 const U& value = U{},
253 std::optional<std::string_view> name = std::nullopt,
254 std::optional<METADATA_RANGE> metadata = std::nullopt
259 std::ranges::input_range VALUE_RANGE,
260 validity_bitmap_input VALIDITY_RANGE,
261 input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
262 requires(std::convertible_to<std::ranges::range_value_t<VALUE_RANGE>, T>)
263 [[nodiscard]]
static arrow_proxy create_proxy(
264 const date::time_zone* timezone,
267 std::optional<std::string_view> name = std::nullopt,
268 std::optional<METADATA_RANGE> metadata = std::nullopt
272 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
273 requires std::is_same_v<std::ranges::range_value_t<R>, nullable<T>>
274 [[nodiscard]]
static arrow_proxy create_proxy(
275 const date::time_zone* timezone,
277 std::optional<std::string_view> name = std::nullopt,
278 std::optional<METADATA_RANGE> metadata = std::nullopt
281 template <input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
282 [[nodiscard]]
static arrow_proxy create_proxy_impl(
283 const date::time_zone* timezone,
284 u8_buffer<buffer_inner_value_type>&& data_buffer,
285 std::optional<validity_bitmap>&& bitmap_input,
286 std::optional<std::string_view> name = std::nullopt,
287 std::optional<METADATA_RANGE> metadata = std::nullopt
296 template <mpl::iterator_of_type<typename timestamp_array<T>::inner_value_type> InputIt>
299 const auto input_range = std::ranges::subrange(first, last);
300 const auto values = input_range
301 | std::views::transform(
304 return v.get_sys_time().time_since_epoch();
307 const size_t idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
308 m_data_access.insert_values(idx, values.begin(), values.end());
314 void assign(
const T& rhs,
size_type index);
318 const date::time_zone* m_timezone;
319 details::primitive_data_access<inner_value_type_duration> m_data_access;
330 template <timestamp_type T>
333 , m_timezone(rhs.m_timezone)
334 , m_data_access(this->get_arrow_proxy(), DATA_BUFFER_INDEX)
338 template <timestamp_type T>
342 m_timezone = rhs.m_timezone;
343 m_data_access.reset_proxy(this->get_arrow_proxy());
347 template <timestamp_type T>
350 , m_timezone(rhs.m_timezone)
351 , m_data_access(this->get_arrow_proxy(), DATA_BUFFER_INDEX)
355 template <timestamp_type T>
359 m_timezone = rhs.m_timezone;
360 m_data_access.reset_proxy(this->get_arrow_proxy());
364 template <timestamp_type T>
368 , m_data_access(this->get_arrow_proxy(), DATA_BUFFER_INDEX)
372 template <timestamp_type T>
373 template <val
idity_bitmap_input R, input_metadata_container METADATA_RANGE>
374 auto timestamp_array<T>::create_proxy(
375 const date::time_zone* timezone,
378 std::optional<std::string_view> name,
379 std::optional<METADATA_RANGE> metadata
382 const auto size = data_buffer.size();
384 return create_proxy_impl(
393 template <timestamp_type T>
394 template <std::ranges::input_range VALUE_RANGE, val
idity_bitmap_input VALIDITY_RANGE, input_metadata_container METADATA_RANGE>
395 requires(std::convertible_to<std::ranges::range_value_t<VALUE_RANGE>, T>)
396 arrow_proxy timestamp_array<T>::create_proxy(
397 const date::time_zone* timezone,
398 VALUE_RANGE&& values,
399 VALIDITY_RANGE&& validity_input,
400 std::optional<std::string_view> name,
401 std::optional<METADATA_RANGE> metadata
404 const auto range = values
405 | std::views::transform(
408 return v.get_sys_time().time_since_epoch().count();
416 std::move(data_buffer),
417 std::forward<VALIDITY_RANGE>(validity_input),
423 template <timestamp_type T>
424 template <
typename U, input_metadata_container METADATA_RANGE>
425 requires std::convertible_to<U, T>
427 const date::time_zone* timezone,
430 std::optional<std::string_view> name,
431 std::optional<METADATA_RANGE> metadata
436 return create_proxy(timezone, std::move(data_buffer), std::move(name), std::move(metadata));
439 template <timestamp_type T>
440 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE>
441 requires std::convertible_to<std::ranges::range_value_t<R>, T>
443 const date::time_zone* timezone,
446 std::optional<std::string_view> name,
447 std::optional<METADATA_RANGE> metadata
450 std::optional<validity_bitmap> bitmap =
nullable ? std::make_optional<validity_bitmap>(
nullptr, 0)
452 const auto values = range
453 | std::views::transform(
456 return v.get_sys_time().time_since_epoch().count();
460 return self_type::create_proxy_impl(
462 std::move(data_buffer),
470 template <timestamp_type T>
471 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE>
472 requires std::is_same_v<std::ranges::range_value_t<R>,
nullable<T>>
474 const date::time_zone* timezone,
476 std::optional<std::string_view> name,
477 std::optional<METADATA_RANGE> metadata
481 | std::views::transform(
487 auto is_non_null = range
488 | std::views::transform(
491 return v.has_value();
494 return self_type::create_proxy(timezone, values, is_non_null, std::move(name), std::move(metadata));
497 template <timestamp_type T>
498 template <input_metadata_container METADATA_RANGE>
500 const date::time_zone* timezone,
502 std::optional<validity_bitmap>&& bitmap,
503 std::optional<std::string_view> name,
504 std::optional<METADATA_RANGE> metadata
507 const auto size = data_buffer.size();
508 const auto null_count = bitmap.has_value() ? bitmap->
null_count() : 0;
511 format += timezone->name();
515 const std::optional<std::unordered_set<sparrow::ArrowFlag>>
516 flags = bitmap.has_value()
532 std::vector<buffer<uint8_t>> buffers{
534 std::move(data_buffer).extract_storage()
539 static_cast<std::int64_t
>(size),
540 static_cast<int64_t
>(null_count),
548 return arrow_proxy(std::move(arr), std::move(schema));
551 template <timestamp_type T>
552 void timestamp_array<T>::assign(
const T& rhs, size_type index)
555 m_data_access.value(index) = rhs.get_sys_time().time_since_epoch();
558 template <timestamp_type T>
559 void timestamp_array<T>::assign(T&& rhs, size_type index)
562 m_data_access.value(index) = rhs.get_sys_time().time_since_epoch();
565 template <timestamp_type T>
566 auto timestamp_array<T>::value(size_type i) -> inner_reference
569 return inner_reference(
this, i);
572 template <timestamp_type T>
573 auto timestamp_array<T>::value(size_type i)
const -> inner_const_reference
576 const auto& val = m_data_access.value(i);
577 using time_duration =
typename T::duration;
578 const auto sys_time = std::chrono::sys_time<time_duration>{val};
579 return T{m_timezone, sys_time};
582 template <timestamp_type T>
583 auto timestamp_array<T>::value_begin() -> value_iterator
585 return value_iterator(functor_type(
this), 0);
588 template <timestamp_type T>
589 auto timestamp_array<T>::value_end() -> value_iterator
591 return value_iterator(functor_type(
this), this->
size());
594 template <timestamp_type T>
595 auto timestamp_array<T>::value_cbegin() const -> const_value_iterator
597 return const_value_iterator(const_functor_type(
this), 0);
600 template <timestamp_type T>
601 auto timestamp_array<T>::value_cend() const -> const_value_iterator
603 return const_value_iterator(const_functor_type(
this), this->
size());
606 template <timestamp_type T>
607 void timestamp_array<T>::resize_values(size_type new_length, inner_value_type value)
609 m_data_access.resize_values(new_length, value.get_sys_time().time_since_epoch());
612 template <timestamp_type T>
613 auto timestamp_array<T>::insert_value(const_value_iterator pos, inner_value_type value, size_type count)
617 const size_t idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
618 m_data_access.insert_value(idx, value.get_sys_time().time_since_epoch(), count);
619 return value_iterator(functor_type(
this), idx);
622 template <timestamp_type T>
623 auto timestamp_array<T>::erase_values(const_value_iterator pos, size_type count) -> value_iterator
626 const size_t idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
627 m_data_access.erase_values(idx, count);
628 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.
Object that owns a piece of contiguous memory.
storage_type extract_storage() noexcept
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)
SPARROW_API const date::time_zone * get_timezone(const arrow_proxy &proxy)
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)
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.