38 template <
class DERIVED>
110 struct get_data_type_from_array;
209 template <
class DERIVED>
249 using list_size_type =
inner_types::list_size_type;
282 using offset_type = std::conditional_t<BIG, const std::int64_t, const std::int32_t>;
293 template <class... ARGS>
300 template <std::ranges::range SIZES_RANGE>
312 std::optional<std::string_view> name = std::nullopt,
313 std::optional<METADATA_RANGE> metadata = std::nullopt
318 std::ranges::input_range OFFSET_BUFFER_RANGE,
320 requires std::convertible_to<std::ranges::range_value_t<OFFSET_BUFFER_RANGE>,
offset_type>
323 OFFSET_BUFFER_RANGE&& list_offsets_range,
325 std::optional<std::string_view> name = std::nullopt,
326 std::optional<METADATA_RANGE> metadata = std::nullopt
329 offset_buffer_type list_offsets{std::forward<OFFSET_BUFFER_RANGE>(list_offsets_range)};
330 return list_array_impl<BIG>::create_proxy(
331 std::move(flat_values),
332 std::move(list_offsets),
333 std::forward<VB>(validity_input),
334 std::forward<std::optional<std::string_view>>(name),
335 std::forward<std::optional<METADATA_RANGE>>(metadata)
341 input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
342 [[nodiscard]]
static arrow_proxy create_proxy(
344 offset_buffer_type&& list_offsets,
345 bool nullable =
true,
346 std::optional<std::string_view> name = std::nullopt,
347 std::optional<METADATA_RANGE> metadata = std::nullopt
352 std::ranges::input_range OFFSET_BUFFER_RANGE,
353 input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
354 requires std::convertible_to<std::ranges::range_value_t<OFFSET_BUFFER_RANGE>, offset_type>
355 [[nodiscard]]
static arrow_proxy create_proxy(
357 OFFSET_BUFFER_RANGE&& list_offsets_range,
358 bool nullable =
true,
359 std::optional<std::string_view> name = std::nullopt,
360 std::optional<METADATA_RANGE> metadata = std::nullopt
363 offset_buffer_type list_offsets{std::forward<OFFSET_BUFFER_RANGE>(list_offsets_range)};
364 return list_array_impl<BIG>::create_proxy(
365 std::move(flat_values),
366 std::move(list_offsets),
368 std::forward<std::optional<std::string_view>>(name),
369 std::forward<std::optional<METADATA_RANGE>>(metadata)
373 static constexpr std::size_t OFFSET_BUFFER_INDEX = 1;
374 [[nodiscard]]
constexpr std::pair<offset_type, offset_type> offset_range(
size_type i)
const;
376 [[nodiscard]]
constexpr offset_type* make_list_offsets();
395 using offset_type = std::conditional_t<BIG, const std::int64_t, const std::int32_t>;
407 template <
class... ARGS>
410 :
self_type(create_proxy(std::forward<ARGS>(args)...))
417 std::ranges::input_range OFFSET_BUFFER_RANGE,
418 std::ranges::input_range SIZE_RANGE,
422 std::convertible_to<std::ranges::range_value_t<OFFSET_BUFFER_RANGE>, offset_type>
423 && std::convertible_to<std::ranges::range_value_t<SIZE_RANGE>, list_size_type>
427 OFFSET_BUFFER_RANGE&& list_offsets,
428 SIZE_RANGE&& list_sizes,
430 std::optional<std::string_view> name = std::nullopt,
431 std::optional<METADATA_RANGE> metadata = std::nullopt
434 return list_view_array_impl<BIG>::create_proxy(
435 std::move(flat_values),
436 offset_buffer_type(std::forward<OFFSET_BUFFER_RANGE>(list_offsets)),
437 size_buffer_type(std::forward<SIZE_RANGE>(list_sizes)),
438 std::forward<VB>(validity_input),
445 validity_bitmap_input VB = validity_bitmap,
446 input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
447 [[nodiscard]]
static arrow_proxy create_proxy(
449 offset_buffer_type&& list_offsets,
450 size_buffer_type&& list_sizes,
452 std::optional<std::string_view> name = std::nullopt,
453 std::optional<METADATA_RANGE> metadata = std::nullopt
457 std::ranges::input_range OFFSET_BUFFER_RANGE,
458 std::ranges::input_range SIZE_RANGE,
459 input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
461 std::convertible_to<std::ranges::range_value_t<OFFSET_BUFFER_RANGE>, offset_type>
462 && std::convertible_to<std::ranges::range_value_t<SIZE_RANGE>, list_size_type>
464 [[nodiscard]]
static arrow_proxy create_proxy(
466 OFFSET_BUFFER_RANGE&& list_offsets,
467 SIZE_RANGE&& list_sizes,
468 bool nullable =
true,
469 std::optional<std::string_view> name = std::nullopt,
470 std::optional<METADATA_RANGE> metadata = std::nullopt
473 return list_view_array_impl<BIG>::create_proxy(
474 std::move(flat_values),
475 offset_buffer_type(std::forward<OFFSET_BUFFER_RANGE>(list_offsets)),
476 size_buffer_type(std::forward<SIZE_RANGE>(list_sizes)),
483 template <input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
484 [[nodiscard]]
static arrow_proxy create_proxy(
486 offset_buffer_type&& list_offsets,
487 size_buffer_type&& list_sizes,
488 bool nullable =
true,
489 std::optional<std::string_view> name = std::nullopt,
490 std::optional<METADATA_RANGE> metadata = std::nullopt
493 static constexpr std::size_t OFFSET_BUFFER_INDEX = 1;
494 static constexpr std::size_t SIZES_BUFFER_INDEX = 2;
495 [[nodiscard]]
constexpr std::pair<offset_type, offset_type> offset_range(size_type i)
const;
497 [[nodiscard]]
constexpr offset_type* make_list_offsets();
498 [[nodiscard]]
constexpr offset_type* make_list_sizes();
500 offset_type* p_list_offsets;
527 template <
class... ARGS>
530 :
self_type(create_proxy(std::forward<ARGS>(args)...))
540 std::uint64_t list_size,
543 std::optional<std::string_view> name = std::nullopt,
544 std::optional<METADATA_RANGE> metadata = std::nullopt
551 std::uint64_t list_size,
554 std::optional<std::string_view> name = std::nullopt,
555 std::optional<METADATA_RANGE> metadata = std::nullopt
558 [[nodiscard]]
static uint64_t list_size_from_format(
const std::string_view format);
559 [[nodiscard]]
constexpr std::pair<offset_type, offset_type> offset_range(size_type i)
const;
561 uint64_t m_list_size;
572 template <
class DERIVED>
575 , p_flat_array(make_flat_array())
579 template <
class DERIVED>
582 , p_flat_array(make_flat_array())
586 template <
class DERIVED>
590 p_flat_array = make_flat_array();
594 template <
class DERIVED>
597 return p_flat_array.get();
600 template <
class DERIVED>
603 return p_flat_array.get();
606 template <
class DERIVED>
607 constexpr auto list_array_crtp_base<DERIVED>::value_begin() -> value_iterator
612 template <
class DERIVED>
613 constexpr auto list_array_crtp_base<DERIVED>::value_end() -> value_iterator
615 return value_iterator(
616 detail::layout_value_functor<DERIVED, inner_value_type>(&this->derived_cast()),
621 template <
class DERIVED>
622 constexpr auto list_array_crtp_base<DERIVED>::value_cbegin() const -> const_value_iterator
624 return const_value_iterator(
630 template <
class DERIVED>
631 constexpr auto list_array_crtp_base<DERIVED>::value_cend() const -> const_value_iterator
633 return const_value_iterator(
639 template <
class DERIVED>
640 constexpr auto list_array_crtp_base<DERIVED>::value(size_type i) -> inner_reference
642 const auto r = this->derived_cast().offset_range(i);
644 return list_value{p_flat_array.get(),
static_cast<st
>(r.first),
static_cast<st
>(r.second)};
647 template <
class DERIVED>
648 constexpr auto list_array_crtp_base<DERIVED>::value(size_type i)
const -> inner_const_reference
650 const auto r = this->derived_cast().offset_range(i);
652 return list_value{p_flat_array.get(),
static_cast<st
>(r.first),
static_cast<st
>(r.second)};
655 template <
class DERIVED>
658 return array_factory(this->get_arrow_proxy().children()[0].view());
666# pragma GCC diagnostic push
667# pragma GCC diagnostic ignored "-Wcast-align"
673 , p_list_offsets(make_list_offsets())
678 template <std::ranges::range SIZES_RANGE>
682 std::forward<SIZES_RANGE>(sizes)
687 template <val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
690 offset_buffer_type&& list_offsets,
692 std::optional<std::string_view> name,
693 std::optional<METADATA_RANGE> metadata
696 const auto size = list_offsets.size() - 1;
707 BIG ? std::string(
"+L") : std::string(
"+l"),
711 new ArrowSchema*[1]{
new ArrowSchema(std::move(flat_schema))},
717 std::vector<buffer<std::uint8_t>> arr_buffs = {
718 std::move(vbitmap).extract_storage(),
719 std::move(list_offsets).extract_storage()
723 static_cast<std::int64_t
>(size),
724 static_cast<int64_t
>(null_count),
726 std::move(arr_buffs),
727 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
732 return arrow_proxy{std::move(arr), std::move(schema)};
736 template <val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
739 offset_buffer_type&& list_offsets,
741 std::optional<std::string_view> name,
742 std::optional<METADATA_RANGE> metadata
747 return list_array_impl<BIG>::create_proxy(
748 std::move(flat_values),
749 std::move(list_offsets),
757 const auto size = list_offsets.size() - 1;
762 BIG ? std::string(
"+L") : std::string(
"+l"),
766 new ArrowSchema*[1]{
new ArrowSchema(std::move(flat_schema))},
772 std::vector<buffer<std::uint8_t>> arr_buffs = {
774 std::move(list_offsets).extract_storage()
778 static_cast<std::int64_t
>(size),
781 std::move(arr_buffs),
782 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
787 return arrow_proxy{std::move(arr), std::move(schema)};
794 , p_list_offsets(make_list_offsets())
804 p_list_offsets = make_list_offsets();
810 constexpr auto list_array_impl<BIG>::offset_range(size_type i)
const -> std::pair<offset_type, offset_type>
812 return std::make_pair(p_list_offsets[i], p_list_offsets[i + 1]);
816 constexpr auto list_array_impl<BIG>::make_list_offsets() -> offset_type*
818 return reinterpret_cast<offset_type*
>(
819 this->get_arrow_proxy().buffers()[OFFSET_BUFFER_INDEX].data() + this->get_arrow_proxy().offset()
830 , p_list_offsets(make_list_offsets())
831 , p_list_sizes(make_list_sizes())
836 template <val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
837 arrow_proxy list_view_array_impl<BIG>::create_proxy(
839 offset_buffer_type&& list_offsets,
840 size_buffer_type&& list_sizes,
842 std::optional<std::string_view> name,
843 std::optional<METADATA_RANGE> metadata
846 SPARROW_ASSERT(list_offsets.size() == list_sizes.size(),
"sizes and offset must have the same size");
847 const auto size = list_sizes.size();
855 BIG ? std::string(
"+vL") : std::string(
"+vl"),
859 new ArrowSchema*[1]{
new ArrowSchema(std::move(flat_schema))},
864 std::vector<buffer<std::uint8_t>> arr_buffs = {
865 std::move(vbitmap).extract_storage(),
866 std::move(list_offsets).extract_storage(),
867 std::move(list_sizes).extract_storage()
871 static_cast<std::int64_t
>(size),
872 static_cast<int64_t
>(null_count),
874 std::move(arr_buffs),
875 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
880 return arrow_proxy{std::move(arr), std::move(schema)};
884 template <input_metadata_container METADATA_RANGE>
885 arrow_proxy list_view_array_impl<BIG>::create_proxy(
887 offset_buffer_type&& list_offsets,
888 size_buffer_type&& list_sizes,
890 std::optional<std::string_view> name,
891 std::optional<METADATA_RANGE> metadata
896 return list_view_array_impl<BIG>::create_proxy(
897 std::move(flat_values),
898 std::move(list_offsets),
899 std::move(list_sizes),
907 SPARROW_ASSERT(list_offsets.size() == list_sizes.size(),
"sizes and offset must have the same size");
908 const auto size = list_sizes.size();
913 BIG ? std::string(
"+vL") : std::string(
"+vl"),
917 new ArrowSchema*[1]{
new ArrowSchema(std::move(flat_schema))},
922 std::vector<buffer<std::uint8_t>> arr_buffs = {
924 std::move(list_offsets).extract_storage(),
925 std::move(list_sizes).extract_storage()
929 static_cast<std::int64_t
>(size),
932 std::move(arr_buffs),
933 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
938 return arrow_proxy{std::move(arr), std::move(schema)};
945 , p_list_offsets(make_list_offsets())
946 , p_list_sizes(make_list_sizes())
956 p_list_offsets = make_list_offsets();
957 p_list_sizes = make_list_sizes();
963 inline constexpr auto list_view_array_impl<BIG>::offset_range(size_type i)
const
964 -> std::pair<offset_type, offset_type>
966 const auto offset = p_list_offsets[i];
967 return std::make_pair(offset, offset + p_list_sizes[i]);
971 constexpr auto list_view_array_impl<BIG>::make_list_offsets() -> offset_type*
973 return reinterpret_cast<offset_type*
>(
974 this->get_arrow_proxy().buffers()[OFFSET_BUFFER_INDEX].data() + this->get_arrow_proxy().offset()
979 constexpr auto list_view_array_impl<BIG>::make_list_sizes() -> offset_type*
981 return reinterpret_cast<offset_type*
>(
982 this->get_arrow_proxy().buffers()[SIZES_BUFFER_INDEX].data() + this->get_arrow_proxy().offset()
987# pragma GCC diagnostic pop
994 inline auto fixed_sized_list_array::list_size_from_format(
const std::string_view format) -> uint64_t
997 const auto n_digits = format.size() - 3;
998 const auto list_size_str = format.substr(3, n_digits);
999 return std::stoull(std::string(list_size_str));
1008 constexpr auto fixed_sized_list_array::offset_range(size_type i)
const
1009 -> std::pair<offset_type, offset_type>
1011 const auto offset = i * m_list_size;
1012 return std::make_pair(offset, offset + m_list_size);
1015 template <val
idity_bitmap_input R, input_metadata_container METADATA_RANGE>
1016 inline arrow_proxy fixed_sized_list_array::create_proxy(
1017 std::uint64_t list_size,
1018 array&& flat_values,
1020 std::optional<std::string_view> name,
1021 std::optional<METADATA_RANGE> metadata
1024 const auto size = flat_values.size() /
static_cast<std::size_t
>(list_size);
1029 const auto null_count = vbitmap.
null_count();
1031 const repeat_view<bool> children_ownership{
true, 1};
1033 std::string format =
"+w:" + std::to_string(list_size);
1037 std::move(metadata),
1039 new ArrowSchema*[1]{
new ArrowSchema(std::move(flat_schema))},
1045 std::vector<buffer<std::uint8_t>> arr_buffs = {vbitmap.
extract_storage()};
1048 static_cast<std::int64_t
>(size),
1049 static_cast<int64_t
>(null_count),
1051 std::move(arr_buffs),
1052 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
1057 return arrow_proxy{std::move(arr), std::move(schema)};
1060 template <val
idity_bitmap_input R, input_metadata_container METADATA_RANGE>
1061 inline arrow_proxy fixed_sized_list_array::create_proxy(
1062 std::uint64_t list_size,
1063 array&& flat_values,
1065 std::optional<std::string_view> name,
1066 std::optional<METADATA_RANGE> metadata
1071 return fixed_sized_list_array::create_proxy(
1073 std::move(flat_values),
1081 const auto size = flat_values.size() /
static_cast<std::size_t
>(list_size);
1083 const repeat_view<bool> children_ownership{
true, 1};
1085 std::string format =
"+w:" + std::to_string(list_size);
1089 std::move(metadata),
1091 new ArrowSchema*[1]{
new ArrowSchema(std::move(flat_schema))},
1097 std::vector<buffer<std::uint8_t>> arr_buffs = {
1098 buffer<std::uint8_t>{
nullptr, 0}
1102 static_cast<std::int64_t
>(size),
1105 std::move(arr_buffs),
1106 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
1111 return arrow_proxy{std::move(arr), std::move(schema)};
typename base_type::const_bitmap_range const_bitmap_range
typename base_type::iterator_tag iterator_tag
constexpr array_bitmap_base_impl & operator=(const array_bitmap_base_impl &)
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.
Object that owns a piece of contiguous memory.
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
constexpr fixed_sized_list_array(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
std::uint64_t offset_type
typename base_type::const_bitmap_range const_bitmap_range
constexpr list_array_crtp_base & operator=(const self_type &)
constexpr array_wrapper * raw_flat_array()
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)
constexpr list_array_crtp_base(const self_type &)
typename inner_types::value_iterator value_iterator
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
nullable< inner_value_type > value_type
list_value inner_const_reference
constexpr const array_wrapper * raw_flat_array() const
list_value inner_reference
array_bitmap_base< DERIVED > base_type
constexpr list_array_crtp_base(self_type &&) noexcept=default
list_array_impl< BIG > self_type
constexpr list_array_impl(const self_type &)
std::conditional_t< BIG, const std::int64_t, const std::int32_t > offset_type
typename base_type::size_type size_type
constexpr list_array_impl & operator=(const self_type &)
array_inner_types< self_type > inner_types
constexpr list_array_impl(self_type &&) noexcept=default
static constexpr 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
u8_buffer< std::remove_const_t< offset_type > > offset_buffer_type
list_array_impl(arrow_proxy proxy)
constexpr list_view_array_impl & operator=(self_type &&)=default
typename base_type::size_type size_type
constexpr 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
constexpr 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
constexpr list_view_array_impl & operator=(const self_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__)
constexpr 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
A list array implementation.
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
A list view array implementation.
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
A big list array implementation.
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()