72 template <
class DERIVED>
90 [[nodiscard]] std::optional<std::string_view>
name()
const;
91 [[nodiscard]] std::optional<std::string_view>
metadata()
const;
99 [[nodiscard]]
bool empty()
const;
120 template <std::ranges::input_range R>
123 template <std::ranges::input_range R>
124 requires(std::convertible_to<std::ranges::range_value_t<R>, std::uint8_t>)
150#if defined(__cpp_lib_format)
151 friend struct std::formatter<DERIVED>;
166 template <
class... Args>
185 template <std::ranges::input_range TYPE_MAPPING = std::vector<std::u
int8_t>>
186 requires(std::convertible_to<std::ranges::range_value_t<TYPE_MAPPING>, std::uint8_t>)
187 static auto create_proxy(
188 std::vector<array>&& children,
191 TYPE_MAPPING&& type_mapping = TYPE_MAPPING{},
192 std::optional<std::string_view>
name = std::nullopt,
193 std::optional<std::string_view>
metadata = std::nullopt
197 std::vector<array>&& children,
200 std::string&& format,
202 std::optional<std::string_view>
name = std::nullopt,
203 std::optional<std::string_view>
metadata = std::nullopt
206 SPARROW_API std::size_t element_offset(std::size_t i)
const;
208 const std::int32_t* p_offsets;
219 template <
class... Args>
232 template <std::ranges::input_range TYPE_MAPPING = std::vector<std::u
int8_t>>
233 requires(std::convertible_to<std::ranges::range_value_t<TYPE_MAPPING>, std::uint8_t>)
234 static auto create_proxy(
235 std::vector<array>&& children,
237 TYPE_MAPPING&& type_mapping = TYPE_MAPPING{}
241 std::vector<array>&& children,
243 std::string&& format,
255 template <
class DERIVED>
260 format_string.remove_prefix(4);
262 constexpr std::string_view delim{
","};
263 std::size_t child_index = 0;
264 std::ranges::for_each(
265 format_string | std::views::split(delim),
268 const auto as_int = std::atoi(std::string(s.begin(), s.end()).c_str());
269 ret[
static_cast<std::size_t
>(as_int)] =
static_cast<std::uint8_t
>(child_index);
276 template <
class DERIVED>
277 template <std::ranges::input_range R>
281 const std::size_t n = std::ranges::size(child_index_to_type_id);
282 std::array<std::uint8_t, 256> ret;
285 for (std::size_t i = 0; i < 256; ++i)
287 ret[i] =
static_cast<std::uint8_t
>(i);
292 for (std::size_t i = 0; i < n; ++i)
294 ret[child_index_to_type_id[i]] =
static_cast<std::uint8_t
>(i);
300 template <
class DERIVED>
301 template <std::ranges::input_range R>
302 requires(std::convertible_to<std::ranges::range_value_t<R>, std::uint8_t>)
305 const auto range_size = std::ranges::size(range);
308 std::string ret = dense ?
"+ud:" :
"+us:";
311 for (std::size_t i = 0; i < n; ++i)
313 ret += std::to_string(i) +
",";
318 for (
const auto& v : range)
320 ret += std::to_string(v) +
",";
328 throw std::invalid_argument(
"Invalid type-id map");
332 template <
class DERIVED>
338 template <
class DERIVED>
344 template <
class DERIVED>
350 template <
class DERIVED>
356 template <
class DERIVED>
365 template <
class DERIVED>
371 template <
class DERIVED>
384 template <
class DERIVED>
387 const auto type_id =
static_cast<std::size_t
>(
p_type_ids[i]);
389 const auto offset = this->
derived_cast().element_offset(i);
393 template <
class DERIVED>
399 template <
class DERIVED>
405 template <
class DERIVED>
411 template <
class DERIVED>
417 template <
class DERIVED>
423 template <
class DERIVED>
429 template <
class DERIVED>
435 template <
class DERIVED>
441 template <
class DERIVED>
447 template <
class DERIVED>
453 template <
class DERIVED>
459 template <
class DERIVED>
465 template <
class DERIVED>
471 template <
class DERIVED>
477 template <
class DERIVED>
480 return (*
this)[this->
size() - 1];
483 template <
class DERIVED>
487 for (std::size_t i = 0; i < children.size(); ++i)
497 return std::ranges::equal(lhs, rhs);
504 template <std::ranges::input_range TYPE_MAPPING>
505 requires(std::convertible_to<std::ranges::range_value_t<TYPE_MAPPING>, std::uint8_t>)
506 auto dense_union_array::create_proxy(
507 std::vector<array>&& children,
508 type_id_buffer_type&& element_type,
509 offset_buffer_type&& offsets,
510 TYPE_MAPPING&& child_index_to_type_id,
511 std::optional<std::string_view> name,
512 std::optional<std::string_view> metadata
515 const auto n_children = children.size();
518 auto type_id_to_child_index = type_id_map_from_child_to_type_id(child_index_to_type_id);
520 std::string format = make_format_string(
523 std::forward<TYPE_MAPPING>(child_index_to_type_id)
526 return create_proxy_impl(
528 std::move(element_type),
531 std::move(type_id_to_child_index),
541 template <std::ranges::input_range TYPE_MAPPING>
542 requires(std::convertible_to<std::ranges::range_value_t<TYPE_MAPPING>, std::uint8_t>)
543 auto sparse_union_array::create_proxy(
544 std::vector<array>&& children,
545 type_id_buffer_type&& element_type,
546 TYPE_MAPPING&& child_index_to_type_id
549 const auto n_children = children.size();
552 auto type_id_to_child_index = type_id_map_from_child_to_type_id(child_index_to_type_id);
554 std::string format = make_format_string(
557 std::forward<TYPE_MAPPING>(child_index_to_type_id)
560 return create_proxy_impl(
562 std::move(element_type),
564 std::move(type_id_to_child_index)
569#if defined(__cpp_lib_format)
572 requires std::derived_from<U, sparrow::union_array_crtp_base<U>>
573struct std::formatter<U>
575 constexpr auto parse(std::format_parse_context& ctx)
580 auto format(
const U& ar, std::format_context& ctx)
const
582 if constexpr (std::is_same_v<U, sparrow::dense_union_array>)
584 std::format_to(ctx.out(),
"DenseUnion");
586 else if constexpr (std::is_same_v<U, sparrow::sparse_union_array>)
588 std::format_to(ctx.out(),
"SparseUnion");
592 static_assert(sparrow::mpl::dependent_false<U>::value,
"Unknown union array type");
595 const auto& proxy = ar.get_arrow_proxy();
596 std::format_to(ctx.out(),
" [name={} | size={}] <", proxy.name().value_or(
"nullptr"), proxy.length());
600 std::prev(ar.cend()),
601 [&ctx](
const auto& value)
603 std::format_to(ctx.out(),
"{}, ", value);
607 return std::format_to(ctx.out(),
"{}>", ar.back());
613 template <
typename U>
614 requires std::derived_from<U, sparrow::union_array_crtp_base<U>>
615 std::ostream&
operator<<(std::ostream& os,
const U& value)
617 os << std::format(
"{}", value);
void sparse_union_array()
Proxy class over ArrowArray and ArrowSchema.
Base class for CRTP base classes.
derived_type & derived_cast()
SPARROW_API dense_union_array & operator=(const dense_union_array &rhs)
u8_buffer< std::uint32_t > offset_buffer_type
union_array_crtp_base< dense_union_array > base_type
typename base_type::type_id_buffer_type type_id_buffer_type
dense_union_array(Args &&... args)
SPARROW_API dense_union_array(arrow_proxy proxy)
SPARROW_API dense_union_array(const dense_union_array &rhs)
dense_union_array(dense_union_array &&rhs)=default
dense_union_array & operator=(dense_union_array &&rhs)=default
sparse_union_array(Args &&... args)
union_array_crtp_base< sparse_union_array > base_type
typename base_type::type_id_buffer_type type_id_buffer_type
SPARROW_API sparse_union_array(arrow_proxy proxy)
array_traits::inner_value_type inner_value_type
std::reverse_iterator< const_iterator > const_reverse_iterator
std::array< std::uint8_t, 256 > type_id_map
const_iterator begin() const
self_type & operator=(self_type &&rhs)=default
const std::uint8_t * p_type_ids
union_array_crtp_base(const self_type &rhs)
static std::string make_format_string(bool dense, std::size_t n, R &&child_index_to_type_id)
detail::layout_bracket_functor< const derived_type, value_type > const_functor_type
union_array_crtp_base(self_type &&rhs)=default
array_traits::const_reference value_type
u8_buffer< std::uint8_t > type_id_buffer_type
const_reverse_iterator rend() const
std::array< std::uint8_t, 256 > m_type_id_map
self_type & operator=(const self_type &rhs)
const_iterator cbegin() const
union_array_crtp_base< DERIVED > self_type
const_iterator cend() const
union_array_crtp_base(arrow_proxy proxy)
value_type operator[](size_type i)
detail::layout_bracket_functor< derived_type, value_type > functor_type
const_reverse_iterator crbegin() const
const_reverse_iterator crend() const
static type_id_map parse_type_id_map(std::string_view format_string)
functor_index_iterator< const_functor_type > const_iterator
value_type operator[](size_type i) const
value_type at(size_type i) const
functor_index_iterator< functor_type > iterator
const_reverse_iterator rbegin() const
const arrow_proxy & get_arrow_proxy() const
std::optional< std::string_view > name() const
static type_id_map type_id_map_from_child_to_type_id(R &&child_index_to_type_id)
arrow_proxy & get_arrow_proxy()
children_type make_children(arrow_proxy &proxy)
const_iterator end() const
std::optional< std::string_view > metadata() const
std::vector< cloning_ptr< array_wrapper > > children_type
constexpr bool excludes_copy_and_move_ctor_v
void unreachable()
Invokes undefined behavior.
constexpr bool is_dense_union_array_v
Checks whether T is a dense_union_array type.
SPARROW_API bool operator==(const array &lhs, const array &rhs)
Compares the content of two arrays.
SPARROW_API cloning_ptr< array_wrapper > array_factory(arrow_proxy proxy)
SPARROW_API array_traits::const_reference array_element(const array_wrapper &ar, std::size_t index)
std::ostream & operator<<(std::ostream &stream, T n)
constexpr bool is_sparse_union_array_v
Checks whether T is a sparse_union_array type.
std::size_t range_size(R &&r)
data_type
Runtime identifier of arrow data types, usually associated with raw bytes with the associated value.
mpl::rename< mpl::transform< detail::array_const_reference_t, all_base_types_t >, nullable_variant > const_reference
mpl::rename< all_base_types_t, std::variant > inner_value_type
static constexpr sparrow::data_type get()
static constexpr sparrow::data_type get()