22#include <unordered_map>
51 template <
class T,
class LAYOUT_POLICY,
class OPTIONS_TYPE>
79 template <
class T,
class... OPTION_FLAGS>
80 [[nodiscard]]
constexpr auto build(T&& t, OPTION_FLAGS&&...)
83 using decayed_t = std::decay_t<T>;
90 using value_type =
typename decayed_t::value_type;
92 std::forward<T>(t).get()
105 template <
class T,
class... OPTION_FLAGS>
106 [[nodiscard]]
constexpr auto build(std::initializer_list<T> t, OPTION_FLAGS&&... flags)
108 auto subranges = std::views::all(t);
109 return build(std::forward<
decltype(subranges)>(subranges), std::forward<OPTION_FLAGS>(flags)...);
115 template <
class LAYOUT_POLICY,
class T,
class... OPTION_FLAGS>
116 [[nodiscard]]
constexpr auto
125 && std::is_scalar_v<ensured_range_value_t<T>>;
127 template <
typename T>
133 template <
typename T>
139 template <
typename T>
143 template <
typename T>
152 template <
typename T>
159 template <
typename T>
168 && std::ranges::input_range<ensured_range_value_t<T>>
176 template <
typename T>
187 && std::is_same_v<std::ranges::range_value_t<T>,
byte_t>;
201 && std::ranges::input_range<ensured_range_value_t<T>>
227 template <translates_to_primitive_layout T,
class OPTION_FLAGS>
235 return type(std::forward<U>(t));
239 template <translates_to_date_layout T,
class OPTION_FLAGS>
240 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
247 return type(std::forward<U>(t));
251 template <translates_to_duration_layout T,
class OPTION_FLAGS>
252 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
259 return type(std::forward<U>(t));
263 template <translates_to_timestamp_layout T,
class OPTION_FLAGS>
264 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
267 using timezone_ptr = std::decay_t<
decltype(std::declval<ensured_range_value_t<T>>().get_time_zone())>;
280 return t.begin()->get_time_zone();
283 return type(tz, std::forward<U>(t));
287 template <translates_to_timestamp_without_timezone_layout T,
class OPTION_FLAGS>
288 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
295 return type(std::forward<U>(t));
299 template <translates_to_
interval_layout T,
class OPTION_FLAGS>
300 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
307 return type(std::forward<U>(t));
311 template <translates_to_time_layout T,
class OPTION_FLAGS>
312 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
319 return type(std::forward<U>(t));
323 template <translate_to_variable_sized_list_layout T,
class OPTION_FLAGS>
324 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
328 using type = std::conditional_t<
339 | std::views::transform(
350 auto detyped_array =
array(std::move(typed_array));
352 return type(std::move(detyped_array), type::offset_from_sizes(sizes),
where_null(t));
356 template <translate_to_fixed_sized_list_layout T,
class OPTION_FLAGS>
357 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
360 static constexpr std::size_t
361 list_size = std::tuple_size_v<look_trough_t<std::ranges::range_value_t<T>>>;
381 template <translate_to_map_layout T,
class OPTION_FLAGS>
382 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
386 using key_type =
typename raw_value_type::first_type;
393 | std::views::transform(
400 | std::views::transform(
423 template <translate_to_struct_layout T,
class OPTION_FLAGS>
424 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
427 static constexpr std::size_t
n_children = std::tuple_size_v<mnv_t<std::ranges::range_value_t<T>>>;
433 std::vector<array> detyped_children(
n_children);
438 | std::views::transform(
439 [](
const auto& maybe_nullable_tuple)
441 const auto& tuple_val =
ensure_value(maybe_nullable_tuple);
442 return std::get<decltype(i)::value>(tuple_val);
446 using tuple_element_type = std::tuple_element_t<
decltype(i)::value,
tuple_type>;
448 detyped_children[
decltype(i)::value] =
array(
458 template <translate_to_variable_sized_binary_layout T,
class OPTION_FLAGS>
459 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
470 | std::views::transform(
477 return type(std::move(data_buffer), type::offset_from_sizes(sizes),
where_null(t));
481 template <translate_to_fixed_w
idth_binary_layout T,
class OPTION_FLAGS>
482 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
489 return type(std::forward<U>(t));
493 template <translate_to_union_layout T,
class OPTION_FLAGS>
494 struct builder<T, dont_enforce_layout, OPTION_FLAGS>
498 static constexpr std::size_t
variant_size = std::variant_size_v<variant_type>;
502 requires(std::is_same_v<type, sparrow::sparse_union_array>)
508 using type_at_index = std::variant_alternative_t<
decltype(i)::value,
variant_type>;
510 | std::views::transform(
511 [](
const auto& variant)
513 return variant.index() ==
decltype(i)::value
514 ? std::get<type_at_index>(variant)
520 detyped_children[
decltype(i)::value] =
array(
527 auto type_id_range = t
528 | std::views::transform(
531 return static_cast<std::uint8_t
>(v.index());
536 return type(std::move(detyped_children), std::move(type_id_buffer));
540 template <
class T,
class OPTION_FLAGS>
553 std::map<raw_range_value_type, key_type, nested_less<raw_range_value_type>> value_map;
554 std::vector<raw_range_value_type> values;
555 std::vector<key_type> keys;
557 values.reserve(input_size);
558 keys.reserve(input_size);
560 for (
const auto& v : t)
562 auto find_res = value_map.find(v);
563 if (find_res == value_map.end())
565 value_map.insert({v, key});
572 keys.push_back(find_res->second);
583 return type(std::move(keys_buffer),
array(std::move(values_array)));
587 template <
class T,
class OPTION_FLAGS>
596 using value_type = std::decay_t<raw_range_value_type>;
600 std::vector<value_type> values{};
601 std::vector<int64_t> acc_run_lengths{};
603 values.reserve(input_size);
604 acc_run_lengths.reserve(input_size);
610 for (
const auto& v : t)
620 if (!eq(values.back(), v))
622 acc_run_lengths.push_back(i);
628 acc_run_lengths.push_back(i);
637 return type(
array(std::move(run_length_typed_array)),
array(std::move(values_array)));
Dynamically typed array encapsulating an Arrow layout.
Forward declaration of dictionary_encoded_array.
static auto offset_from_sizes(SIZES_RANGE &&sizes) -> offset_buffer_type
Creates offset buffer from map sizes.
A view that repeats a value a given number of times.
Sparse union array implementation without offset buffer.
Array implementation for storing timestamp values with timezone information.
This buffer class is used as storage buffer for all sparrow arrays.
Concept for character-like types.
Concept for std::array types.
std::conditional_t< is_dict_encode< mnv_t< T > >, enforce_dict_encoded_layout, std::conditional_t< is_run_end_encode< mnv_t< T > >, enforce_run_end_encoded_layout, dont_enforce_layout > > layout_flag_t
constexpr decltype(auto) ensure_value_range(T &&t) noexcept
look_trough_t< std::ranges::range_value_t< T > > ensured_range_value_t
ensured_range_value_t< ensured_range_value_t< T > > nested_ensured_range_inner_value_t
constexpr std::size_t get_size_save(T &&t)
constexpr auto build_impl(T &&t, sparrow::mpl::typelist< OPTION_FLAGS... > typelist)
constexpr std::vector< std::size_t > where_null(T &&t)
constexpr decltype(auto) ensure_value(T &&t)
void for_each_index(F &&f)
consteval bool any_of(L< T... >, Predicate predicate={})
Checks if at least one type in the typelist satisfies the predicate.
constexpr bool is_type_instance_of_v
Variable template for convenient access to is_type_instance_of.
consteval bool contains()
Checks if a typelist contains a specific type.
primitive_array_impl< T > time_array
Array of time values.
mpl:: typelist< chrono::time_seconds, chrono::time_milliseconds, chrono::time_microseconds, chrono::time_nanoseconds > time_types_t
list_array_impl< false > list_array
A list array implementation.
constexpr auto build(T &&t, OPTION_FLAGS &&...)
function to create a sparrow array from arbitrary nested combinations of ranges, tuples,...
primitive_array_impl< T > interval_array
Array of interval values.
mpl::typelist< zoned_time_without_timezone_seconds, zoned_time_without_timezone_milliseconds, zoned_time_without_timezone_microseconds, zoned_time_without_timezone_nanoseconds > zoned_time_without_timezone_types_t
mpl::typelist< date_days, date_milliseconds > date_types_t
constexpr std::size_t range_size(R &&r)
constexpr large_list_flag_t large_list_flag
primitive_array_impl< T > date_array
Array of std::chrono::duration values.
string_array_impl< std::int32_t > string_array
Type alias for variable-size string arrays with 32-bit offsets.
primitive_array_impl< T > primitive_array
Array of values of whose type has fixed binary size.
date::zoned_time< Duration, TimeZonePtr > timestamp
fixed_width_binary_array_impl< fixed_width_binary_traits::value_type, fixed_width_binary_traits::const_reference > fixed_width_binary_array
primitive_array_impl< T > timestamp_without_timezone_array
Array of timestamps without timezone.
list_array_impl< true > big_list_array
A big list array implementation.
primitive_array_impl< T > duration_array
Array of std::chrono::duration values.
mpl::typelist< chrono::months, days_time_interval, month_day_nanoseconds_interval > interval_types_t
mpl:: typelist< std::chrono::seconds, std::chrono::milliseconds, std::chrono::microseconds, std::chrono::nanoseconds > duration_types_t
static constexpr type create(U &&t)
sparrow::primitive_array< ensured_range_value_t< T > > type
static constexpr std::size_t n_children
std::ranges::range_value_t< T > raw_value_type
std::ranges::range_value_t< T > variant_type
static constexpr std::size_t list_size
static type create(U &&t)
static constexpr std::size_t variant_size
typename raw_value_type::second_type value_type
static type create(U &&t)
typename raw_value_type::first_type key_type
ensured_range_value_t< T > tuple_type
std::decay_t< decltype(std::declval< ensured_range_value_t< T > >().get_time_zone())> timezone_ptr
sparrow::dictionary_encoded_array< key_type > type
static type create(U &&t)
std::ranges::range_value_t< T > raw_range_value_type
std::ranges::range_value_t< T > raw_range_value_type
static type create(U &&t)
sparrow::run_end_encoded_array type
Workaround to replace static_assert(false) in template code.
Compile-time type predicate: true if the evaluated type is the same as T.
A sequence of types used for metaprogramming operations.