41 template <decimal_type T>
116 template <decimal_type T>
152 template <decimal_type T>
170 "The storage type must be an integral type of size 4, 8, 16 or 32 bytes"
201 template <
class... Args>
241 std::ranges::input_range VALUE_RANGE,
244 requires std::convertible_to<std::ranges::range_value_t<VALUE_RANGE>,
typename T::integer_type>
245 [[nodiscard]]
static auto create_proxy(
247 VALIDITY_RANGE&& bitmaps,
248 std::size_t precision,
250 std::optional<std::string_view> name = std::nullopt,
251 std::optional<METADATA_RANGE> metadata = std::nullopt
267 std::ranges::input_range NULLABLE_VALUE_RANGE,
270 [[nodiscard]]
static auto create_proxy(
271 NULLABLE_VALUE_RANGE&& range,
272 std::size_t precision,
274 std::optional<std::string_view> name = std::nullopt,
275 std::optional<METADATA_RANGE> metadata = std::nullopt
291 template <std::ranges::input_range VALUE_RANGE, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
292 requires std::is_same_v<std::ranges::range_value_t<VALUE_RANGE>,
typename T::integer_type>
293 [[nodiscard]]
static auto create_proxy(
295 std::size_t precision,
298 std::optional<std::string_view> name = std::nullopt,
299 std::optional<METADATA_RANGE> metadata = std::nullopt
315 template <val
idity_bitmap_input R, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
316 [[nodiscard]]
static auto create_proxy(
319 std::size_t precision,
321 std::optional<std::string_view> name = std::nullopt,
322 std::optional<METADATA_RANGE> metadata = std::nullopt
337 template <input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
338 [[nodiscard]]
static auto create_proxy(
340 std::size_t precision,
343 std::optional<std::string_view> name = std::nullopt,
344 std::optional<METADATA_RANGE> metadata = std::nullopt
359 template <input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
360 [[nodiscard]]
static auto create_proxy_impl(
362 std::size_t precision,
364 std::optional<validity_bitmap> bitmap,
365 std::optional<std::string_view> name = std::nullopt,
366 std::optional<METADATA_RANGE> metadata = std::nullopt
376 static constexpr std::string generate_format(std::size_t precision,
int scale);
412 constexpr void assign(
const T& rhs,
size_type index);
417 static constexpr size_type DATA_BUFFER_INDEX = 1;
426 std::size_t m_precision;
435 template <decimal_type T>
442 const auto format = this->get_arrow_proxy().format();
445 if (format.size() < 2 || format[0] !=
'd' || format[1] !=
':')
447 throw std::runtime_error(
"Invalid format string for decimal array");
451 const auto format_str = format.substr(2);
453 std::stringstream ss;
456 ss >> m_precision >> c >> m_scale;
461 throw std::runtime_error(
"Invalid format string for decimal array");
465 template <decimal_type T>
466 template <std::ranges::input_range VALUE_RANGE, val
idity_bitmap_input VALIDITY_RANGE, input_metadata_container METADATA_RANGE>
467 requires std::convertible_to<std::ranges::range_value_t<VALUE_RANGE>,
typename T::integer_type>
470 VALIDITY_RANGE&& bitmaps,
471 std::size_t precision,
473 std::optional<std::string_view> name,
474 std::optional<METADATA_RANGE> metadata
478 const auto size = u8_data_buffer.
size();
480 return create_proxy_impl(
481 std::move(u8_data_buffer),
490 template <decimal_type T>
491 template <std::ranges::input_range NULLABLE_VALUE_RANGE, input_metadata_container METADATA_RANGE>
494 NULLABLE_VALUE_RANGE&& range,
495 std::size_t precision,
497 std::optional<std::string_view> name,
498 std::optional<METADATA_RANGE> metadata
502 | std::views::transform(
508 auto is_non_null = range
509 | std::views::transform(
512 return v.has_value();
515 return create_proxy(values, is_non_null, precision, scale, std::move(name), std::move(metadata));
518 template <decimal_type T>
519 template <input_metadata_container METADATA_RANGE>
520 auto decimal_array<T>::create_proxy(
522 std::size_t precision,
525 std::optional<std::string_view> name,
526 std::optional<METADATA_RANGE> metadata
529 const size_t size = data_buffer.size();
530 return create_proxy_impl(
531 std::move(data_buffer),
534 nullable ? std::make_optional<validity_bitmap>(
nullptr, size) : std::nullopt,
540 template <decimal_type T>
541 template <std::ranges::input_range VALUE_RANGE, input_metadata_container METADATA_RANGE>
542 requires std::is_same_v<std::ranges::range_value_t<VALUE_RANGE>,
typename T::integer_type>
545 std::size_t precision,
548 std::optional<std::string_view> name,
549 std::optional<METADATA_RANGE> metadata
553 const auto size = u8_data_buffer.
size();
554 return create_proxy_impl(
555 std::move(u8_data_buffer),
558 nullable ? std::make_optional<validity_bitmap>(
nullptr, size) : std::nullopt,
564 template <decimal_type T>
565 template <val
idity_bitmap_input R, input_metadata_container METADATA_RANGE>
566 auto decimal_array<T>::create_proxy(
569 std::size_t precision,
571 std::optional<std::string_view> name,
572 std::optional<METADATA_RANGE> metadata
575 const auto size = data_buffer.size();
577 return create_proxy_impl(
578 std::move(data_buffer),
587 template <decimal_type T>
588 template <input_metadata_container METADATA_RANGE>
589 [[nodiscard]]
auto decimal_array<T>::create_proxy_impl(
590 u8_buffer<storage_type>&& data_buffer,
591 std::size_t precision,
593 std::optional<validity_bitmap> bitmap,
594 std::optional<std::string_view> name,
595 std::optional<METADATA_RANGE> metadata
598 const std::optional<std::unordered_set<sparrow::ArrowFlag>>
599 flags = bitmap.has_value()
603 const auto size = data_buffer.size();
604 const size_t null_count = bitmap.has_value() ? bitmap->
null_count() : 0;
608 generate_format(precision, scale),
618 std::vector<buffer<uint8_t>> buffers(2);
620 buffers[1] = std::move(data_buffer).extract_storage();
624 static_cast<std::int64_t
>(size),
625 static_cast<int64_t
>(null_count),
633 return arrow_proxy(std::move(arr), std::move(schema));
636 template <decimal_type T>
643 template <decimal_type T>
647 const auto ptr = this->get_arrow_proxy().buffers()[DATA_BUFFER_INDEX].template data<const storage_type>();
651 template <decimal_type T>
652 constexpr auto decimal_array<T>::value_begin() -> value_iterator
657 template <decimal_type T>
658 constexpr auto decimal_array<T>::value_end() -> value_iterator
660 return value_iterator(detail::layout_value_functor<self_type, inner_reference>(
this), this->size());
663 template <decimal_type T>
664 constexpr auto decimal_array<T>::value_cbegin() const -> const_value_iterator
669 template <decimal_type T>
670 constexpr auto decimal_array<T>::value_cend() const -> const_value_iterator
672 return const_value_iterator(
678 template <decimal_type T>
679 constexpr void decimal_array<T>::assign(
const T& rhs, size_type index)
682 const auto ptr = this->get_arrow_proxy().buffers()[DATA_BUFFER_INDEX].template data<storage_type>();
683 const auto storage = rhs.storage();
685 const auto scaled_storage = storage
686 *
static_cast<storage_type
>(
687 static_cast<size_t>(std::pow(10, m_scale - rhs.scale()))
689 ptr[index] = scaled_storage;
692 template <decimal_type T>
693 constexpr std::string decimal_array<T>::generate_format(std::size_t precision,
int scale)
695 constexpr std::size_t sizeof_decimal =
sizeof(storage_type);
696 std::string format_str =
"d:" + std::to_string(precision) +
"," + std::to_string(scale);
697 if constexpr (sizeof_decimal != 16)
700 format_str +=
"," + std::to_string(sizeof_decimal * 8);
typename base_type::const_bitmap_range const_bitmap_range
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
constexpr size_type size() const noexcept(!SPARROW_CONTRACTS_THROW_ON_FAILURE)
Returns the number of elements that can be held in currently allocated storage.
Object that owns a piece of contiguous memory.
Array implementation for decimal types.
nullable< inner_const_reference, bitmap_const_reference > const_reference
typename base_type::difference_type difference_type
typename base_type::bitmap_const_reference bitmap_const_reference
array_inner_types< self_type > inner_types
decimal_array(arrow_proxy proxy)
Constructs a decimal array from an arrow proxy.
typename inner_types::const_value_iterator const_value_iterator
nullable< inner_value_type > value_type
typename base_type::const_bitmap_iterator const_bitmap_iterator
typename base_type::bitmap_type bitmap_type
typename base_type::const_bitmap_range const_bitmap_range
typename T::integer_type storage_type
decimal_array< T > self_type
typename inner_types::inner_reference inner_reference
constexpr inner_const_reference value(size_type i) const
Gets a constant reference to the value at the specified index.
typename inner_types::inner_const_reference inner_const_reference
mutable_array_bitmap_base< self_type > base_type
typename inner_types::inner_value_type inner_value_type
typename base_type::size_type size_type
typename base_type::iterator_tag iterator_tag
decimal_array(Args &&... args)
Constructs a decimal array with the given arguments.
constexpr inner_reference value(size_type i)
Gets a mutable reference to the value at the specified index.
typename inner_types::value_iterator value_iterator
storage_type extract_storage() noexcept
Extracts the underlying storage (move operation).
constexpr size_type null_count() const noexcept
Returns the number of bits set to false (null/invalid).
A view that repeats a value a given number of times.
This buffer class is used as storage buffer for all sparrow arrays.
#define SPARROW_ASSERT_TRUE(expr__)
constexpr std::size_t size(typelist< T... >={})
Gets the count of types contained in a typelist.
constexpr bool excludes_copy_and_move_ctor_v
Convenience variable template for excludes_copy_and_move_ctor.
constexpr bool is_type_instance_of_v
Variable template for convenient access to is_type_instance_of.
constexpr bool is_decimal_array_v
Type trait to check if a type is a decimal array.
array_bitmap_base_impl< D, true > mutable_array_bitmap_base
Convenient alias for arrays with mutable validity bitmaps.
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.
decimal_array< decimal< int128_t > > decimal_128_array
Type alias for 128-bit decimal array.
decimal_array< decimal< int32_t > > decimal_32_array
Type alias for 32-bit decimal array.
decimal_array< decimal< int64_t > > decimal_64_array
Type alias for 64-bit decimal array.
decimal_array< decimal< int256_t > > decimal_256_array
Type alias for 256-bit decimal array.
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
Type alias for a validity bitmap using 8-bit storage blocks.
validity_bitmap ensure_validity_bitmap(std::size_t size, R &&validity_input)
Ensures a validity bitmap of the specified size from various input types.
data_type
Runtime identifier of arrow data types, usually associated with raw bytes with the associated value.
functor_index_iterator< detail::layout_value_functor< array_type, inner_reference > > value_iterator
decimal_reference< array_type > inner_reference
std::random_access_iterator_tag iterator_tag
functor_index_iterator< detail::layout_value_functor< const array_type, inner_value_type > > const_value_iterator
decimal_array< T > array_type
bitmap_type::const_reference bitmap_const_reference
nullable< inner_const_reference, bitmap_const_reference > const_reference
Base class for array_inner_types specializations.
Traits class that must be specialized by array implementations.
static constexpr sparrow::data_type get()
Gets the data type for 128-bit decimal.
static constexpr sparrow::data_type get()
Gets the data type for 256-bit decimal.
static constexpr sparrow::data_type get()
Gets the data type for 32-bit decimal.
static constexpr sparrow::data_type get()
Gets the data type for 64-bit decimal.
Metafunction for retrieving the data_type of a typed array.