37 template <
class DERIVED>
87 struct get_data_type_from_array;
186 template <
class DERIVED>
262 using offset_type = std::conditional_t<BIG, const std::int64_t, const std::int32_t>;
273 template <
class... ARGS>
276 :
self_type(create_proxy(std::forward<ARGS>(args)...))
280 template <std::ranges::range SIZES_RANGE>
285 template <val
idity_bitmap_input VB = val
idity_bitmap>
290 std::optional<std::string_view> name = std::nullopt,
291 std::optional<std::string_view> metadata = std::nullopt
294 static constexpr std::size_t OFFSET_BUFFER_INDEX = 1;
295 [[nodiscard]] std::pair<offset_type, offset_type> offset_range(size_type i)
const;
316 using offset_type = std::conditional_t<BIG, const std::int64_t, const std::int32_t>;
328 template <
class... ARGS>
331 :
self_type(create_proxy(std::forward<ARGS>(args)...))
337 template <val
idity_bitmap_input VB = val
idity_bitmap>
343 std::optional<std::string_view> name = std::nullopt,
344 std::optional<std::string_view> metadata = std::nullopt
347 static constexpr std::size_t OFFSET_BUFFER_INDEX = 1;
348 static constexpr std::size_t SIZES_BUFFER_INDEX = 2;
349 [[nodiscard]] std::pair<offset_type, offset_type> offset_range(size_type i)
const;
381 template <
class... ARGS>
384 :
self_type(create_proxy(std::forward<ARGS>(args)...))
390 template <val
idity_bitmap_input R = val
idity_bitmap>
392 std::uint64_t list_size,
395 std::optional<std::string_view> name = std::nullopt,
396 std::optional<std::string_view> metadata = std::nullopt
399 [[nodiscard]]
static uint64_t list_size_from_format(
const std::string_view format);
400 [[nodiscard]] std::pair<offset_type, offset_type> offset_range(size_type i)
const;
402 uint64_t m_list_size;
413 template <
class DERIVED>
416 , p_flat_array(make_flat_array())
420 template <
class DERIVED>
423 , p_flat_array(make_flat_array())
427 template <
class DERIVED>
431 p_flat_array = make_flat_array();
435 template <
class DERIVED>
438 return p_flat_array.get();
441 template <
class DERIVED>
444 return p_flat_array.get();
447 template <
class DERIVED>
448 auto list_array_crtp_base<DERIVED>::value_begin() -> value_iterator
453 template <
class DERIVED>
454 auto list_array_crtp_base<DERIVED>::value_end() -> value_iterator
456 return value_iterator(
457 detail::layout_value_functor<DERIVED, inner_value_type>(&this->derived_cast()),
462 template <
class DERIVED>
463 auto list_array_crtp_base<DERIVED>::value_cbegin() const -> const_value_iterator
465 return const_value_iterator(
471 template <
class DERIVED>
472 auto list_array_crtp_base<DERIVED>::value_cend() const -> const_value_iterator
474 return const_value_iterator(
480 template <
class DERIVED>
481 auto list_array_crtp_base<DERIVED>::value(size_type i) -> inner_reference
483 const auto r = this->derived_cast().offset_range(i);
485 return list_value{p_flat_array.get(),
static_cast<st
>(r.first),
static_cast<st
>(r.second)};
488 template <
class DERIVED>
489 auto list_array_crtp_base<DERIVED>::value(size_type i)
const -> inner_const_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>
499 return array_factory(this->get_arrow_proxy().children()[0].view());
507# pragma GCC diagnostic push
508# pragma GCC diagnostic ignored "-Wcast-align"
514 , p_list_offsets(make_list_offsets())
519 template <std::ranges::range SIZES_RANGE>
527 template <val
idity_bitmap_input VB>
530 offset_buffer_type&& list_offsets,
532 std::optional<std::string_view> name,
533 std::optional<std::string_view> metadata
536 const auto size = list_offsets.size() - 1;
544 BIG ? std::string(
"+L") : std::string(
"+l"),
553 std::vector<buffer<std::uint8_t>> arr_buffs = {
554 std::move(vbitmap).extract_storage(),
555 std::move(list_offsets).extract_storage()
559 static_cast<std::int64_t
>(size),
560 static_cast<int64_t
>(null_count),
562 std::move(arr_buffs),
564 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
567 return arrow_proxy{std::move(arr), std::move(schema)};
573 , p_list_offsets(make_list_offsets())
583 p_list_offsets = make_list_offsets();
589 auto list_array_impl<BIG>::offset_range(size_type i)
const -> std::pair<offset_type, offset_type>
591 return std::make_pair(p_list_offsets[i], p_list_offsets[i + 1]);
595 auto list_array_impl<BIG>::make_list_offsets() -> offset_type*
597 return reinterpret_cast<offset_type*
>(
598 this->get_arrow_proxy().buffers()[OFFSET_BUFFER_INDEX].data() + this->get_arrow_proxy().offset()
609 , p_list_offsets(make_list_offsets())
610 , p_list_sizes(make_list_sizes())
615 template <val
idity_bitmap_input VB>
616 arrow_proxy list_view_array_impl<BIG>::create_proxy(
618 offset_buffer_type&& list_offsets,
619 size_buffer_type&& list_sizes,
621 std::optional<std::string_view> name,
622 std::optional<std::string_view> metadata
625 SPARROW_ASSERT(list_offsets.size() == list_sizes.size(),
"sizes and offset must have the same size");
627 const auto size = list_sizes.size();
635 BIG ? std::string(
"+vL") : std::string(
"+vl"),
644 std::vector<buffer<std::uint8_t>> arr_buffs = {
645 std::move(vbitmap).extract_storage(),
646 std::move(list_offsets).extract_storage(),
647 std::move(list_sizes).extract_storage()
651 static_cast<std::int64_t
>(size),
652 static_cast<int64_t
>(null_count),
654 std::move(arr_buffs),
656 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
659 return arrow_proxy{std::move(arr), std::move(schema)};
665 , p_list_offsets(make_list_offsets())
666 , p_list_sizes(make_list_sizes())
676 p_list_offsets = make_list_offsets();
677 p_list_sizes = make_list_sizes();
683 inline auto list_view_array_impl<BIG>::offset_range(size_type i)
const
684 -> std::pair<offset_type, offset_type>
686 const auto offset = p_list_offsets[i];
687 return std::make_pair(offset, offset + p_list_sizes[i]);
691 auto list_view_array_impl<BIG>::make_list_offsets() -> offset_type*
693 return reinterpret_cast<offset_type*
>(
694 this->get_arrow_proxy().buffers()[OFFSET_BUFFER_INDEX].data() + this->get_arrow_proxy().offset()
699 auto list_view_array_impl<BIG>::make_list_sizes() -> offset_type*
701 return reinterpret_cast<offset_type*
>(
702 this->get_arrow_proxy().buffers()[SIZES_BUFFER_INDEX].data() + this->get_arrow_proxy().offset()
707# pragma GCC diagnostic pop
714 inline auto fixed_sized_list_array::list_size_from_format(
const std::string_view format) -> uint64_t
717 const auto n_digits = format.size() - 3;
718 const auto list_size_str = format.substr(3, n_digits);
719 return std::stoull(std::string(list_size_str));
728 inline auto fixed_sized_list_array::offset_range(size_type i)
const -> std::pair<offset_type, offset_type>
730 const auto offset = i * m_list_size;
731 return std::make_pair(offset, offset + m_list_size);
734 template <val
idity_bitmap_input R>
735 inline arrow_proxy fixed_sized_list_array::create_proxy(
736 std::uint64_t list_size,
739 std::optional<std::string_view> name,
740 std::optional<std::string_view> metadata
743 const auto size = flat_values.size() /
static_cast<std::size_t
>(list_size);
750 std::string format =
"+w:" + std::to_string(list_size);
761 std::vector<buffer<std::uint8_t>> arr_buffs = {vbitmap.
extract_storage()};
764 static_cast<std::int64_t
>(size),
765 static_cast<int64_t
>(null_count),
767 std::move(arr_buffs),
769 new ArrowArray*[1]{
new ArrowArray(std::move(flat_arr))},
772 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...
#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
constexpr bool is_list_view_array_v
Checks whether T is a list_view_array type.
ArrowSchema make_arrow_schema(F format, N name, M metadata, std::optional< ArrowFlag > flags, int64_t n_children, ArrowSchema **children, ArrowSchema *dictionary)
Creates an ArrowSchema owned by a unique_ptr and holding the provided data.
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.
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.
ArrowArray make_arrow_array(int64_t length, int64_t null_count, int64_t offset, B buffers, size_t n_children, ArrowArray **children, ArrowArray *dictionary)
Creates an ArrowArray.
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()