43 template <std::ranges::sized_range T,
class CR>
78 fixed_width_binary_traits::value_type,
79 fixed_width_binary_traits::const_reference>;
81 template <std::ranges::sized_range T,
class CR>
121 template <std::ranges::sized_range T,
class CR>
128 sizeof(std::ranges::range_value_t<T>) ==
sizeof(
byte_t),
129 "Only sequences of types with the same size as byte_t are supported"
195 template <
class... ARGS>
198 :
base_type(create_proxy(std::forward<ARGS>(args)...))
203 using base_type::get_arrow_proxy;
204 using base_type::size;
261 size_t element_count,
264 std::optional<std::string_view> name = std::nullopt,
265 std::optional<METADATA_RANGE> metadata = std::nullopt
283 template <input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
287 std::optional<std::string_view> name = std::nullopt,
288 std::optional<METADATA_RANGE> metadata = std::nullopt
312 std::ranges::input_range VALUES,
316 std::ranges::input_range<std::ranges::range_value_t<VALUES>>
322 std::optional<std::string_view> name = std::nullopt,
323 std::optional<METADATA_RANGE> metadata = std::nullopt
345 template <std::ranges::input_range VALUES, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
347 std::ranges::input_range<std::ranges::range_value_t<VALUES>>
353 std::optional<std::string_view> name = std::nullopt,
354 std::optional<METADATA_RANGE> metadata = std::nullopt
374 template <std::ranges::input_range NULLABLE_VALUES, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
376 && std::ranges::input_range<typename std::ranges::range_value_t<NULLABLE_VALUES>::value_type>
378 std::ranges::range_value_t<typename std::ranges::range_value_t<NULLABLE_VALUES>::value_type>,
382 std::optional<std::string_view> name = std::nullopt,
383 std::optional<METADATA_RANGE> metadata = std::nullopt
409 template <mpl::
char_like C, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>>
410 [[nodiscard]]
static arrow_proxy create_proxy_impl(
412 size_t element_count,
414 std::optional<validity_bitmap>&& validity_input,
415 std::optional<std::string_view> name = std::nullopt,
416 std::optional<METADATA_RANGE> metadata = std::nullopt
419 static constexpr size_t DATA_BUFFER_INDEX = 1;
441 [[nodiscard]]
constexpr value_iterator value_begin();
450 [[nodiscard]]
constexpr value_iterator value_end();
501 template <std::ranges::sized_range U>
503 constexpr void resize_values(size_type new_length, U
value);
524 template <std::ranges::sized_range U>
553 template <
typename InputIt>
554 requires std::input_iterator<InputIt>
594 template <std::ranges::sized_range U>
596 constexpr void assign(U&& rhs, size_type index);
598 size_t m_element_size = 0;
611 template <std::ranges::sized_range T,
class CR>
619 template <std::ranges::sized_range T,
class CR>
620 template <mpl::
char_like C, val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
621 arrow_proxy fixed_width_binary_array_impl<T, CR>::create_proxy(
623 size_t element_count,
626 std::optional<std::string_view> name,
627 std::optional<METADATA_RANGE> metadata
631 return create_proxy_impl(
632 std::move(data_buffer),
641 template <std::ranges::sized_range T,
class CR>
642 template <input_metadata_container METADATA_RANGE>
643 arrow_proxy fixed_width_binary_array_impl<T, CR>::create_proxy(
646 std::optional<std::string_view> name,
647 std::optional<METADATA_RANGE> metadata
650 u8_buffer<char> data_buffer{};
651 std::optional<validity_bitmap> bitmap =
nullable ? std::make_optional<validity_bitmap>(
nullptr, 0)
653 return create_proxy_impl(
654 std::move(data_buffer),
663 template <std::ranges::sized_range T,
class CR>
664 template <std::ranges::input_range R, val
idity_bitmap_input VB, input_metadata_container METADATA_RANGE>
666 std::ranges::input_range<std::ranges::range_value_t<R>> &&
673 std::optional<std::string_view> name,
674 std::optional<METADATA_RANGE> metadata
677 using values_type = std::ranges::range_value_t<R>;
678 using values_inner_value_type = std::ranges::range_value_t<values_type>;
681 const size_t element_size = std::ranges::empty(values) ? 0 : std::ranges::size(*values.begin());
685 std::move(data_buffer),
688 std::forward<VB>(validity_input),
689 std::forward<std::optional<std::string_view>>(name),
690 std::forward<std::optional<METADATA_RANGE>>(metadata)
694 template <std::ranges::sized_range T,
class CR>
695 template <std::ranges::input_range R, input_metadata_container METADATA_RANGE>
697 std::ranges::input_range<std::ranges::range_value_t<R>> &&
704 std::optional<std::string_view> name,
705 std::optional<METADATA_RANGE> metadata
710 return create_proxy(std::forward<R>(values),
validity_bitmap{}, std::move(name), std::move(metadata));
714 using values_type = std::ranges::range_value_t<R>;
715 using values_inner_value_type = std::ranges::range_value_t<values_type>;
718 const size_t element_size = std::ranges::empty(values) ? 0 : std::ranges::size(*values.begin());
720 return create_proxy_impl(
721 std::move(data_buffer),
731 template <std::ranges::sized_range T,
class CR>
732 template <std::ranges::input_range NULLABLE_RANGE, input_metadata_container METADATA_RANGE>
734 && std::ranges::input_range<typename std::ranges::range_value_t<NULLABLE_RANGE>::value_type>
736 std::ranges::range_value_t<typename std::ranges::range_value_t<NULLABLE_RANGE>::value_type>,
739 NULLABLE_RANGE&& range,
740 std::optional<std::string_view> name,
741 std::optional<METADATA_RANGE> metadata
745 const auto values = range
746 | std::views::transform(
752 const auto is_non_null = range
753 | std::views::transform(
756 return v.has_value();
759 return self_type::create_proxy(values, is_non_null, std::move(name), std::move(metadata));
762 template <std::ranges::sized_range T,
class CR>
763 template <mpl::
char_like C, input_metadata_container METADATA_RANGE>
764 arrow_proxy fixed_width_binary_array_impl<T, CR>::create_proxy_impl(
766 size_t element_count,
768 std::optional<validity_bitmap>&& bitmap,
769 std::optional<std::string_view> name,
770 std::optional<METADATA_RANGE> metadata
774 element_size == 0 ? (data_buffer.size() == 0) : (data_buffer.size() % element_size == 0)
777 const auto null_count = bitmap.has_value() ? bitmap->null_count() : 0;
778 std::string format_str =
"w:" + std::to_string(element_size);
779 const std::optional<std::unordered_set<ArrowFlag>>
780 flags = bitmap.has_value()
785 std::move(format_str),
790 repeat_view<bool>(
true, 0),
795 std::vector<buffer<std::uint8_t>> arr_buffs = {
796 bitmap.has_value() ? std::move(*bitmap).extract_storage() : buffer<std::uint8_t>{
nullptr, 0},
797 std::move(data_buffer).extract_storage()
801 static_cast<std::int64_t
>(element_count),
802 static_cast<int64_t
>(null_count),
804 std::move(arr_buffs),
810 return arrow_proxy{std::move(arr), std::move(schema)};
813 template <std::ranges::sized_range T,
class CR>
814 constexpr auto fixed_width_binary_array_impl<T, CR>::data(size_type i) -> data_iterator
816 const arrow_proxy& proxy = this->get_arrow_proxy();
817 auto data_buffer = proxy.buffers()[DATA_BUFFER_INDEX];
818 const size_t data_buffer_size = data_buffer.size();
819 const size_type index_offset = (
static_cast<size_type
>(proxy.offset()) * m_element_size) + i;
821 return data_buffer.template data<data_value_type>() + index_offset;
824 template <std::ranges::sized_range T,
class CR>
825 constexpr auto fixed_width_binary_array_impl<T, CR>::data(size_type i)
const -> const_data_iterator
827 const arrow_proxy& proxy = this->get_arrow_proxy();
828 const auto data_buffer = proxy.buffers()[DATA_BUFFER_INDEX];
829 const size_t data_buffer_size = data_buffer.size();
830 const size_type index_offset = (
static_cast<size_type
>(proxy.offset()) * m_element_size) + i;
832 return data_buffer.template data<const data_value_type>() + index_offset;
835 template <std::ranges::sized_range T,
class CR>
836 template <std::ranges::sized_range U>
838 constexpr void fixed_width_binary_array_impl<T, CR>::assign(U&& rhs, size_type index)
842 std::copy(std::ranges::begin(rhs), std::ranges::end(rhs), data(index * m_element_size));
845 template <std::ranges::sized_range T,
class CR>
852 template <std::ranges::sized_range T,
class CR>
856 const auto offset_begin = i * m_element_size;
857 const auto offset_end = offset_begin + m_element_size;
863 template <std::ranges::sized_range T,
class CR>
864 constexpr auto fixed_width_binary_array_impl<T, CR>::value_begin() -> value_iterator
866 return value_iterator{functor_type{&(this->derived_cast())}, 0};
869 template <std::ranges::sized_range T,
class CR>
870 constexpr auto fixed_width_binary_array_impl<T, CR>::value_end() -> value_iterator
875 template <std::ranges::sized_range T,
class CR>
876 constexpr auto fixed_width_binary_array_impl<T, CR>::value_cbegin() const -> const_value_iterator
878 return const_value_iterator{const_functor_type{&(this->derived_cast())}, 0};
881 template <std::ranges::sized_range T,
class CR>
882 constexpr auto fixed_width_binary_array_impl<T, CR>::value_cend() const -> const_value_iterator
887 template <std::ranges::sized_range T,
class CR>
888 template <std::ranges::sized_range U>
890 constexpr void fixed_width_binary_array_impl<T, CR>::resize_values(size_type new_length, U value)
893 if (new_length <
size())
896 const size_t new_size = new_length +
static_cast<size_t>(proxy.offset());
897 const auto offset = new_size * m_element_size;
898 auto& data_buffer = proxy.get_array_private_data()->buffers()[DATA_BUFFER_INDEX];
899 data_buffer.resize(offset);
901 else if (new_length >
size())
903 insert_value(value_cend(), value, new_length -
size());
907 template <std::ranges::sized_range T,
class CR>
908 template <std::ranges::sized_range U>
915 const auto idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
917 const uint8_t* uint8_ptr =
reinterpret_cast<const uint8_t*
>(
value.data());
918 const std::vector<uint8_t> casted_value(uint8_ptr, uint8_ptr +
value.size());
920 const auto joined_repeated_value_range = std::ranges::views::join(my_repeat_view);
923 const auto offset_begin = (idx + proxy.
offset()) * m_element_size;
924 const auto pos_to_insert =
sparrow::next(data_buffer.cbegin(), offset_begin);
925 data_buffer.insert(pos_to_insert, joined_repeated_value_range.begin(), joined_repeated_value_range.end());
929 template <std::ranges::sized_range T,
class CR>
930 template <
typename InputIt>
931 requires std::input_iterator<InputIt>
943 auto values = std::ranges::subrange(first, last);
944 const size_t cumulative_sizes = values.size() * m_element_size;
945 auto& data_buffer = get_arrow_proxy().get_array_private_data()->buffers()[DATA_BUFFER_INDEX];
946 data_buffer.resize(data_buffer.size() + cumulative_sizes);
947 const auto idx =
static_cast<size_t>(std::distance(value_cbegin(), pos));
949 const auto offset_begin = m_element_size * (idx + get_arrow_proxy().offset());
950 auto insert_pos =
sparrow::next(casted_values.begin(), offset_begin);
959 for (
const auto& val : values)
961 std::copy(val.begin(), val.end(), insert_pos);
962 std::advance(insert_pos, m_element_size);
967 template <std::ranges::sized_range T,
class CR>
968 constexpr auto fixed_width_binary_array_impl<T, CR>::erase_values(const_value_iterator pos, size_type count)
973 const size_t index =
static_cast<size_t>(std::distance(value_cbegin(), pos));
978 auto& data_buffer = get_arrow_proxy().get_array_private_data()->buffers()[DATA_BUFFER_INDEX];
979 const size_type byte_count = m_element_size * count;
980 const auto offset_begin = m_element_size * (index +
static_cast<size_type
>(get_arrow_proxy().offset()));
981 const auto offset_end = offset_begin + byte_count;
984 data_buffer.begin() +
static_cast<difference_type
>(offset_end),
986 data_buffer.begin() +
static_cast<difference_type
>(offset_begin)
988 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
SPARROW_API size_t offset() const
Gets the starting offset within the buffers.
SPARROW_API arrow_array_private_data * get_array_private_data()
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
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)
Constructs fixed-width binary array from Arrow proxy.
nullable< inner_value_type > value_type
fixed_width_binary_array_impl(ARGS &&... args)
Generic constructor for creating fixed-width binary array.
nullable< inner_const_reference, bitmap_const_reference > const_reference
typename inner_types::data_iterator data_iterator
constexpr inner_const_reference value(size_type i) const
Gets const reference to element at specified index.
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
constexpr inner_reference value(size_type i)
Gets mutable 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__)
constexpr std::size_t size(typelist< T... >={})
Gets the count of types contained in a typelist.
constexpr bool excludes_copy_and_move_ctor_v
Convenience variable template for excludes_copy_and_move_ctor.
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.
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 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.