diff --git a/include/sparrow/builder/builder.hpp b/include/sparrow/builder/builder.hpp index 7a881a11..442b600e 100644 --- a/include/sparrow/builder/builder.hpp +++ b/include/sparrow/builder/builder.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -132,20 +133,32 @@ namespace sparrow concept translate_to_struct_layout = std::ranges::input_range && tuple_like> && !all_elements_same>; + template + concept fixed_width_binary_types = (mpl::fixed_size_span || mpl::std_array) + && std::is_same_v, byte_t>; + template concept translate_to_fixed_sized_list_layout = std::ranges::input_range && tuple_like> + && !((mpl::fixed_size_span> || mpl::std_array>) && fixed_width_binary_types>) && all_elements_same>; template concept translate_to_variable_sized_binary_layout = std::ranges::input_range && std::ranges::input_range> + && !((mpl::fixed_size_span> || mpl::std_array>) && fixed_width_binary_types>) && !tuple_like> && // tuples go to struct layout // value type of inner must be char like ( char, // byte, uint8) mpl::char_like>; + template + concept translate_to_fixed_width_binary_layout = std::ranges::input_range + && ((mpl::fixed_size_span> + || mpl::std_array>) + && fixed_width_binary_types>); + template concept translate_to_union_layout = std::ranges::input_range && // value type must be a variant-like type @@ -282,6 +295,18 @@ namespace sparrow } }; + template + struct builder + { + using type = sparrow::fixed_width_binary_array; + + template + static type create(U&& t) + { + return type(std::move(t)); + } + }; + template struct builder { diff --git a/include/sparrow/layout/array_wrapper.hpp b/include/sparrow/layout/array_wrapper.hpp index d3f8e377..52bb9d7e 100644 --- a/include/sparrow/layout/array_wrapper.hpp +++ b/include/sparrow/layout/array_wrapper.hpp @@ -178,7 +178,7 @@ namespace sparrow template array_wrapper_impl::array_wrapper_impl(T&& ar) - : array_wrapper(this->get_data_type()) + : array_wrapper(detail::array_access::get_arrow_proxy(ar).data_type()) , m_storage(value_ptr(std::move(ar))) , p_array(std::get>(m_storage).get()) { @@ -186,7 +186,7 @@ namespace sparrow template array_wrapper_impl::array_wrapper_impl(T* ar) - : array_wrapper(this->get_data_type()) + : array_wrapper(detail::array_access::get_arrow_proxy(*ar).data_type()) , m_storage(ar) , p_array(ar) { @@ -194,7 +194,7 @@ namespace sparrow template array_wrapper_impl::array_wrapper_impl(std::shared_ptr ar) - : array_wrapper(this->get_data_type()) + : array_wrapper(detail::array_access::get_arrow_proxy(*ar).data_type()) , m_storage(std::move(ar)) , p_array(std::get>(m_storage).get()) { diff --git a/include/sparrow/layout/dispatch.hpp b/include/sparrow/layout/dispatch.hpp index 55f79f38..1b3f9b95 100644 --- a/include/sparrow/layout/dispatch.hpp +++ b/include/sparrow/layout/dispatch.hpp @@ -19,6 +19,7 @@ #include "sparrow/layout/array_wrapper.hpp" #include "sparrow/layout/decimal_array.hpp" #include "sparrow/layout/dictionary_encoded_array.hpp" +#include "sparrow/layout/fixed_width_binary_array.hpp" #include "sparrow/layout/list_layout/list_array.hpp" #include "sparrow/layout/nested_value_types.hpp" #include "sparrow/layout/null_array.hpp" @@ -125,6 +126,8 @@ namespace sparrow return func(unwrap_array(ar)); case data_type::DECIMAL256: return func(unwrap_array(ar)); + case data_type::FIXED_WIDTH_BINARY: + return func(unwrap_array(ar)); default: throw std::invalid_argument("array type not supported"); } diff --git a/include/sparrow/layout/fixed_width_binary_layout/fixed_width_binary_array.hpp b/include/sparrow/layout/fixed_width_binary_layout/fixed_width_binary_array.hpp index f6bf490c..de4d6059 100644 --- a/include/sparrow/layout/fixed_width_binary_layout/fixed_width_binary_array.hpp +++ b/include/sparrow/layout/fixed_width_binary_layout/fixed_width_binary_array.hpp @@ -36,20 +36,14 @@ namespace sparrow { - namespace detail - { - template - struct variable_size_binary_format; - } - template class fixed_width_binary_array_impl; - using fixed_binary_traits = arrow_traits>; + using fixed_width_binary_traits = arrow_traits>; using fixed_width_binary_array = fixed_width_binary_array_impl< - fixed_binary_traits::value_type, - fixed_binary_traits::const_reference>; + fixed_width_binary_traits::value_type, + fixed_width_binary_traits::const_reference>; template struct array_inner_types> : array_inner_types_base diff --git a/test/test_builder.cpp b/test/test_builder.cpp index fc7f5aab..9a9c8a4a 100644 --- a/test/test_builder.cpp +++ b/test/test_builder.cpp @@ -199,6 +199,40 @@ namespace sparrow } } + TEST_CASE("fixed-width-binary") + { + // fixed_width_binary + { + std::vector> v{ + {byte_t(1), byte_t(2), byte_t(3)}, + {byte_t(4), byte_t(5), byte_t(6)}, + {byte_t(7), byte_t(8), byte_t(9)} + }; + auto arr = sparrow::build(v); + [[maybe_unused]] const auto lol = arr.get_arrow_proxy().format(); + [[maybe_unused]] const auto lol2 = arr.get_arrow_proxy().data_type(); + test::generic_consistency_test(arr); + REQUIRE_EQ(arr.size(), 3); + using arr_type = std::decay_t; + static_assert(std::is_same_v); + } + // fixed_width_binary with nulls + { + std::vector>> v{ + std::array{byte_t(1), byte_t(2), byte_t(3)}, + sparrow::nullval, + std::array{byte_t(7), byte_t(8), byte_t(9)} + }; + auto arr = sparrow::build(v); + [[maybe_unused]] const auto lol = arr.get_arrow_proxy().format(); + [[maybe_unused]] const auto lol2 = arr.get_arrow_proxy().data_type(); + test::generic_consistency_test(arr); + REQUIRE_EQ(arr.size(), 3); + using arr_type = std::decay_t; + static_assert(std::is_same_v); + } + } + TEST_CASE("sparse-union") { SUBCASE("simple")