Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-PLACET committed Jan 10, 2025
1 parent 06b86c7 commit 609a659
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
25 changes: 25 additions & 0 deletions include/sparrow/builder/builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <sparrow/builder/nested_eq.hpp>
#include <sparrow/builder/nested_less.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/primitive_array.hpp>
#include <sparrow/layout/struct_layout/struct_array.hpp>
Expand Down Expand Up @@ -132,20 +133,32 @@ namespace sparrow
concept translate_to_struct_layout = std::ranges::input_range<T> && tuple_like<ensured_range_value_t<T>>
&& !all_elements_same<ensured_range_value_t<T>>;

template <class T>
concept fixed_width_binary_types = (mpl::fixed_size_span<T> || mpl::std_array<T>)
&& std::is_same_v<std::ranges::range_value_t<T>, byte_t>;

template <class T>
concept translate_to_fixed_sized_list_layout = std::ranges::input_range<T>
&& tuple_like<ensured_range_value_t<T>>
&& !((mpl::fixed_size_span<ensured_range_value_t<T>> || mpl::std_array<ensured_range_value_t<T>>) && fixed_width_binary_types<ensured_range_value_t<T>>)
&& all_elements_same<ensured_range_value_t<T>>;

template <class T>
concept translate_to_variable_sized_binary_layout = std::ranges::input_range<T>
&& std::ranges::input_range<ensured_range_value_t<T>>
&& !((mpl::fixed_size_span<ensured_range_value_t<T>> || mpl::std_array<ensured_range_value_t<T>>) && fixed_width_binary_types<ensured_range_value_t<T>>)
&& !tuple_like<ensured_range_value_t<T>>
&& // tuples go to struct layout
// value type of inner must be char like ( char,
// byte, uint8)
mpl::char_like<nested_ensured_range_inner_value_t<T>>;

template <class T>
concept translate_to_fixed_width_binary_layout = std::ranges::input_range<T>
&& ((mpl::fixed_size_span<ensured_range_value_t<T>>
|| mpl::std_array<ensured_range_value_t<T>>)
&& fixed_width_binary_types<ensured_range_value_t<T>>);

template <class T>
concept translate_to_union_layout = std::ranges::input_range<T> &&
// value type must be a variant-like type
Expand Down Expand Up @@ -282,6 +295,18 @@ namespace sparrow
}
};

template <translate_to_fixed_width_binary_layout T, class OPTION_FLAGS>
struct builder<T, dont_enforce_layout, OPTION_FLAGS>
{
using type = sparrow::fixed_width_binary_array;

template <class U>
static type create(U&& t)
{
return type(std::move(t));
}
};

template <translate_to_union_layout T, class OPTION_FLAGS>
struct builder<T, dont_enforce_layout, OPTION_FLAGS>
{
Expand Down
6 changes: 3 additions & 3 deletions include/sparrow/layout/array_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,23 @@ namespace sparrow

template <class T>
array_wrapper_impl<T>::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<T>(std::move(ar)))
, p_array(std::get<value_ptr<T>>(m_storage).get())
{
}

template <class T>
array_wrapper_impl<T>::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)
{
}

template <class T>
array_wrapper_impl<T>::array_wrapper_impl(std::shared_ptr<T> 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<std::shared_ptr<T>>(m_storage).get())
{
Expand Down
3 changes: 3 additions & 0 deletions include/sparrow/layout/dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -125,6 +126,8 @@ namespace sparrow
return func(unwrap_array<decimal_128_array>(ar));
case data_type::DECIMAL256:
return func(unwrap_array<decimal_256_array>(ar));
case data_type::FIXED_WIDTH_BINARY:
return func(unwrap_array<fixed_width_binary_array>(ar));
default:
throw std::invalid_argument("array type not supported");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,14 @@

namespace sparrow
{
namespace detail
{
template <class T, class OT>
struct variable_size_binary_format;
}

template <std::ranges::sized_range T, class CR>
class fixed_width_binary_array_impl;

using fixed_binary_traits = arrow_traits<std::vector<byte_t>>;
using fixed_width_binary_traits = arrow_traits<std::vector<byte_t>>;

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 <std::ranges::sized_range T, class CR>
struct array_inner_types<fixed_width_binary_array_impl<T, CR>> : array_inner_types_base
Expand Down
34 changes: 34 additions & 0 deletions test/test_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,40 @@ namespace sparrow
}
}

TEST_CASE("fixed-width-binary")
{
// fixed_width_binary
{
std::vector<std::array<byte_t, 3>> 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<decltype(arr)>;
static_assert(std::is_same_v<arr_type, sparrow::fixed_width_binary_array>);
}
// fixed_width_binary with nulls
{
std::vector<nt<std::array<byte_t, 3>>> v{
std::array<byte_t, 3>{byte_t(1), byte_t(2), byte_t(3)},
sparrow::nullval,
std::array<byte_t, 3>{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<decltype(arr)>;
static_assert(std::is_same_v<arr_type, sparrow::fixed_width_binary_array>);
}
}

TEST_CASE("sparse-union")
{
SUBCASE("simple")
Expand Down

0 comments on commit 609a659

Please sign in to comment.