36 template <decimal_type T>
47 struct get_data_type_from_array;
87 template <decimal_type T>
110 template <decimal_type T>
128 "The storage type must be an integral type of size 4, 8, 16 or 32 bytes"
148 template <
class... Args>
162 std::ranges::input_range VALUE_RANGE,
165 requires std::convertible_to<std::ranges::range_value_t<VALUE_RANGE>,
typename T::integer_type>
166 [[nodiscard]]
static auto create_proxy(
168 VALIDITY_RANGE&& bitmaps,
169 std::size_t precision,
171 std::optional<std::string_view> name = std::nullopt,
172 std::optional<METADATA_RANGE> metadata = std::nullopt
176 std::ranges::input_range NULLABLE_VALUE_RANGE,
179 [[nodiscard]]
static auto create_proxy(
180 NULLABLE_VALUE_RANGE&& range,
181 std::size_t precision,
183 std::optional<std::string_view> name = std::nullopt,
184 std::optional<METADATA_RANGE> metadata = std::nullopt
187 template <std::ranges::input_range VALUE_RANGE, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
188 requires std::is_same_v<std::ranges::range_value_t<VALUE_RANGE>,
typename T::integer_type>
189 [[nodiscard]]
static auto create_proxy(
191 std::size_t precision,
194 std::optional<std::string_view> name = std::nullopt,
195 std::optional<METADATA_RANGE> metadata = std::nullopt
198 template <val
idity_bitmap_input R, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
199 [[nodiscard]]
static auto create_proxy(
202 std::size_t precision,
204 std::optional<std::string_view> name = std::nullopt,
205 std::optional<METADATA_RANGE> metadata = std::nullopt
208 template <input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
209 [[nodiscard]]
static auto create_proxy(
211 std::size_t precision,
214 std::optional<std::string_view> name = std::nullopt,
215 std::optional<METADATA_RANGE> metadata = std::nullopt
218 template <input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
219 [[nodiscard]]
static auto create_proxy_impl(
221 std::size_t precision,
223 std::optional<validity_bitmap>,
224 std::optional<std::string_view> name = std::nullopt,
225 std::optional<METADATA_RANGE> metadata = std::nullopt
228 static std::string generate_format(std::size_t precision,
int scale);
236 void assign(
const T& rhs,
size_type index);
240 static constexpr size_type DATA_BUFFER_INDEX = 1;
248 std::size_t m_precision;
256 template <decimal_type T>
263 const auto format = this->get_arrow_proxy().format();
266 if (format.size() < 2 || format[0] !=
'd' || format[1] !=
':')
268 throw std::runtime_error(
"Invalid format string for decimal array");
272 const auto format_str = format.substr(2);
274 std::stringstream ss;
277 ss >> m_precision >> c >> m_scale;
282 throw std::runtime_error(
"Invalid format string for decimal array");
286 template <decimal_type T>
287 template <std::ranges::input_range VALUE_RANGE, val
idity_bitmap_input VALIDITY_RANGE, input_metadata_container METADATA_RANGE>
288 requires std::convertible_to<std::ranges::range_value_t<VALUE_RANGE>,
typename T::integer_type>
291 VALIDITY_RANGE&& bitmaps,
292 std::size_t precision,
294 std::optional<std::string_view> name,
295 std::optional<METADATA_RANGE> metadata
299 const auto size = u8_data_buffer.
size();
301 return create_proxy_impl(
302 std::move(u8_data_buffer),
311 template <decimal_type T>
312 template <std::ranges::input_range NULLABLE_VALUE_RANGE, input_metadata_container METADATA_RANGE>
315 NULLABLE_VALUE_RANGE&& range,
316 std::size_t precision,
318 std::optional<std::string_view> name,
319 std::optional<METADATA_RANGE> metadata
323 | std::views::transform(
329 auto is_non_null = range
330 | std::views::transform(
333 return v.has_value();
336 return create_proxy(values, is_non_null, precision, scale, std::move(name), std::move(metadata));
339 template <decimal_type T>
340 template <input_metadata_container METADATA_RANGE>
341 auto decimal_array<T>::create_proxy(
343 std::size_t precision,
346 std::optional<std::string_view> name,
347 std::optional<METADATA_RANGE> metadata
350 const size_t size = data_buffer.size();
351 return create_proxy_impl(
352 std::move(data_buffer),
355 nullable ? std::make_optional<validity_bitmap>(
nullptr, size) : std::nullopt,
361 template <decimal_type T>
362 template <std::ranges::input_range VALUE_RANGE, input_metadata_container METADATA_RANGE>
363 requires std::is_same_v<std::ranges::range_value_t<VALUE_RANGE>,
typename T::integer_type>
366 std::size_t precision,
369 std::optional<std::string_view> name,
370 std::optional<METADATA_RANGE> metadata
374 const auto size = u8_data_buffer.
size();
375 return create_proxy_impl(
376 std::move(u8_data_buffer),
379 nullable ? std::make_optional<validity_bitmap>(
nullptr, size) : std::nullopt,
385 template <decimal_type T>
386 template <val
idity_bitmap_input R, input_metadata_container METADATA_RANGE>
387 auto decimal_array<T>::create_proxy(
390 std::size_t precision,
392 std::optional<std::string_view> name,
393 std::optional<METADATA_RANGE> metadata
396 const auto size = data_buffer.size();
398 return create_proxy_impl(
399 std::move(data_buffer),
408 template <decimal_type T>
409 template <input_metadata_container METADATA_RANGE>
410 [[nodiscard]]
auto decimal_array<T>::create_proxy_impl(
411 u8_buffer<storage_type>&& data_buffer,
412 std::size_t precision,
414 std::optional<validity_bitmap> bitmap,
415 std::optional<std::string_view> name,
416 std::optional<METADATA_RANGE> metadata
419 const std::optional<std::unordered_set<sparrow::ArrowFlag>>
420 flags = bitmap.has_value()
424 const auto size = data_buffer.size();
425 const size_t null_count = bitmap.has_value() ? bitmap->
null_count() : 0;
429 generate_format(precision, scale),
439 std::vector<buffer<uint8_t>> buffers(2);
441 buffers[1] = std::move(data_buffer).extract_storage();
445 static_cast<std::int64_t
>(size),
446 static_cast<int64_t
>(null_count),
454 return arrow_proxy(std::move(arr), std::move(schema));
457 template <decimal_type T>
464 template <decimal_type T>
468 const auto ptr = this->get_arrow_proxy().buffers()[DATA_BUFFER_INDEX].template data<const storage_type>();
472 template <decimal_type T>
473 auto decimal_array<T>::value_begin() -> value_iterator
478 template <decimal_type T>
479 auto decimal_array<T>::value_end() -> value_iterator
481 return value_iterator(detail::layout_value_functor<self_type, inner_reference>(
this), this->size());
484 template <decimal_type T>
485 auto decimal_array<T>::value_cbegin() const -> const_value_iterator
490 template <decimal_type T>
491 auto decimal_array<T>::value_cend() const -> const_value_iterator
493 return const_value_iterator(
499 template <decimal_type T>
500 void decimal_array<T>::assign(
const T& rhs, size_type index)
503 const auto ptr = this->get_arrow_proxy().buffers()[DATA_BUFFER_INDEX].template data<storage_type>();
504 const auto storage = rhs.storage();
506 const auto scaled_storage = storage
507 *
static_cast<storage_type
>(
508 static_cast<size_t>(std::pow(10, m_scale - rhs.scale()))
510 ptr[index] = scaled_storage;
513 template <decimal_type T>
514 std::string decimal_array<T>::generate_format(std::size_t precision,
int scale)
516 constexpr std::size_t sizeof_decimal =
sizeof(storage_type);
517 std::stringstream format_str;
518 format_str <<
"d:" << precision <<
"," << scale;
519 if (sizeof_decimal != 16)
521 format_str <<
"," << sizeof_decimal * 8;
523 return format_str.str();
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
Proxy class over ArrowArray and ArrowSchema.
constexpr size_type size() const noexcept
Object that owns a piece of contiguous memory.
inner_const_reference value(size_type i) const
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)
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
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)
inner_reference value(size_type i)
typename inner_types::value_iterator value_iterator
Implementation of reference to inner type used for layout L.
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.
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
constexpr bool is_type_instance_of_v
true if T is a concrete type template instanciation of U which is a type template.
constexpr bool is_decimal_array_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.
decimal_array< decimal< int128_t > > decimal_128_array
decimal_array< decimal< int32_t > > decimal_32_array
decimal_array< decimal< int64_t > > decimal_64_array
decimal_array< decimal< int256_t > > decimal_256_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
validity_bitmap ensure_validity_bitmap(std::size_t size, R &&validity_input)
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 specialization.
Traits class that must be specialized by array classes inheriting from array_crtp_base.
static constexpr sparrow::data_type get()
static constexpr sparrow::data_type get()
static constexpr sparrow::data_type get()
static constexpr sparrow::data_type get()