38 template <std::ranges::sized_range T,
class CR>
44 fixed_width_binary_traits::value_type,
45 fixed_width_binary_traits::const_reference>;
47 template <std::ranges::sized_range T,
class CR>
78 struct get_data_type_from_array;
90 template <std::ranges::sized_range T,
class CR>
97 sizeof(std::ranges::range_value_t<T>) ==
sizeof(
byte_t),
98 "Only sequences of types with the same size as byte_t are supported"
140 template <
class... ARGS>
143 :
base_type(create_proxy(std::forward<ARGS>(args)...))
148 using base_type::get_arrow_proxy;
149 using base_type::size;
174 std::optional<std::string_view> name = std::nullopt,
175 std::optional<METADATA_RANGE> metadata = std::nullopt
188 std::ranges::input_range R,
192 std::ranges::input_range<std::ranges::range_value_t<R>> &&
200 std::optional<std::string_view> name = std::nullopt,
201 std::optional<METADATA_RANGE> metadata = std::nullopt
213 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
215 && std::ranges::input_range<typename std::ranges::range_value_t<R>::value_type>
216 && std::is_same_v<std::ranges::range_value_t<typename std::ranges::range_value_t<R>::value_type>,
byte_t>
217 [[nodiscard]]
static arrow_proxy create_proxy(
219 std::optional<std::string_view> name = std::nullopt,
220 std::optional<METADATA_RANGE> metadata = std::nullopt
223 static constexpr size_t DATA_BUFFER_INDEX = 1;
227 [[nodiscard]] value_iterator value_begin();
228 [[nodiscard]] value_iterator value_end();
237 template <std::ranges::sized_range U>
238 requires mpl::convertible_ranges<U, T>
239 void resize_values(size_type new_length, U
value);
241 template <std::ranges::sized_range U>
242 requires mpl::convertible_ranges<U, T>
245 template <
typename InputIt>
246 requires std::input_iterator<InputIt>
247 && mpl::convertible_ranges<typename std::iterator_traits<InputIt>::value_type, T>
252 template <std::ranges::sized_range U>
253 requires mpl::convertible_ranges<U, T>
254 void assign(U&& rhs, size_type index);
256 size_t m_element_size = 0;
269 template <std::ranges::sized_range T,
class CR>
277 template <std::ranges::sized_range T,
class CR>
278 template <mpl::
char_like C, val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
279 arrow_proxy fixed_width_binary_array_impl<T, CR>::create_proxy(
283 std::optional<std::string_view> name,
284 std::optional<METADATA_RANGE> metadata
288 const size_t element_count = data_buffer.size() / element_size;
292 std::string format_str =
"w:" + std::to_string(element_size);
295 std::move(format_str),
305 std::vector<buffer<std::uint8_t>> arr_buffs = {
306 std::move(vbitmap).extract_storage(),
307 std::move(data_buffer).extract_storage()
311 static_cast<std::int64_t
>(element_count),
312 static_cast<int64_t
>(null_count),
314 std::move(arr_buffs),
316 repeat_view<bool>(
true, 0),
320 return arrow_proxy{std::move(arr), std::move(schema)};
323 template <std::ranges::sized_range T,
class CR>
324 template <std::ranges::input_range R, val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
326 std::ranges::input_range<std::ranges::range_value_t<R>> &&
330 arrow_proxy fixed_width_binary_array_impl<T, CR>::create_proxy(
333 std::optional<std::string_view> name,
334 std::optional<METADATA_RANGE> metadata
337 using values_type = std::ranges::range_value_t<R>;
338 using values_inner_value_type = std::ranges::range_value_t<values_type>;
342 const size_t element_size = std::ranges::size(*values.begin());
346 std::move(data_buffer),
348 std::forward<VB>(validity_input),
349 std::forward<std::optional<std::string_view>>(name),
350 std::forward<std::optional<METADATA_RANGE>>(metadata)
354 template <std::ranges::sized_range T,
class CR>
355 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE>
357 && std::ranges::input_range<typename std::ranges::range_value_t<R>::value_type>
358 && std::is_same_v<std::ranges::range_value_t<typename std::ranges::range_value_t<R>::value_type>,
byte_t>
359 arrow_proxy fixed_width_binary_array_impl<T, CR>::create_proxy(
361 std::optional<std::string_view> name,
362 std::optional<METADATA_RANGE> metadata
366 const auto values = range
367 | std::views::transform(
373 const auto is_non_null = range
374 | std::views::transform(
377 return v.has_value();
380 return self_type::create_proxy(values, is_non_null, std::move(name), std::move(metadata));
383 template <std::ranges::sized_range T,
class CR>
384 auto fixed_width_binary_array_impl<T, CR>::data(size_type i) -> data_iterator
386 const arrow_proxy& proxy = this->get_arrow_proxy();
387 auto data_buffer = proxy.buffers()[DATA_BUFFER_INDEX];
388 const size_t data_buffer_size = data_buffer.size();
389 const size_type index_offset = (
static_cast<size_type
>(proxy.offset()) * m_element_size) + i;
391 return data_buffer.template data<data_value_type>() + index_offset;
394 template <std::ranges::sized_range T,
class CR>
395 auto fixed_width_binary_array_impl<T, CR>::data(size_type i)
const -> const_data_iterator
397 const arrow_proxy& proxy = this->get_arrow_proxy();
398 const auto data_buffer = proxy.buffers()[DATA_BUFFER_INDEX];
399 const size_t data_buffer_size = data_buffer.size();
400 const size_type index_offset = (
static_cast<size_type
>(proxy.offset()) * m_element_size) + i;
402 return data_buffer.template data<const data_value_type>() + index_offset;
405 template <std::ranges::sized_range T,
class CR>
406 template <std::ranges::sized_range U>
408 void fixed_width_binary_array_impl<T, CR>::assign(U&& rhs, size_type index)
412 std::copy(std::ranges::begin(rhs), std::ranges::end(rhs), data(index * m_element_size));
415 template <std::ranges::sized_range T,
class CR>
422 template <std::ranges::sized_range T,
class CR>
426 const auto offset_begin = i * m_element_size;
427 const auto offset_end = offset_begin + m_element_size;
433 template <std::ranges::sized_range T,
class CR>
434 auto fixed_width_binary_array_impl<T, CR>::value_begin() -> value_iterator
436 return value_iterator{functor_type{&(this->derived_cast())}, 0};
439 template <std::ranges::sized_range T,
class CR>
440 auto fixed_width_binary_array_impl<T, CR>::value_end() -> value_iterator
445 template <std::ranges::sized_range T,
class CR>
446 auto fixed_width_binary_array_impl<T, CR>::value_cbegin() const -> const_value_iterator
448 return const_value_iterator{const_functor_type{&(this->derived_cast())}, 0};
451 template <std::ranges::sized_range T,
class CR>
452 auto fixed_width_binary_array_impl<T, CR>::value_cend() const -> const_value_iterator
457 template <std::ranges::sized_range T,
class CR>
458 template <std::ranges::sized_range U>
460 void fixed_width_binary_array_impl<T, CR>::resize_values(size_type new_length, U value)
463 if (new_length <
size())
466 const size_t new_size = new_length +
static_cast<size_t>(proxy.offset());
467 const auto offset = new_size * m_element_size;
468 auto& data_buffer = proxy.get_array_private_data()->buffers()[DATA_BUFFER_INDEX];
469 data_buffer.resize(offset);
471 else if (new_length >
size())
473 insert_value(value_cend(), value, new_length -
size());
477 template <std::ranges::sized_range T,
class CR>
478 template <std::ranges::sized_range U>
484 const auto idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
486 const uint8_t* uint8_ptr =
reinterpret_cast<const uint8_t*
>(
value.data());
487 const std::vector<uint8_t> casted_value(uint8_ptr, uint8_ptr +
value.size());
489 const auto joined_repeated_value_range = std::ranges::views::join(my_repeat_view);
492 const auto offset_begin = (idx + proxy.
offset()) * m_element_size;
493 const auto pos_to_insert =
sparrow::next(data_buffer.cbegin(), offset_begin);
494 data_buffer.insert(pos_to_insert, joined_repeated_value_range.begin(), joined_repeated_value_range.end());
498 template <std::ranges::sized_range T,
class CR>
499 template <
typename InputIt>
500 requires std::input_iterator<InputIt>
512 auto values = std::ranges::subrange(first, last);
513 const size_t cumulative_sizes = values.size() * m_element_size;
514 auto& data_buffer = get_arrow_proxy().get_array_private_data()->buffers()[DATA_BUFFER_INDEX];
515 data_buffer.resize(data_buffer.size() + cumulative_sizes);
516 const auto idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
517 std::span<byte_t> casted_values{
reinterpret_cast<byte_t*
>(data_buffer.data()), data_buffer.size()};
518 const auto offset_begin = m_element_size * (idx + get_arrow_proxy().offset());
519 auto insert_pos =
sparrow::next(casted_values.begin(), offset_begin);
528 for (
const auto& val : values)
530 std::copy(val.begin(), val.end(), insert_pos);
531 std::advance(insert_pos, m_element_size);
536 template <std::ranges::sized_range T,
class CR>
537 auto fixed_width_binary_array_impl<T, CR>::erase_values(const_value_iterator pos, size_type count)
542 const size_t index =
static_cast<size_t>(std::distance(value_cbegin(), pos));
547 auto& data_buffer = get_arrow_proxy().get_array_private_data()->buffers()[DATA_BUFFER_INDEX];
548 const size_type byte_count = m_element_size * count;
549 const auto offset_begin = m_element_size * (index +
static_cast<size_type
>(get_arrow_proxy().offset()));
550 const auto offset_end = offset_begin + byte_count;
553 data_buffer.begin() +
static_cast<difference_type
>(offset_end),
555 data_buffer.begin() +
static_cast<difference_type
>(offset_begin)
557 data_buffer.resize(data_buffer.size() - byte_count);
typename base_type::const_bitmap_range const_bitmap_range
typename base_type::iterator_tag iterator_tag
std::conditional_t< is_mutable, mutable_array_base< D >, array_crtp_base< D > > base_type
typename base_type::bitmap_const_reference bitmap_const_reference
typename base_type::bitmap_type bitmap_type
typename base_type::difference_type difference_type
constexpr BufferType & buffers() noexcept
Proxy class over ArrowArray and ArrowSchema.
SPARROW_API size_t offset() const
SPARROW_API arrow_array_private_data * get_array_private_data()
constexpr size_type null_count() const noexcept
bitset_iterator< self_type, true > const_iterator
typename inner_types::data_value_type data_value_type
fixed_width_binary_array_impl< T, fixed_width_binary_traits::const_reference > self_type
typename inner_types::const_functor_type const_functor_type
array_inner_types< self_type > inner_types
inner_reference value(size_type i)
nullable< inner_reference, bitmap_reference > reference
typename inner_types::value_iterator value_iterator
typename base_type::size_type size_type
typename base_type::difference_type difference_type
typename inner_types::inner_value_type inner_value_type
typename base_type::const_bitmap_range const_bitmap_range
mutable_array_bitmap_base< self_type > base_type
fixed_width_binary_array_impl(arrow_proxy)
nullable< inner_value_type > value_type
fixed_width_binary_array_impl(ARGS &&... args)
Constructs a fixed-width binary array.
inner_const_reference value(size_type i) const
nullable< inner_const_reference, bitmap_const_reference > const_reference
typename inner_types::data_iterator data_iterator
typename inner_types::inner_const_reference inner_const_reference
typename inner_types::const_value_iterator const_value_iterator
typename base_type::iterator_tag iterator_tag
typename inner_types::inner_reference inner_reference
typename base_type::bitmap_const_reference bitmap_const_reference
typename base_type::bitmap_type bitmap_type
typename inner_types::functor_type functor_type
typename inner_types::const_data_iterator const_data_iterator
typename base_type::bitmap_reference bitmap_reference
Implementation of reference to inner type used for layout L.
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.
Matches range types From whose elements are convertible to elements of range type To.
#define SPARROW_ASSERT_TRUE(expr__)
constexpr std::size_t size(typelist< T... >={})
constexpr bool excludes_copy_and_move_ctor_v
constexpr bool is_type_instance_of_v
true if T is a concrete type template instanciation of U which is a type template.
array_bitmap_base_impl< D, true > mutable_array_bitmap_base
Convenient typedef to be used as a crtp base class for arrays using a mutable validity buffer.
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 all_same_size(const Range &range)
arrow_traits< std::vector< byte_t > > fixed_width_binary_traits
constexpr InputIt next(InputIt it, Distance n)
fixed_width_binary_array_impl< fixed_width_binary_traits::value_type, fixed_width_binary_traits::const_reference > fixed_width_binary_array
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
SPARROW_API std::size_t num_bytes_for_fixed_sized_binary(std::string_view format)
Get the number of bytes for a fixed width binary layout from the ArrowArray format string.
validity_bitmap ensure_validity_bitmap(std::size_t size, R &&validity_input)
data_type
Runtime identifier of arrow data types, usually associated with raw bytes with the associated value.
fixed_width_binary_array_impl< T, CR > array_type
functor_index_iterator< const_functor_type > const_iterator
detail::layout_value_functor< array_type, inner_reference > functor_type
detail::layout_value_functor< const array_type, inner_const_reference > const_functor_type
functor_index_iterator< functor_type > iterator
const_iterator const_value_iterator
data_value_type * data_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
bitmap_type::const_iterator const_bitmap_iterator
std::random_access_iterator_tag iterator_tag
const data_value_type * const_data_iterator
fixed_width_binary_reference< array_type > inner_reference
typename T::value_type data_value_type
Base class for array_inner_types specialization.
Traits class that must be specialized by array classes inheriting from array_crtp_base.
Provides compile-time information about Arrow data types.
static constexpr sparrow::data_type get()