23#if defined(__cpp_lib_format)
151 using base_type::insert;
152 using base_type::push_back;
153 using base_type::resize;
184 template <
class... Args>
260 return get_arrow_proxy().children()
261 | std::views::transform(
262 [](
const auto& child)
276 template <layout_or_array A>
293 template <std::ranges::input_range R>
307 template <layout_or_array A>
345 std::ranges::input_range CHILDREN_RANGE,
348 requires std::same_as<std::ranges::range_value_t<CHILDREN_RANGE>,
array>
350 CHILDREN_RANGE&& children,
352 std::optional<std::string_view> name = std::nullopt,
353 std::optional<METADATA_RANGE> metadata = std::nullopt
373 template <std::ranges::input_range CHILDREN_RANGE, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
374 requires std::same_as<std::ranges::range_value_t<CHILDREN_RANGE>,
array>
376 CHILDREN_RANGE&& children,
378 std::optional<std::string_view> name = std::nullopt,
379 std::optional<METADATA_RANGE> metadata = std::nullopt
401 template <std::ranges::input_range CHILDREN_RANGE, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
402 requires std::same_as<std::ranges::range_value_t<CHILDREN_RANGE>,
array>
404 CHILDREN_RANGE&& children,
405 std::optional<validity_bitmap>&& bitmap,
406 std::optional<std::string_view> name = std::nullopt,
407 std::optional<METADATA_RANGE> metadata = std::nullopt
450 template <std::input_iterator InputIt>
451 requires std::convertible_to<typename std::iterator_traits<InputIt>::value_type,
struct_value>
504 template <
class TRANSFORM>
505 void rebuild_children(
size_type new_length, TRANSFORM&& transform)
507 std::vector<array> new_children;
509 for (std::size_t child_index = 0; child_index <
children_count(); ++child_index)
512 transform(new_values, child_index);
516 new_children.push_back(std::move(new_child));
518 get_arrow_proxy().set_length(new_length);
519 for (std::size_t child_index = 0; child_index < new_children.size(); ++child_index)
521 set_child(std::move(new_children[child_index]), child_index);
537 template <std::ranges::input_range CHILDREN_RANGE, val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
538 requires std::same_as<std::ranges::range_value_t<CHILDREN_RANGE>,
array>
540 CHILDREN_RANGE&& children,
542 std::optional<std::string_view> name,
543 std::optional<METADATA_RANGE> metadata
546 const auto size = children.empty() ? 0 : children[0].size();
549 std::forward<CHILDREN_RANGE>(children),
556 template <std::input_iterator InputIt>
557 requires std::convertible_to<typename std::iterator_traits<InputIt>::value_type,
struct_value>
563 for (
auto it = first; it != last; ++it, ++count)
567 return std::next(
value_begin(),
static_cast<std::ptrdiff_t
>(index));
570 template <std::ranges::input_range CHILDREN_RANGE, input_metadata_container METADATA_RANGE>
571 requires std::same_as<std::ranges::range_value_t<CHILDREN_RANGE>,
array>
573 CHILDREN_RANGE&& children,
575 std::optional<std::string_view> name,
576 std::optional<METADATA_RANGE> metadata
579 const size_t size = children.empty() ? 0 : children[0].size();
581 std::forward<CHILDREN_RANGE>(children),
583 ? std::make_optional<validity_bitmap>(
nullptr, size, validity_bitmap::storage_type::allocator_type{})
590 template <std::ranges::input_range CHILDREN_RANGE, input_metadata_container METADATA_RANGE>
591 requires std::same_as<std::ranges::range_value_t<CHILDREN_RANGE>,
array>
593 CHILDREN_RANGE&& children,
594 std::optional<validity_bitmap>&& bitmap,
595 std::optional<std::string_view> name,
596 std::optional<METADATA_RANGE> metadata
599 const auto n_children = children.size();
603 const auto size = children.empty() ? 0 : children[0].size();
605 for (std::size_t i = 0; i < n_children; ++i)
607 auto& child = children[i];
610 child_arrays[i] =
new ArrowArray(std::move(flat_arr));
611 child_schemas[i] =
new ArrowSchema(std::move(flat_schema));
614 const bool bitmap_has_value = bitmap.has_value();
615 const auto null_count = bitmap_has_value ? bitmap->null_count() : 0;
616 const auto flags = bitmap_has_value
632 ? std::move(*bitmap).extract_storage()
635 std::vector<buffer<std::uint8_t>> arr_buffs;
637 arr_buffs.emplace_back(std::move(bitmap_buffer));
640 static_cast<std::int64_t
>(size),
641 static_cast<std::int64_t
>(null_count),
643 std::move(arr_buffs),
649 return arrow_proxy{std::move(arr), std::move(schema)};
652 template <layout_or_array A>
657 get_arrow_proxy().add_child(std::move(
array), std::move(schema));
658 m_children.emplace_back(
array_factory(get_arrow_proxy().children().back().view()));
661 template <std::ranges::input_range R>
665 for (
const auto& child : children)
669 m_children.reserve(m_children.size() + children.size());
670 for (
auto&& child : children)
672 add_child(std::forward<
decltype(child)>(child));
676 template <layout_or_array A>
681 get_arrow_proxy().set_child(index, std::move(
array), std::move(schema));
682 m_children[index] =
array_factory(get_arrow_proxy().children()[index].view());
686#if defined(__cpp_lib_format)
692 constexpr auto parse(std::format_parse_context& ctx)
698 ->
decltype(ctx.out());
typename base_type::const_bitmap_range const_bitmap_range
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 for array type erasure.
Dynamically typed array encapsulating an Arrow layout.
SPARROW_API size_type size() const
Object that owns a piece of contiguous memory.
xsimd::aligned_allocator< T > default_allocator
constexpr void reserve(size_type new_cap)
Base class definining common interface for arrays with a bitmap.
A view that repeats a value a given number of times.
SPARROW_API value_iterator erase_values(const_value_iterator pos, size_type count)
SPARROW_API inner_reference value(size_type i)
Gets mutable reference to struct at specified index.
array_inner_types< self_type > inner_types
SPARROW_API children_type make_children()
Creates the children array wrappers.
void add_child(A &&child)
Adds a child array to the struct.
static auto create_proxy_impl(CHILDREN_RANGE &&children, std::optional< validity_bitmap > &&bitmap, std::optional< std::string_view > name=std::nullopt, std::optional< METADATA_RANGE > metadata=std::nullopt) -> arrow_proxy
Implementation helper for creating Arrow proxy from components.
typename base_type::iterator iterator
SPARROW_API const_value_iterator value_cbegin() const
Gets const iterator to beginning of value range.
typename base_type::const_iterator const_iterator
SPARROW_API struct_array(const struct_array &rhs)
Copy constructor.
SPARROW_API struct_array(arrow_proxy proxy)
Constructs struct array from Arrow proxy.
SPARROW_API value_iterator insert_value(const_value_iterator pos, const struct_value &value, size_type count)
SPARROW_API value_iterator value_end()
Gets iterator to end of value range.
mutable_array_bitmap_base< self_type > base_type
SPARROW_API void resize_values(size_type new_length, const struct_value &value)
SPARROW_API void pop_children(size_t n)
Removes the last n children from the struct.
auto names() const
Gets the names of all child arrays.
void set_child(A &&child, size_t index)
Sets a child array at the specified index.
SPARROW_API inner_const_reference value(size_type i) const
Gets const reference to struct at specified index.
constexpr value_iterator insert_values(const_value_iterator pos, InputIt first, InputIt last)
SPARROW_API array_wrapper * raw_child(std::size_t i)
Gets mutable pointer to child array at specified index.
void add_children(R &&children)
Adds multiple children to the struct array.
SPARROW_API const array_wrapper * raw_child(std::size_t i) const
Gets const pointer to child array at specified index.
nullable< inner_value_type > value_type
nullable< inner_const_reference, bitmap_const_reference > const_reference
SPARROW_API value_iterator value_begin()
Gets iterator to beginning of value range.
struct_value inner_reference
struct_array(Args &&... args)
Generic constructor for creating struct array from various inputs.
typename base_type::size_type size_type
typename inner_types::value_iterator value_iterator
base_type::iterator_tag iterator_tag
struct_value inner_value_type
std::vector< cloning_ptr< array_wrapper > > children_type
typename base_type::bitmap_type bitmap_type
struct_array(struct_array &&)=default
struct_array & operator=(struct_array &&)=default
static auto create_proxy(CHILDREN_RANGE &&children, VB &&bitmaps, std::optional< std::string_view > name=std::nullopt, std::optional< METADATA_RANGE > metadata=std::nullopt) -> arrow_proxy
Creates Arrow proxy from children arrays with explicit validity bitmap.
struct_value inner_const_reference
SPARROW_API size_type children_count() const
Gets the number of child arrays (fields).
base_type::const_bitmap_range const_bitmap_range
SPARROW_API const_value_iterator value_cend() const
Gets const iterator to end of value range.
SPARROW_API struct_array & operator=(const struct_array &rhs)
Copy assignment operator.
typename base_type::bitmap_const_reference bitmap_const_reference
typename inner_types::const_value_iterator const_value_iterator
#define SPARROW_ASSERT_TRUE(expr__)
constexpr bool excludes_copy_and_move_ctor_v
Convenience variable template for excludes_copy_and_move_ctor.
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.
SPARROW_API void append_values(array &destination, const std::vector< array_traits::value_type > &values)
SPARROW_API array array_empty_like(const array &source)
constexpr bool is_struc_array_v
Type trait to check if a type is a struct_array.
std::pair< ArrowArray, ArrowSchema > extract_arrow_structures(A &&a)
Extracts the internal ArrowArray and ArrowSchema structures from the given array or typed layout.
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.
std::ostream & operator<<(std::ostream &os, const nullval_t &)
SPARROW_API cloning_ptr< array_wrapper > array_factory(arrow_proxy proxy)
validity_bitmap ensure_validity_bitmap(std::size_t size, R &&validity_input)
Ensures a validity bitmap of the specified size from various input types.
SPARROW_API array make_array_view(const array_wrapper &source)
data_type
Runtime identifier of arrow data types, usually associated with raw bytes with the associated value.
SPARROW_API std::vector< array_traits::value_type > snapshot_array(const array &source)
functor_index_iterator< detail::layout_value_functor< array_type, inner_value_type > > value_iterator
struct_value inner_value_type
struct_value inner_reference
functor_index_iterator< detail::layout_value_functor< const array_type, inner_value_type > > const_value_iterator
std::random_access_iterator_tag iterator_tag
struct_value inner_const_reference
Base class for array_inner_types specializations.
Traits class that must be specialized by array implementations.
static constexpr sparrow::data_type get()
Metafunction for retrieving the data_type of a typed array.