39 template <
class DERIVED>
89 struct get_data_type_from_array;
188 template <
class DERIVED>
264 using offset_type = std::conditional_t<BIG, const std::int64_t, const std::int32_t>;
275 template <
class... ARGS>
278 :
self_type(create_proxy(std::forward<ARGS>(args)...))
282 template <std::ranges::range SIZES_RANGE>
294 std::optional<std::string_view> name = std::nullopt,
295 std::optional<METADATA_RANGE> metadata = std::nullopt
298 static constexpr std::size_t OFFSET_BUFFER_INDEX = 1;
299 [[nodiscard]] std::pair<offset_type, offset_type> offset_range(size_type i)
const;
320 using offset_type = std::conditional_t<BIG, const std::int64_t, const std::int32_t>;
332 template <
class... ARGS>
335 :
self_type(create_proxy(std::forward<ARGS>(args)...))
349 std::optional<std::string_view> name = std::nullopt,
350 std::optional<METADATA_RANGE> metadata = std::nullopt
353 static constexpr std::size_t OFFSET_BUFFER_INDEX = 1;
354 static constexpr std::size_t SIZES_BUFFER_INDEX = 2;
355 [[nodiscard]] std::pair<offset_type, offset_type> offset_range(size_type i)
const;
387 template <
class... ARGS>
390 :
self_type(create_proxy(std::forward<ARGS>(args)...))
400 std::uint64_t list_size,
403 std::optional<std::string_view> name = std::nullopt,
404 std::optional<METADATA_RANGE> metadata = std::nullopt
407 [[nodiscard]]
static uint64_t list_size_from_format(
const std::string_view format);
408 [[nodiscard]] std::pair<offset_type, offset_type> offset_range(size_type i)
const;
410 uint64_t m_list_size;
421 template <
class DERIVED>
424 , p_flat_array(make_flat_array())
428 template <
class DERIVED>
431 , p_flat_array(make_flat_array())
435 template <
class DERIVED>
439 p_flat_array = make_flat_array();
443 template <
class DERIVED>
446 return p_flat_array.get();
449 template <
class DERIVED>
452 return p_flat_array.get();
455 template <
class DERIVED>
456 auto list_array_crtp_base<DERIVED>::value_begin() -> value_iterator
461 template <
class DERIVED>
462 auto list_array_crtp_base<DERIVED>::value_end() -> value_iterator
464 return value_iterator(
465 detail::layout_value_functor<DERIVED, inner_value_type>(&this->derived_cast()),
470 template <
class DERIVED>
471 auto list_array_crtp_base<DERIVED>::value_cbegin() const -> const_value_iterator
473 return const_value_iterator(
479 template <
class DERIVED>
480 auto list_array_crtp_base<DERIVED>::value_cend() const -> const_value_iterator
482 return const_value_iterator(
488 template <
class DERIVED>
489 auto list_array_crtp_base<DERIVED>::value(size_type i) -> inner_reference
491 const auto r = this->derived_cast().offset_range(i);
493 return list_value{p_flat_array.get(),
static_cast<st
>(r.first),
static_cast<st
>(r.second)};
496 template <
class DERIVED>
497 auto list_array_crtp_base<DERIVED>::value(size_type i)
const -> inner_const_reference
499 const auto r = this->derived_cast().offset_range(i);
501 return list_value{p_flat_array.get(),
static_cast<st
>(r.first),
static_cast<st
>(r.second)};
504 template <
class DERIVED>
507 return array_factory(this->get_arrow_proxy().children()[0].view());
515# pragma GCC diagnostic push
516# pragma GCC diagnostic ignored "-Wcast-align"
522 , p_list_offsets(make_list_offsets())
527 template <std::ranges::range SIZES_RANGE>
535 template <val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
538 offset_buffer_type&& list_offsets,
540 std::optional<std::string_view> name,
541 std::optional<METADATA_RANGE> metadata
544 const auto size = list_offsets.size() - 1;
553 BIG ? std::string(
"+L") : std::string(
"+l"),
563 std::vector<buffer<std::uint8_t>> arr_buffs = {
564 std::move(vbitmap).extract_storage(),
565 std::move(list_offsets).extract_storage()
569 static_cast<std::int64_t
>(size),
570 static_cast<int64_t
>(null_count),
572 std::move(arr_buffs),
573 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
578 return arrow_proxy{std::move(arr), std::move(schema)};
584 , p_list_offsets(make_list_offsets())
594 p_list_offsets = make_list_offsets();
600 auto list_array_impl<BIG>::offset_range(size_type i)
const -> std::pair<offset_type, offset_type>
602 return std::make_pair(p_list_offsets[i], p_list_offsets[i + 1]);
606 auto list_array_impl<BIG>::make_list_offsets() -> offset_type*
608 return reinterpret_cast<offset_type*
>(
609 this->get_arrow_proxy().buffers()[OFFSET_BUFFER_INDEX].data() + this->get_arrow_proxy().offset()
620 , p_list_offsets(make_list_offsets())
621 , p_list_sizes(make_list_sizes())
626 template <val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
627 arrow_proxy list_view_array_impl<BIG>::create_proxy(
629 offset_buffer_type&& list_offsets,
630 size_buffer_type&& list_sizes,
632 std::optional<std::string_view> name,
633 std::optional<METADATA_RANGE> metadata
636 SPARROW_ASSERT(list_offsets.size() == list_sizes.size(),
"sizes and offset must have the same size");
638 const auto size = list_sizes.size();
648 BIG ? std::string(
"+vL") : std::string(
"+vl"),
657 std::vector<buffer<std::uint8_t>> arr_buffs = {
658 std::move(vbitmap).extract_storage(),
659 std::move(list_offsets).extract_storage(),
660 std::move(list_sizes).extract_storage()
664 static_cast<std::int64_t
>(size),
665 static_cast<int64_t
>(null_count),
667 std::move(arr_buffs),
668 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
673 return arrow_proxy{std::move(arr), std::move(schema)};
679 , p_list_offsets(make_list_offsets())
680 , p_list_sizes(make_list_sizes())
690 p_list_offsets = make_list_offsets();
691 p_list_sizes = make_list_sizes();
697 inline auto list_view_array_impl<BIG>::offset_range(size_type i)
const
698 -> std::pair<offset_type, offset_type>
700 const auto offset = p_list_offsets[i];
701 return std::make_pair(offset, offset + p_list_sizes[i]);
705 auto list_view_array_impl<BIG>::make_list_offsets() -> offset_type*
707 return reinterpret_cast<offset_type*
>(
708 this->get_arrow_proxy().buffers()[OFFSET_BUFFER_INDEX].data() + this->get_arrow_proxy().offset()
713 auto list_view_array_impl<BIG>::make_list_sizes() -> offset_type*
715 return reinterpret_cast<offset_type*
>(
716 this->get_arrow_proxy().buffers()[SIZES_BUFFER_INDEX].data() + this->get_arrow_proxy().offset()
721# pragma GCC diagnostic pop
728 inline auto fixed_sized_list_array::list_size_from_format(
const std::string_view format) -> uint64_t
731 const auto n_digits = format.size() - 3;
732 const auto list_size_str = format.substr(3, n_digits);
733 return std::stoull(std::string(list_size_str));
742 inline auto fixed_sized_list_array::offset_range(size_type i)
const -> std::pair<offset_type, offset_type>
744 const auto offset = i * m_list_size;
745 return std::make_pair(offset, offset + m_list_size);
748 template <val
idity_bitmap_input R, input_metadata_container METADATA_RANGE>
749 inline arrow_proxy fixed_sized_list_array::create_proxy(
750 std::uint64_t list_size,
753 std::optional<std::string_view> name,
754 std::optional<METADATA_RANGE> metadata
757 const auto size = flat_values.size() /
static_cast<std::size_t
>(list_size);
764 const repeat_view<bool> children_ownership{
true, 1};
766 std::string format =
"+w:" + std::to_string(list_size);
772 new ArrowSchema*[1]{
new ArrowSchema(std::move(flat_schema))},
778 std::vector<buffer<std::uint8_t>> arr_buffs = {vbitmap.
extract_storage()};
781 static_cast<std::int64_t
>(size),
782 static_cast<int64_t
>(null_count),
784 std::move(arr_buffs),
785 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
790 return arrow_proxy{std::move(arr), std::move(schema)};
typename base_type::const_bitmap_range const_bitmap_range
array_bitmap_base_impl & operator=(const array_bitmap_base_impl &)
typename base_type::iterator_tag iterator_tag
typename base_type::bitmap_const_reference bitmap_const_reference
typename base_type::bitmap_type bitmap_type
Base class defining common immutable interface for arrays with a bitmap.
Base class for array type erasure.
Dynamically typed array encapsulating an Arrow layout.
Proxy class over ArrowArray and ArrowSchema.
Smart pointer behaving like a copiable std::unique_ptr.
storage_type extract_storage() noexcept
constexpr size_type null_count() const noexcept
fixed_sized_list_array & operator=(const self_type &)=default
inner_types::list_size_type list_size_type
array_inner_types< self_type > inner_types
fixed_sized_list_array(arrow_proxy proxy)
fixed_sized_list_array(ARGS &&... args)
list_array_crtp_base< self_type > base_type
fixed_sized_list_array self_type
fixed_sized_list_array & operator=(self_type &&)=default
fixed_sized_list_array(self_type &&)=default
typename base_type::size_type size_type
fixed_sized_list_array(const self_type &)=default
std::uint64_t offset_type
typename base_type::const_bitmap_range const_bitmap_range
const array_wrapper * raw_flat_array() const
list_array_crtp_base(self_type &&)=default
nullable< inner_const_reference, bitmap_const_reference > const_reference
typename inner_types::const_value_iterator const_value_iterator
list_value inner_value_type
typename base_type::bitmap_const_reference bitmap_const_reference
typename base_type::iterator_tag iterator_tag
list_array_crtp_base(arrow_proxy proxy)
array_wrapper * raw_flat_array()
typename inner_types::value_iterator value_iterator
list_array_crtp_base & operator=(const self_type &)
list_array_crtp_base & operator=(self_type &&)=default
typename base_type::bitmap_type bitmap_type
list_array_crtp_base< DERIVED > self_type
typename base_type::size_type size_type
array_inner_types< DERIVED > inner_types
list_array_crtp_base(const self_type &)
nullable< inner_value_type > value_type
list_value inner_const_reference
list_value inner_reference
array_bitmap_base< DERIVED > base_type
list_array_impl(self_type &&)=default
list_array_impl< BIG > self_type
std::conditional_t< BIG, const std::int64_t, const std::int32_t > offset_type
typename base_type::size_type size_type
list_array_impl & operator=(self_type &&)=default
list_array_impl(ARGS &&... args)
list_array_impl(const self_type &)
array_inner_types< self_type > inner_types
static auto offset_from_sizes(SIZES_RANGE &&sizes) -> offset_buffer_type
inner_types::list_size_type list_size_type
list_array_crtp_base< list_array_impl< BIG > > base_type
list_array_impl & operator=(const self_type &)
u8_buffer< std::remove_const_t< offset_type > > offset_buffer_type
list_array_impl(arrow_proxy proxy)
list_view_array_impl & operator=(const self_type &)
typename base_type::size_type size_type
list_view_array_impl & operator=(self_type &&)=default
list_view_array_impl(self_type &&)=default
u8_buffer< std::remove_const_t< offset_type > > offset_buffer_type
list_view_array_impl(arrow_proxy proxy)
std::conditional_t< BIG, const std::int64_t, const std::int32_t > offset_type
array_inner_types< self_type > inner_types
list_array_crtp_base< list_view_array_impl< BIG > > base_type
list_view_array_impl(ARGS &&... args)
list_view_array_impl< BIG > self_type
list_view_array_impl(const self_type &)
inner_types::list_size_type list_size_type
u8_buffer< std::remove_const_t< list_size_type > > size_buffer_type
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(expr__, message__)
sparrow::u8_buffer< OFFSET_TYPE > offset_buffer_from_sizes(SIZES_RANGE &&sizes)
constexpr std::size_t size(typelist< T... >={})
constexpr bool excludes_copy_and_move_ctor_v
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.
constexpr bool is_list_view_array_v
Checks whether T is a list_view_array type.
list_array_impl< false > list_array
array_bitmap_base_impl< D, false > array_bitmap_base
Convenient typedef to be used as a crtp base class for arrays using an immutable validity buffer.
constexpr bool is_fixed_sized_list_array_v
Checks whether T is a fixed_sized_list_array type.
list_view_array_impl< true > big_list_view_array
std::pair< ArrowArray, ArrowSchema > extract_arrow_structures(A &&a)
Extracts the internal ArrowArrays and ArrowSchema structures from the given array or typed layout.
constexpr bool is_big_list_array_v
Checks whether T is a big_list_array type.
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.
list_view_array_impl< false > list_view_array
dynamic_bitset< std::uint8_t > validity_bitmap
constexpr bool is_list_array_v
Checks whether T is a list_array type.
SPARROW_API cloning_ptr< array_wrapper > array_factory(arrow_proxy proxy)
list_array_impl< true > big_list_array
validity_bitmap ensure_validity_bitmap(std::size_t size, R &&validity_input)
constexpr bool is_big_list_view_array_v
Checks whether T is a big_list_view_array type.
data_type
Runtime identifier of arrow data types, usually associated with raw bytes with the associated value.
list_value inner_value_type
functor_index_iterator< detail::layout_value_functor< const array_type, inner_value_type > > const_value_iterator
std::random_access_iterator_tag iterator_tag
fixed_sized_list_array array_type
list_value inner_reference
list_value inner_const_reference
std::uint64_t list_size_type
functor_index_iterator< detail::layout_value_functor< array_type, inner_value_type > > value_iterator
std::conditional_t< BIG, std::uint64_t, std::uint32_t > list_size_type
functor_index_iterator< detail::layout_value_functor< const array_type, inner_value_type > > const_value_iterator
std::random_access_iterator_tag iterator_tag
list_array_impl< BIG > array_type
functor_index_iterator< detail::layout_value_functor< array_type, inner_value_type > > value_iterator
list_value inner_value_type
list_value inner_const_reference
list_value inner_reference
list_value inner_value_type
list_value inner_const_reference
std::random_access_iterator_tag iterator_tag
functor_index_iterator< detail::layout_value_functor< array_type, inner_value_type > > value_iterator
list_value inner_reference
std::conditional_t< BIG, std::uint64_t, std::uint32_t > list_size_type
functor_index_iterator< detail::layout_value_functor< const array_type, inner_value_type > > const_value_iterator
list_view_array_impl< BIG > array_type
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()
static constexpr sparrow::data_type get()