45 template <std::ranges::sized_range T,
typename CR,
typename Ext = empty_extension>
80 fixed_width_binary_traits::value_type,
81 fixed_width_binary_traits::const_reference>;
88 return "fixed_width_binary_array";
92 template <std::ranges::sized_range T,
typename CR,
typename Ext>
132 template <std::ranges::sized_range T,
class CR,
class Ext>
140 sizeof(std::ranges::range_value_t<T>) ==
sizeof(
byte_t),
141 "Only sequences of types with the same size as byte_t are supported"
215 template <class... ARGS>
223 using base_type::get_arrow_proxy;
224 using base_type::size;
281 size_t element_count,
284 std::optional<std::string_view> name = std::nullopt,
285 std::optional<METADATA_RANGE> metadata = std::nullopt
303 template <input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
307 std::optional<std::string_view> name = std::nullopt,
308 std::optional<METADATA_RANGE> metadata = std::nullopt
332 std::ranges::input_range VALUES,
336 std::ranges::input_range<std::ranges::range_value_t<VALUES>>
342 std::optional<std::string_view> name = std::nullopt,
343 std::optional<METADATA_RANGE> metadata = std::nullopt
365 template <std::ranges::input_range VALUES, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
367 std::ranges::input_range<std::ranges::range_value_t<VALUES>>
373 std::optional<std::string_view> name = std::nullopt,
374 std::optional<METADATA_RANGE> metadata = std::nullopt
394 template <std::ranges::input_range NULLABLE_VALUES, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
396 && std::ranges::input_range<typename std::ranges::range_value_t<NULLABLE_VALUES>::value_type>
398 std::ranges::range_value_t<typename std::ranges::range_value_t<NULLABLE_VALUES>::value_type>,
402 std::optional<std::string_view> name = std::nullopt,
403 std::optional<METADATA_RANGE> metadata = std::nullopt
429 template <mpl::
char_like C, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
430 [[nodiscard]]
static arrow_proxy create_proxy_impl(
432 size_t element_count,
434 std::optional<validity_bitmap>&& validity_input,
435 std::optional<std::string_view> name = std::nullopt,
436 std::optional<METADATA_RANGE> metadata = std::nullopt
439 static constexpr size_t DATA_BUFFER_INDEX = 1;
449 [[nodiscard]]
constexpr size_type byte_offset(size_type index)
const
451 return (index +
static_cast<size_type
>(this->get_arrow_proxy().offset())) * m_element_size;
461 [[nodiscard]]
constexpr auto& get_data_buffer()
463 return this->get_arrow_proxy().get_array_private_data()->buffers()[DATA_BUFFER_INDEX];
473 [[nodiscard]]
constexpr const auto& get_data_buffer()
const
475 return this->get_arrow_proxy().buffers()[DATA_BUFFER_INDEX];
558 template <std::ranges::sized_range U>
559 requires mpl::convertible_ranges<U, T>
581 template <std::ranges::sized_range U>
582 requires mpl::convertible_ranges<U, T>
610 template <
typename InputIt>
611 requires std::input_iterator<InputIt>
612 && mpl::convertible_ranges<typename std::iterator_traits<InputIt>::value_type, T>
651 template <std::ranges::sized_range U>
652 requires mpl::convertible_ranges<U, T>
653 constexpr void assign(U&& rhs,
size_type index);
655 size_t m_element_size = 0;
668 template <std::ranges::sized_range T,
typename CR,
typename Ext>
676 template <std::ranges::sized_range T,
typename CR,
typename Ext>
679 , m_element_size(rhs.m_element_size)
684 template <std::ranges::sized_range T,
typename CR,
typename Ext>
690 m_element_size = rhs.m_element_size;
696 template <std::ranges::sized_range T,
typename CR,
typename Ext>
697 template <mpl::
char_like C, val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
698 arrow_proxy fixed_width_binary_array_impl<T, CR, Ext>::create_proxy(
700 size_t element_count,
703 std::optional<std::string_view> name,
704 std::optional<METADATA_RANGE> metadata
708 return create_proxy_impl(
709 std::move(data_buffer),
718 template <std::ranges::sized_range T,
typename CR,
typename Ext>
719 template <input_metadata_container METADATA_RANGE>
720 arrow_proxy fixed_width_binary_array_impl<T, CR, Ext>::create_proxy(
723 std::optional<std::string_view> name,
724 std::optional<METADATA_RANGE> metadata
727 u8_buffer<char> data_buffer{};
728 std::optional<validity_bitmap> bitmap =
nullable ? std::make_optional<validity_bitmap>(
734 return create_proxy_impl(
735 std::move(data_buffer),
744 template <std::ranges::sized_range T,
typename CR,
typename Ext>
745 template <std::ranges::input_range R, val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
747 std::ranges::input_range<std::ranges::range_value_t<R>> &&
751 arrow_proxy fixed_width_binary_array_impl<T, CR, Ext>::create_proxy(
754 std::optional<std::string_view> name,
755 std::optional<METADATA_RANGE> metadata
758 using values_type = std::ranges::range_value_t<R>;
759 using values_inner_value_type = std::ranges::range_value_t<values_type>;
762 const size_t element_size = std::ranges::empty(values) ? 0 : std::ranges::size(*values.begin());
766 std::move(data_buffer),
769 std::forward<VB>(validity_input),
770 std::forward<std::optional<std::string_view>>(name),
771 std::forward<std::optional<METADATA_RANGE>>(metadata)
775 template <std::ranges::sized_range T,
typename CR,
typename Ext>
776 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE>
778 std::ranges::input_range<std::ranges::range_value_t<R>> &&
782 arrow_proxy fixed_width_binary_array_impl<T, CR, Ext>::create_proxy(
785 std::optional<std::string_view> name,
786 std::optional<METADATA_RANGE> metadata
792 std::forward<R>(values),
800 using values_type = std::ranges::range_value_t<R>;
801 using values_inner_value_type = std::ranges::range_value_t<values_type>;
804 const size_t element_size = std::ranges::empty(values) ? 0 : std::ranges::size(*values.begin());
806 return create_proxy_impl(
807 std::move(data_buffer),
817 template <std::ranges::sized_range T,
typename CR,
typename Ext>
818 template <std::ranges::input_range NULLABLE_RANGE, input_metadata_container METADATA_RANGE>
820 && std::ranges::input_range<typename std::ranges::range_value_t<NULLABLE_RANGE>::value_type>
822 std::ranges::range_value_t<typename std::ranges::range_value_t<NULLABLE_RANGE>::value_type>,
824 arrow_proxy fixed_width_binary_array_impl<T, CR, Ext>::create_proxy(
825 NULLABLE_RANGE&& range,
826 std::optional<std::string_view> name,
827 std::optional<METADATA_RANGE> metadata
831 const auto values = range
832 | std::views::transform(
838 const auto is_non_null = range
839 | std::views::transform(
842 return v.has_value();
845 return self_type::create_proxy(values, is_non_null, std::move(name), std::move(metadata));
848 template <std::ranges::sized_range T,
typename CR,
typename Ext>
849 template <mpl::
char_like C, input_metadata_container METADATA_RANGE>
850 arrow_proxy fixed_width_binary_array_impl<T, CR, Ext>::create_proxy_impl(
852 size_t element_count,
854 std::optional<validity_bitmap>&& bitmap,
855 std::optional<std::string_view> name,
856 std::optional<METADATA_RANGE> metadata
860 element_size == 0 ? (data_buffer.size() == 0) : (data_buffer.size() % element_size == 0)
863 const auto null_count = bitmap.has_value() ? bitmap->null_count() : 0;
864 std::string format_str =
"w:" + std::to_string(element_size);
865 const std::optional<std::unordered_set<ArrowFlag>>
866 flags = bitmap.has_value()
871 std::move(format_str),
876 repeat_view<bool>(
true, 0),
881 std::vector<buffer<std::uint8_t>> arr_buffs;
882 arr_buffs.reserve(2);
883 arr_buffs.emplace_back(
884 bitmap.has_value() ? std::move(*bitmap).extract_storage()
885 : buffer<std::uint8_t>{nullptr, 0, validity_bitmap::default_allocator()}
887 arr_buffs.emplace_back(std::move(data_buffer).extract_storage());
890 static_cast<std::int64_t
>(element_count),
891 static_cast<int64_t
>(null_count),
893 std::move(arr_buffs),
895 repeat_view<bool>(
true, 0),
899 arrow_proxy proxy{std::move(arr), std::move(schema)};
904 template <std::ranges::sized_range T,
typename CR,
typename Ext>
905 constexpr auto fixed_width_binary_array_impl<T, CR, Ext>::data(size_type i) -> data_iterator
907 return const_cast<data_iterator
>(std::as_const(*this).data(i));
910 template <std::ranges::sized_range T,
typename CR,
typename Ext>
911 constexpr auto fixed_width_binary_array_impl<T, CR, Ext>::data(size_type i)
const -> const_data_iterator
913 const auto& data_buffer = get_data_buffer();
914 const size_t data_buffer_size = data_buffer.size();
915 const size_type index_offset = (
static_cast<size_type
>(this->get_arrow_proxy().offset())
919 return data_buffer.template data<const data_value_type>() + index_offset;
922 template <std::ranges::sized_range T,
typename CR,
typename Ext>
923 template <std::ranges::sized_range U>
925 constexpr void fixed_width_binary_array_impl<T, CR, Ext>::assign(U&& rhs, size_type index)
929 std::copy(std::ranges::begin(rhs), std::ranges::end(rhs), data(index * m_element_size));
932 template <std::ranges::sized_range T,
typename CR,
typename Ext>
939 template <std::ranges::sized_range T,
typename CR,
typename Ext>
943 const auto offset_begin = i * m_element_size;
944 const auto offset_end = offset_begin + m_element_size;
950 template <std::ranges::sized_range T,
typename CR,
typename Ext>
951 constexpr auto fixed_width_binary_array_impl<T, CR, Ext>::value_begin() -> value_iterator
953 return value_iterator{functor_type{&(this->derived_cast())}, 0};
956 template <std::ranges::sized_range T,
typename CR,
typename Ext>
957 constexpr auto fixed_width_binary_array_impl<T, CR, Ext>::value_end() -> value_iterator
962 template <std::ranges::sized_range T,
typename CR,
typename Ext>
963 constexpr auto fixed_width_binary_array_impl<T, CR, Ext>::value_cbegin() const -> const_value_iterator
965 return const_value_iterator{const_functor_type{&(this->derived_cast())}, 0};
968 template <std::ranges::sized_range T,
typename CR,
typename Ext>
969 constexpr auto fixed_width_binary_array_impl<T, CR, Ext>::value_cend() const -> const_value_iterator
974 template <std::ranges::sized_range T,
typename CR,
typename Ext>
975 template <std::ranges::sized_range U>
977 constexpr void fixed_width_binary_array_impl<T, CR, Ext>::resize_values(size_type new_length, U value)
980 if (new_length <
size())
982 const size_t new_size = new_length +
static_cast<size_t>(this->get_arrow_proxy().offset());
983 const auto offset = new_size * m_element_size;
984 auto& data_buffer = get_data_buffer();
985 data_buffer.resize(offset);
987 else if (new_length >
size())
989 insert_value(value_cend(), value, new_length -
size());
993 template <std::ranges::sized_range T,
typename CR,
typename Ext>
994 template <std::ranges::sized_range U>
1001 const auto idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
1003 const uint8_t* uint8_ptr =
reinterpret_cast<const uint8_t*
>(
value.data());
1004 const std::vector<uint8_t> casted_value(uint8_ptr, uint8_ptr +
value.size());
1006 const auto joined_repeated_value_range = std::ranges::views::join(my_repeat_view);
1007 auto& data_buffer = get_data_buffer();
1008 const auto offset_begin = byte_offset(idx);
1009 const auto pos_to_insert =
sparrow::next(data_buffer.cbegin(), offset_begin);
1010 data_buffer.insert(pos_to_insert, joined_repeated_value_range.begin(), joined_repeated_value_range.end());
1014 template <std::ranges::sized_range T,
typename CR,
typename Ext>
1015 template <
typename InputIt>
1016 requires std::input_iterator<InputIt>
1028 auto values = std::ranges::subrange(first, last);
1029 const size_t cumulative_sizes = values.size() * m_element_size;
1030 auto& data_buffer = get_data_buffer();
1031 data_buffer.resize(data_buffer.size() + cumulative_sizes);
1032 const auto idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
1034 const auto offset_begin = byte_offset(idx);
1035 auto insert_pos =
sparrow::next(casted_values.begin(), offset_begin);
1044 for (
const auto& val : values)
1046 std::copy(val.begin(), val.end(), insert_pos);
1047 std::advance(insert_pos, m_element_size);
1052 template <std::ranges::sized_range T,
typename CR,
typename Ext>
1054 fixed_width_binary_array_impl<T, CR, Ext>::erase_values(const_value_iterator pos, size_type count)
1059 const size_t index =
static_cast<size_t>(std::distance(value_cbegin(), pos));
1064 auto& data_buffer = get_data_buffer();
1065 const size_type byte_count = m_element_size * count;
1066 const auto offset_begin = byte_offset(index);
1067 const auto offset_end = offset_begin + byte_count;
1070 data_buffer.begin() +
static_cast<difference_type
>(offset_end),
1072 data_buffer.begin() +
static_cast<difference_type
>(offset_begin)
1074 data_buffer.resize(data_buffer.size() - byte_count);
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 &)
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
bitset_iterator< self_type, true > const_iterator
typename storage_type::default_allocator default_allocator
typename base_type::size_type size_type
self_type & operator=(const self_type &)
typename base_type::iterator_tag iterator_tag
typename base_type::const_bitmap_range const_bitmap_range
typename inner_types::data_value_type data_value_type
fixed_width_binary_array_impl(arrow_proxy)
Constructs fixed-width binary array from Arrow proxy.
constexpr inner_reference value(size_type i)
Gets mutable reference to element at specified index.
nullable< inner_reference, bitmap_reference > reference
typename inner_types::inner_const_reference inner_const_reference
nullable< inner_value_type > value_type
typename inner_types::functor_type functor_type
fixed_width_binary_array_impl(const self_type &)
mutable_array_bitmap_base< self_type > base_type
typename inner_types::const_value_iterator const_value_iterator
typename base_type::bitmap_const_reference bitmap_const_reference
fixed_width_binary_array_impl(self_type &&) noexcept=default
Move constructor.
typename base_type::bitmap_reference bitmap_reference
typename inner_types::inner_value_type inner_value_type
nullable< inner_const_reference, bitmap_const_reference > const_reference
typename inner_types::const_functor_type const_functor_type
array_inner_types< self_type > inner_types
typename inner_types::const_data_iterator const_data_iterator
typename inner_types::data_iterator data_iterator
typename inner_types::inner_reference inner_reference
typename inner_types::value_iterator value_iterator
typename base_type::bitmap_type bitmap_type
typename base_type::difference_type difference_type
fixed_width_binary_array_impl< T, fixed_width_binary_traits::const_reference, Ext > self_type
constexpr inner_const_reference value(size_type i) const
Gets const reference to element at specified index.
A view that repeats a value a given number of times.
The class sequence_view describes an object that can refer to a constant contiguous sequence of T wit...
This buffer class is used as storage buffer for all sparrow arrays.
Concept for character-like types.
Concept for convertible range types.
#define SPARROW_ASSERT_TRUE(expr__)
std::string key< fixed_width_binary_array >()
SPARROW_API void increase(const std::string &key)
constexpr std::size_t size(typelist< T... >={})
Gets the count of types contained in a typelist.
constexpr bool is_type_instance_of_v
Variable template for convenient access to is_type_instance_of.
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.
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
Type alias for a validity bitmap using 8-bit storage blocks.
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)
Ensures a validity bitmap of the specified size from various input types.
data_type
Runtime identifier of arrow data types, usually associated with raw bytes with the associated value.
Extensions to the C++ standard library.
const_iterator const_value_iterator
detail::layout_value_functor< array_type, inner_reference > functor_type
functor_index_iterator< functor_type > iterator
fixed_width_binary_reference< array_type > inner_reference
std::reverse_iterator< const_iterator > const_reverse_iterator
bitmap_type::const_iterator const_bitmap_iterator
fixed_width_binary_array_impl< T, CR, Ext > array_type
std::random_access_iterator_tag iterator_tag
data_value_type * data_iterator
functor_index_iterator< const_functor_type > const_iterator
detail::layout_value_functor< const array_type, inner_const_reference > const_functor_type
const data_value_type * const_data_iterator
typename T::value_type data_value_type
Base class for array_inner_types specializations.
Traits class that must be specialized by array implementations.
Provides compile-time information about Arrow data types.
static constexpr sparrow::data_type get()
Metafunction for retrieving the data_type of a typed array.