From 029ab32e9fd2b99ff65605e5281af0586a9b42ff Mon Sep 17 00:00:00 2001 From: Alexis Placet Date: Mon, 23 Dec 2024 10:17:38 +0100 Subject: [PATCH] Activate clang format hook (#317) * Activate clang format hook * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 +- examples/builder_example.cpp | 120 ++- examples/typed_array_high_level.cpp | 17 +- examples/typed_array_low_level.cpp | 5 +- include/sparrow/array.hpp | 12 +- include/sparrow/array_factory.hpp | 2 +- .../arrow_array/private_data.hpp | 1 - .../arrow_array_schema_info_utils.hpp | 2 +- .../arrow_array_schema_utils.hpp | 8 +- .../sparrow/arrow_interface/arrow_schema.hpp | 3 +- include/sparrow/buffer/allocator.hpp | 1 - include/sparrow/buffer/buffer.hpp | 6 +- include/sparrow/buffer/buffer_adaptor.hpp | 8 +- include/sparrow/buffer/buffer_view.hpp | 8 +- include/sparrow/buffer/dynamic_bitset.hpp | 4 +- .../buffer/dynamic_bitset/bitset_iterator.hpp | 8 +- .../dynamic_bitset/bitset_reference.hpp | 2 +- .../dynamic_bitset/dynamic_bitset_view.hpp | 1 - include/sparrow/buffer/u8_buffer.hpp | 55 +- include/sparrow/builder/builder.hpp | 715 +++++++++--------- include/sparrow/builder/builder_utils.hpp | 549 +++++++------- include/sparrow/builder/nested_eq.hpp | 82 +- include/sparrow/builder/nested_less.hpp | 112 +-- include/sparrow/config/config.hpp | 16 +- include/sparrow/layout/array_access.hpp | 8 +- include/sparrow/layout/array_bitmap_base.hpp | 14 +- include/sparrow/layout/array_wrapper.hpp | 47 +- include/sparrow/layout/dispatch.hpp | 176 ++--- include/sparrow/layout/layout_utils.hpp | 22 +- .../sparrow/layout/list_layout/list_array.hpp | 4 +- .../sparrow/layout/list_layout/list_value.hpp | 3 +- include/sparrow/layout/nested_value_types.hpp | 2 +- include/sparrow/layout/primitive_array.hpp | 4 +- .../run_end_encoded_iterator.hpp | 61 +- .../layout/struct_layout/struct_value.hpp | 3 +- include/sparrow/layout/union_array.hpp | 4 +- .../variable_size_binary_array.hpp | 49 +- .../variable_size_binary_iterator.hpp | 4 +- .../variable_size_binary_reference.hpp | 1 - include/sparrow/record_batch.hpp | 24 +- include/sparrow/types/data_traits.hpp | 21 +- include/sparrow/utils/bit.hpp | 2 +- include/sparrow/utils/crtp_base.hpp | 6 +- .../sparrow/utils/functor_index_iterator.hpp | 21 +- include/sparrow/utils/iterator.hpp | 2 +- include/sparrow/utils/memory.hpp | 93 +-- include/sparrow/utils/mp_utils.hpp | 25 +- include/sparrow/utils/offsets.hpp | 18 +- include/sparrow/utils/ranges.hpp | 14 +- include/sparrow/utils/vector_view.hpp | 5 +- src/array_factory.cpp | 195 ++--- src/array_helper.cpp | 37 +- src/arrow_interface/arrow_array.cpp | 54 +- src/arrow_interface/arrow_schema.cpp | 1 - src/dummy32bit.cpp | 6 +- src/list_value.cpp | 4 +- src/struct_value.cpp | 5 +- test/better_junit_reporter.hpp | 4 +- test/external_array_data_creation.cpp | 154 ++-- test/external_array_data_creation.hpp | 14 +- test/junit_xml_writer.hpp | 4 +- test/test_array_wrapper.cpp | 10 +- test/test_binary_array.cpp | 59 +- test/test_buffer_adaptor.cpp | 3 +- test/test_builder.cpp | 92 +-- test/test_builder_dict_encoded.cpp | 145 ++-- test/test_builder_run_end_encoded.cpp | 133 ++-- test/test_builder_utils.cpp | 147 ++-- test/test_decimal_array.cpp | 1 - test/test_dispatch.cpp | 10 +- test/test_high_level_constructors.cpp | 57 +- test/test_list_array.cpp | 106 ++- test/test_list_value.cpp | 1 - test/test_memory.cpp | 9 +- test/test_nested_comperators.cpp | 38 +- test/test_null_array.cpp | 1 - test/test_record_batch.cpp | 1 - test/test_string_array.cpp | 4 +- test/test_struct_array.cpp | 2 +- test/test_traits.cpp | 31 +- test/test_utils.cpp | 2 +- test/test_utils.hpp | 101 +-- test/test_utils_buffers.cpp | 1 - test/test_utils_offsets.cpp | 3 +- test/test_variable_size_binary_view_array.cpp | 17 +- 85 files changed, 1929 insertions(+), 1897 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 891f1780c..fc2c93f95 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ repos: - repo: https://github.com/pre-commit/mirrors-clang-format rev: v19.1.5 - #hooks: - # - id: clang-format + hooks: + - id: clang-format diff --git a/examples/builder_example.cpp b/examples/builder_example.cpp index 36aebf2d1..6406c0169 100644 --- a/examples/builder_example.cpp +++ b/examples/builder_example.cpp @@ -3,17 +3,17 @@ */ -#include #include -#include +#include #include #include -#include +#include +#include #include void primitve_array() -{ +{ //! [builder_primitive_array] // using initializer_list auto arr = sparrow::build({1, 2, 3, 4, 5}); @@ -27,9 +27,13 @@ void primitve_array() auto arr3 = sparrow::build(l); ///////////////////// // using any range - auto iota = std::views::iota(1, 6) | std::views::transform([](int i){ - return static_cast(i); - }); + auto iota = std::views::iota(1, 6) + | std::views::transform( + [](int i) + { + return static_cast(i); + } + ); auto arr4 = sparrow::build(iota); ///////////////////// // all of the arrays above are equivalent to the manually built array @@ -42,8 +46,8 @@ void primitve_array() } void primitve_array_with_nulls() -{ -//! [builder_primitive_array_with_nulls] +{ + //! [builder_primitive_array_with_nulls] // using initializer_list (here we have to explicitly specify the type when using an // initializer list with nulls) auto arr = sparrow::build>({1, 2, sparrow::nullval, 4, 5}); @@ -57,9 +61,13 @@ void primitve_array_with_nulls() auto arr3 = sparrow::build(l); ///////////////////// // using any range - auto iota = std::views::iota(1, 6) | std::views::transform([](int i) -> sparrow::nullable { - return i == 3 ? sparrow::nullable{} : sparrow::nullable{i}; - }); + auto iota = std::views::iota(1, 6) + | std::views::transform( + [](int i) -> sparrow::nullable + { + return i == 3 ? sparrow::nullable{} : sparrow::nullable{i}; + } + ); auto arr4 = sparrow::build(iota); // all of the arrays above are equivalent to the manually built array std::vector where_nulls{2}; @@ -68,29 +76,26 @@ void primitve_array_with_nulls() assert(arr == arr2); assert(arr == arr3); assert(arr == arr4); -//! [builder_primitive_array_with_nulls] + //! [builder_primitive_array_with_nulls] } void list_of_strings() -{ +{ //! [builder_list_of_strings] // [["hello", "world","!"], ["Another", "sentence"]] - std::vector> v{ - {"hello", "world", "!"}, - {"Another", "sentence"} - }; + std::vector> v{{"hello", "world", "!"}, {"Another", "sentence"}}; auto arr = sparrow::build(v); //! [builder_list_of_strings] } -void list_of_strings_with_nulls() +void list_of_strings_with_nulls() { //! [builder_list_of_strings_with_nulls] // [["hello", "world","!"],NULL , ["Another", "sentence"]] using string_vector = std::vector; using nullable_string_vector = sparrow::nullable; std::vector v{ - nullable_string_vector{string_vector{"hello", "world", "!"}}, + nullable_string_vector{string_vector{"hello", "world", "!"}}, nullable_string_vector{}, nullable_string_vector{string_vector{"Another", "sentence"}} }; @@ -98,19 +103,18 @@ void list_of_strings_with_nulls() //! [builder_list_of_strings_with_nulls] } - void list_of_struct() { //! [builder_list_of_struct] /* [ [ - (1, 2.5), + (1, 2.5), (2, 3.5) ], [ - (3, 5.5), - (5, 6.5), + (3, 5.5), + (5, 6.5), (6, 7.5) ], [ @@ -119,45 +123,28 @@ void list_of_struct() ] */ std::vector>> v{ - { - std::tuple{1, 2.5}, - std::tuple{2, 3.5} - }, - { - std::tuple{3, 5.5}, - std::tuple{5, 6.5}, - std::tuple{6, 7.5} - }, - { - std::tuple{7, 8.5} - } + {std::tuple{1, 2.5}, std::tuple{2, 3.5}}, + {std::tuple{3, 5.5}, std::tuple{5, 6.5}, std::tuple{6, 7.5}}, + {std::tuple{7, 8.5}} }; auto arr = sparrow::build(v); //! [builder_list_of_struct] } void fixed_sized_list_strings() -{ +{ //! [builder_fixed_sized_list_strings] - std::vector> v{ - {"hello", "world"}, - {"Another", "sentence"}, - {"This", "is"} - }; + std::vector> v{{"hello", "world"}, {"Another", "sentence"}, {"This", "is"}}; auto arr = sparrow::build(v); //! [builder_fixed_sized_list_strings] } void fixed_sized_list_of_union() -{ +{ //! [builder_fixed_sized_list_of_union] using variant_type = std::variant; using array_type = std::array; - std::vector v{ - {1, 2.5f}, - {2, 3.5f}, - {3, 4.5f} - }; + std::vector v{{1, 2.5f}, {2, 3.5f}, {3, 4.5f}}; auto arr = sparrow::build(v); //! [builder_fixed_sized_list_of_union] } @@ -165,15 +152,13 @@ void fixed_sized_list_of_union() void dict_encoded_variable_sized_binary() { //! [builder_dict_encoded_variable_sized_binary] - sparrow::dict_encode> v{ - std::vector{ - "hello", - "world", - "hello", - "world", - "hello", - } - }; + sparrow::dict_encode> v{std::vector{ + "hello", + "world", + "hello", + "world", + "hello", + }}; auto arr = sparrow::build(v); //! [builder_dict_encoded_variable_sized_binary] } @@ -181,15 +166,13 @@ void dict_encoded_variable_sized_binary() void run_end_encoded_variable_sized_binary() { //! [builder_run_end_encoded_variable_sized_binary] - sparrow::run_end_encode> v{ - std::vector{ - "hello", - "hello", - "hello", - "world", - "world", - } - }; + sparrow::run_end_encode> v{std::vector{ + "hello", + "hello", + "hello", + "world", + "world", + }}; auto arr = sparrow::build(v); //! [builder_run_end_encoded_variable_sized_binary] } @@ -197,7 +180,7 @@ void run_end_encoded_variable_sized_binary() void struct_array() { //! [builder_struct_array] - using tuple_type = std::tuple, sparrow::nullable>; + using tuple_type = std::tuple, sparrow::nullable>; std::vector v{ {1, {"hello", "world"}, 2.5f}, {2, {"Another", "sentence"}, sparrow::nullval}, @@ -210,7 +193,7 @@ void struct_array() void sparse_union_array() { //! [builder_union_array] - using variant_type = std::variant, sparrow::nullable>; + using variant_type = std::variant, sparrow::nullable>; std::vector v{ int{1}, std::array{{"A", "sentence"}}, @@ -221,7 +204,6 @@ void sparse_union_array() //! [builder_union_array] } - int main() { primitve_array(); diff --git a/examples/typed_array_high_level.cpp b/examples/typed_array_high_level.cpp index 57bcf95ad..b1256fbd0 100644 --- a/examples/typed_array_high_level.cpp +++ b/examples/typed_array_high_level.cpp @@ -3,13 +3,13 @@ * The range can be a range of values or a range of nullable values. */ -//#include +// #include /*void example_typed_array_of_floats(){ using value_type = float; std::vector data = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f}; - + // construct the array auto array = sparrow::typed_array(data); @@ -34,7 +34,7 @@ void example_typed_array_of_strings(){ "four", "five" }; - + // construct the array auto array = sparrow::typed_array(data); @@ -61,7 +61,7 @@ void example_typed_array_of_strings_from_nullables(){ nullable_type("four"), nullable_type("five") }; - + // construct the array auto array = sparrow::typed_array(data); @@ -75,9 +75,10 @@ void example_typed_array_of_strings_from_nullables(){ } } }*/ -int main() { - //example_typed_array_of_floats(); - //example_typed_array_of_strings(); - //example_typed_array_of_strings_from_nullables(); +int main() +{ + // example_typed_array_of_floats(); + // example_typed_array_of_strings(); + // example_typed_array_of_strings_from_nullables(); return 0; } diff --git a/examples/typed_array_low_level.cpp b/examples/typed_array_low_level.cpp index c19e5bd29..2d84725e9 100644 --- a/examples/typed_array_low_level.cpp +++ b/examples/typed_array_low_level.cpp @@ -4,9 +4,10 @@ * The typed_array is created from the array_data and the data is accessed. */ -//#include +// #include -int main() { +int main() +{ ///////////////////////////////////////////////// // create array_data with 5 float32 elements // where the value at index 2 is missing diff --git a/include/sparrow/array.hpp b/include/sparrow/array.hpp index 0130d28f7..bd1367ee7 100644 --- a/include/sparrow/array.hpp +++ b/include/sparrow/array.hpp @@ -20,7 +20,7 @@ namespace sparrow { template - requires (not std::is_lvalue_reference_v) + requires(not std::is_lvalue_reference_v) array::array(A&& a) : p_array(new array_wrapper_impl(std::move(a))) { @@ -107,10 +107,12 @@ struct std::formatter auto format(const sparrow::array& ar, std::format_context& ctx) const { - return ar.visit([&ctx](const auto& layout) - { - return std::format_to(ctx.out(), "{}", layout); - }); + return ar.visit( + [&ctx](const auto& layout) + { + return std::format_to(ctx.out(), "{}", layout); + } + ); } }; diff --git a/include/sparrow/array_factory.hpp b/include/sparrow/array_factory.hpp index 4672d9dd7..ed4ba7004 100644 --- a/include/sparrow/array_factory.hpp +++ b/include/sparrow/array_factory.hpp @@ -24,5 +24,5 @@ namespace sparrow { SPARROW_API cloning_ptr array_factory(arrow_proxy proxy); - + } diff --git a/include/sparrow/arrow_interface/arrow_array/private_data.hpp b/include/sparrow/arrow_interface/arrow_array/private_data.hpp index 277dcf330..68c659199 100644 --- a/include/sparrow/arrow_interface/arrow_array/private_data.hpp +++ b/include/sparrow/arrow_interface/arrow_array/private_data.hpp @@ -55,7 +55,6 @@ namespace sparrow BufferType m_buffers; std::vector m_buffers_pointers; - }; constexpr arrow_array_private_data::arrow_array_private_data(BufferType buffers, std::size_t children_size) diff --git a/include/sparrow/arrow_interface/arrow_array_schema_info_utils.hpp b/include/sparrow/arrow_interface/arrow_array_schema_info_utils.hpp index ba69d80d4..39b18389a 100644 --- a/include/sparrow/arrow_interface/arrow_array_schema_info_utils.hpp +++ b/include/sparrow/arrow_interface/arrow_array_schema_info_utils.hpp @@ -26,7 +26,7 @@ namespace sparrow return true; /* THE CODE USED TO MAKES WRONG ASSUMPTIONS AND NEEDS TO BE REFACTORED IN A SEPERATE PR*/ } - + constexpr bool has_bitmap(data_type dt) { switch (dt) diff --git a/include/sparrow/arrow_interface/arrow_array_schema_utils.hpp b/include/sparrow/arrow_interface/arrow_array_schema_utils.hpp index dd095af14..2af6fa6a0 100644 --- a/include/sparrow/arrow_interface/arrow_array_schema_utils.hpp +++ b/include/sparrow/arrow_interface/arrow_array_schema_utils.hpp @@ -53,12 +53,12 @@ namespace sparrow /** * Release the children and dictionnary of an `ArrowArray` or `ArrowSchema`. - * + * * @tparam T `ArrowArray` or `ArrowSchema` * @param t The `ArrowArray` or `ArrowSchema` to release. */ template - requires std::same_as || std::same_as + requires std::same_as || std::same_as void release_common_arrow(T& t); /** @@ -174,14 +174,14 @@ namespace sparrow } template - requires std::same_as || std::same_as + requires std::same_as || std::same_as void release_common_arrow(T& t) { if (t.release == nullptr) { return; } - + if (t.dictionary) { if (t.dictionary->release) diff --git a/include/sparrow/arrow_interface/arrow_schema.hpp b/include/sparrow/arrow_interface/arrow_schema.hpp index 87c05d3a3..cbc246318 100644 --- a/include/sparrow/arrow_interface/arrow_schema.hpp +++ b/include/sparrow/arrow_interface/arrow_schema.hpp @@ -68,7 +68,8 @@ namespace sparrow SPARROW_API void release_arrow_schema(ArrowSchema* schema); /** - * Empty release function to use for the `ArrowSchema.release` member. Should be used for view of ArrowSchema. + * Empty release function to use for the `ArrowSchema.release` member. Should be used for view of + * ArrowSchema. */ SPARROW_API void empty_release_arrow_schema(ArrowSchema* schema); diff --git a/include/sparrow/buffer/allocator.hpp b/include/sparrow/buffer/allocator.hpp index a0dc13a47..a965e9371 100644 --- a/include/sparrow/buffer/allocator.hpp +++ b/include/sparrow/buffer/allocator.hpp @@ -22,7 +22,6 @@ #include "sparrow/utils/variant_visitor.hpp" - namespace sparrow { /* diff --git a/include/sparrow/buffer/buffer.hpp b/include/sparrow/buffer/buffer.hpp index a91b47bd6..ddcf5354d 100644 --- a/include/sparrow/buffer/buffer.hpp +++ b/include/sparrow/buffer/buffer.hpp @@ -736,10 +736,10 @@ namespace sparrow } } - template + template constexpr void buffer::reserve_with_growth_factor(size_type new_cap) { - if(new_cap > capacity()) + if (new_cap > capacity()) { reserve(new_cap * SPARROW_BUFFER_GROWTH_FACTOR); } @@ -785,7 +785,7 @@ namespace sparrow const difference_type offset = std::distance(cbegin(), pos); if (count != 0) { - reserve_with_growth_factor( size() + count); + reserve_with_growth_factor(size() + count); const iterator it = std::next(begin(), offset); std::move_backward(it, end(), std::next(end(), static_cast(count))); std::fill_n(it, count, value); diff --git a/include/sparrow/buffer/buffer_adaptor.hpp b/include/sparrow/buffer/buffer_adaptor.hpp index d4d46a84b..28ccdecd4 100644 --- a/include/sparrow/buffer/buffer_adaptor.hpp +++ b/include/sparrow/buffer/buffer_adaptor.hpp @@ -22,7 +22,6 @@ #include "sparrow/utils/iterator.hpp" #include "sparrow/utils/mp_utils.hpp" - namespace sparrow { template @@ -184,16 +183,17 @@ namespace sparrow size_type m_max_size; }; - - template + template class holder { public: - template + + template holder(Args&&... args) : value(std::forward(args)...) { } + T value; }; diff --git a/include/sparrow/buffer/buffer_view.hpp b/include/sparrow/buffer/buffer_view.hpp index 69535b5f6..c06b34931 100644 --- a/include/sparrow/buffer/buffer_view.hpp +++ b/include/sparrow/buffer/buffer_view.hpp @@ -46,7 +46,8 @@ namespace sparrow using const_reverse_iterator = std::reverse_iterator; buffer_view() = default; - explicit buffer_view(buffer& buffer) requires (!std::is_const_v); + explicit buffer_view(buffer& buffer) + requires(!std::is_const_v); template requires std::same_as, U> explicit buffer_view(const buffer& buffer); @@ -114,7 +115,8 @@ namespace sparrow ******************************/ template - buffer_view::buffer_view(buffer& buffer) requires (!std::is_const_v) + buffer_view::buffer_view(buffer& buffer) + requires(!std::is_const_v) : p_data(buffer.data()) , m_size(buffer.size()) { @@ -339,7 +341,7 @@ namespace sparrow template buffer_view::operator buffer>() const { - return { p_data, p_data + m_size }; + return {p_data, p_data + m_size}; } template diff --git a/include/sparrow/buffer/dynamic_bitset.hpp b/include/sparrow/buffer/dynamic_bitset.hpp index 78038abd1..70d8251f9 100644 --- a/include/sparrow/buffer/dynamic_bitset.hpp +++ b/include/sparrow/buffer/dynamic_bitset.hpp @@ -14,6 +14,6 @@ #pragma once +#include "sparrow/buffer/dynamic_bitset/dynamic_bitset.hpp" #include "sparrow/buffer/dynamic_bitset/dynamic_bitset_view.hpp" -#include "sparrow/buffer/dynamic_bitset/non_owning_dynamic_bitset.hpp" -#include "sparrow/buffer/dynamic_bitset/dynamic_bitset.hpp" \ No newline at end of file +#include "sparrow/buffer/dynamic_bitset/non_owning_dynamic_bitset.hpp" \ No newline at end of file diff --git a/include/sparrow/buffer/dynamic_bitset/bitset_iterator.hpp b/include/sparrow/buffer/dynamic_bitset/bitset_iterator.hpp index 054708329..aaf8cdbd4 100644 --- a/include/sparrow/buffer/dynamic_bitset/bitset_iterator.hpp +++ b/include/sparrow/buffer/dynamic_bitset/bitset_iterator.hpp @@ -14,9 +14,9 @@ #pragma once +#include "sparrow/utils/contracts.hpp" #include "sparrow/utils/iterator.hpp" #include "sparrow/utils/mp_utils.hpp" -#include "sparrow/utils/contracts.hpp" namespace sparrow { @@ -94,7 +94,7 @@ namespace sparrow { if constexpr (is_const) { - if(p_bitset->data() == nullptr) + if (p_bitset->data() == nullptr) { return true; } @@ -182,8 +182,8 @@ namespace sparrow } template - constexpr auto - bitset_iterator::distance_to(const self_type& rhs) const noexcept -> difference_type + constexpr auto bitset_iterator::distance_to(const self_type& rhs) const noexcept + -> difference_type { if (p_block == rhs.p_block) { diff --git a/include/sparrow/buffer/dynamic_bitset/bitset_reference.hpp b/include/sparrow/buffer/dynamic_bitset/bitset_reference.hpp index ef7585adc..98b8f893d 100644 --- a/include/sparrow/buffer/dynamic_bitset/bitset_reference.hpp +++ b/include/sparrow/buffer/dynamic_bitset/bitset_reference.hpp @@ -101,7 +101,7 @@ namespace sparrow template constexpr bitset_reference::operator bool() const noexcept { - if(m_bitset.data() == nullptr) + if (m_bitset.data() == nullptr) { return true; } diff --git a/include/sparrow/buffer/dynamic_bitset/dynamic_bitset_view.hpp b/include/sparrow/buffer/dynamic_bitset/dynamic_bitset_view.hpp index 56faff72d..037fa34b6 100644 --- a/include/sparrow/buffer/dynamic_bitset/dynamic_bitset_view.hpp +++ b/include/sparrow/buffer/dynamic_bitset/dynamic_bitset_view.hpp @@ -17,7 +17,6 @@ #include "sparrow/buffer/buffer_view.hpp" #include "sparrow/buffer/dynamic_bitset/dynamic_bitset_base.hpp" - namespace sparrow { /** diff --git a/include/sparrow/buffer/u8_buffer.hpp b/include/sparrow/buffer/u8_buffer.hpp index 4c3e2f37c..6d014b44e 100644 --- a/include/sparrow/buffer/u8_buffer.hpp +++ b/include/sparrow/buffer/u8_buffer.hpp @@ -18,7 +18,6 @@ #include #include -#include "sparrow/utils/ranges.hpp" #include "sparrow/buffer/buffer_adaptor.hpp" #include "sparrow/utils/ranges.hpp" @@ -27,30 +26,34 @@ namespace sparrow namespace detail { - template + template class holder { public: - template + + template holder(Args&&... args) : value(std::forward(args)...) { } + T value; - T extract_storage() && + T extract_storage() && { return std::move(value); } - const T & storage() const + const T& storage() const { return value; } - T & storage() + + T& storage() { return value; } + void assign(T&& other) { value = std::move(other); @@ -59,14 +62,15 @@ namespace sparrow } // like buffer but for any type T, nut always use buffer as storage - // This internal storage can be extracted - template + // This internal storage can be extracted + template class u8_buffer : private detail::holder>, - public buffer_adaptor&> + public buffer_adaptor&> { public: + using holder_type = detail::holder>; - using buffer_adaptor_type = buffer_adaptor&>; + using buffer_adaptor_type = buffer_adaptor&>; using holder_type::extract_storage; u8_buffer(u8_buffer&& other); @@ -74,50 +78,49 @@ namespace sparrow u8_buffer& operator=(u8_buffer&& other) = delete; u8_buffer& operator=(u8_buffer& other) = delete; - u8_buffer(std::size_t n, const T & val = T{}); - template - requires(!std::same_as, std::decay_t> && std::convertible_to, T>) + u8_buffer(std::size_t n, const T& val = T{}); + template + requires(!std::same_as, std::decay_t> && std::convertible_to, T>) u8_buffer(R&& range); u8_buffer(std::initializer_list ilist); }; - - template + template u8_buffer::u8_buffer(u8_buffer&& other) : holder_type(std::move(other).extract_storage()) , buffer_adaptor_type(holder_type::value) { } - template + template u8_buffer::u8_buffer(const u8_buffer& other) : holder_type(other.storage()) , buffer_adaptor_type(holder_type::value) { } - template - u8_buffer::u8_buffer(std::size_t n, const T & val) + template + u8_buffer::u8_buffer(std::size_t n, const T& val) : holder_type{n * sizeof(T)} , buffer_adaptor_type(holder_type::value) { std::fill(this->begin(), this->end(), val); } - - template - template - requires(!std::same_as, std::decay_t> && std::convertible_to, T>) + template + template + requires(!std::same_as, std::decay_t> + && std::convertible_to, T>) u8_buffer::u8_buffer(R&& range) - : holder_type{range_size(range)* sizeof(T)} - ,buffer_adaptor_type(holder_type::value) + : holder_type{range_size(range) * sizeof(T)} + , buffer_adaptor_type(holder_type::value) { std::ranges::copy(range, this->begin()); } - template + template u8_buffer::u8_buffer(std::initializer_list ilist) - : holder_type{ilist.size() * sizeof(T)} + : holder_type{ilist.size() * sizeof(T)} , buffer_adaptor_type(holder_type::value) { std::copy(ilist.begin(), ilist.end(), this->begin()); diff --git a/include/sparrow/builder/builder.hpp b/include/sparrow/builder/builder.hpp index ff306fa05..7a881a11b 100644 --- a/include/sparrow/builder/builder.hpp +++ b/include/sparrow/builder/builder.hpp @@ -15,414 +15,421 @@ #pragma once -#include -#include #include -#include #include -#include #include +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include -#include -#include #include #include -#include #include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include namespace sparrow { -// forward declaration -namespace detail -{ - template - struct builder; -} - -struct dense_union_flag_t{}; -struct sparse_union_flag_t{}; -struct large_list_flag_t{}; -struct large_binary_flag_t{}; - -// option flag to indicate the desire for large lists -inline constexpr large_list_flag_t large_list_flag; - -/** - * @brief function to create a sparrow array from arbitrary nested - * combinations of ranges, tuples, and nullable types, variants. - * Have a look at the \ref builder "buider documentation" for more information. - */ -template -auto build(T&& t, OPTION_FLAGS&& ... ) -{ - // for toplevel build calls, the layout policy is determined by the type itself - using decayed_t = std::decay_t; - using layout_policy = detail::layout_flag_t; - using option_flags_type = sparrow::mpl::typelist...>; - - if constexpr(detail::is_express_layout_desire) - { - // directely unpack - using value_type = typename decayed_t::value_type; - return detail::builder::create( - std::forward(t).get() - ); - } - else if constexpr(detail::is_nullable_like) - { - static_assert(mpl::dependent_false::value, "toplevel type must not be nullable"); - } - else + // forward declaration + namespace detail { - return detail::builder::create(std::forward(t)); + template + struct builder; } -} - -template -auto build(std::initializer_list t, OPTION_FLAGS&& ... flags) -{ - auto subranges = std::views::all(t); - return build(std::forward(subranges), std::forward(flags)...); -} + struct dense_union_flag_t + { + }; -namespace detail -{ + struct sparse_union_flag_t + { + }; -// this is called by the nested recursive calls -template -auto build_impl(T&& t, [[maybe_unused]] sparrow::mpl::typelist typelist) -{ - using option_flags_type = sparrow::mpl::typelist; - return builder::create(std::forward(t)); -} - -template -concept translates_to_primitive_layout = - std::ranges::input_range && - std::is_scalar_v> -; - -template -concept translate_to_variable_sized_list_layout = - std::ranges::input_range && - std::ranges::input_range> && - !tuple_like> && // tuples go to struct layout - // value type of inner should not be 'char-like'( char, byte, uint8), these are handled by variable_size_binary_array - !mpl::char_like> -; - -template -concept translate_to_struct_layout = - std::ranges::input_range && - tuple_like> && - !all_elements_same> -; - -template -concept translate_to_fixed_sized_list_layout = - std::ranges::input_range && - tuple_like> && - all_elements_same> -; - -template -concept translate_to_variable_sized_binary_layout = - std::ranges::input_range && - std::ranges::input_range> && - !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_union_layout = - std::ranges::input_range && - // value type must be a variant-like type - // *NOTE* we don't check for nullable here, as we want to handle nullable variants - // as in the arrow spec, the nulls are handled by the elements **in** the variant - variant_like< - std::ranges::range_value_t - > -; - -template< translates_to_primitive_layout T, class OPTION_FLAGS> -struct builder -{ - using type = sparrow::primitive_array>; - template - static type create(U&& t) + struct large_list_flag_t { - return type(std::forward(t)); - } -}; + }; -template< translate_to_variable_sized_list_layout T, class OPTION_FLAGS> -struct builder -{ - using raw_value_type = std::ranges::range_value_t; + struct large_binary_flag_t + { + }; + + // option flag to indicate the desire for large lists + inline constexpr large_list_flag_t large_list_flag; + + /** + * @brief function to create a sparrow array from arbitrary nested + * combinations of ranges, tuples, and nullable types, variants. + * Have a look at the \ref builder "buider documentation" for more information. + */ + template + auto build(T&& t, OPTION_FLAGS&&...) + { + // for toplevel build calls, the layout policy is determined by the type itself + using decayed_t = std::decay_t; + using layout_policy = detail::layout_flag_t; + using option_flags_type = sparrow::mpl::typelist...>; - using type = std::conditional_t< - mpl::contains(OPTION_FLAGS{}), - sparrow::big_list_array, - sparrow::list_array - >; + if constexpr (detail::is_express_layout_desire) + { + // directely unpack + using value_type = typename decayed_t::value_type; + return detail::builder::create( + std::forward(t).get() + ); + } + else if constexpr (detail::is_nullable_like) + { + static_assert(mpl::dependent_false::value, "toplevel type must not be nullable"); + } + else + { + return detail::builder::create(std::forward(t)); + } + } - template - static type create(U && t) + template + auto build(std::initializer_list t, OPTION_FLAGS&&... flags) { - auto flat_list_view = std::ranges::views::join(ensure_value_range(t)); - - auto sizes = t | std::views::transform([](const auto& l){ - return get_size_save(l); - }); - - // when the raw_value_type is a "express layout desire" we need to - // propagate this information to the builder, so it can handle the - using layout_policy_type = layout_flag_t; - auto typed_array = build_impl(flat_list_view, OPTION_FLAGS{}); - auto detyped_array = array(std::move(typed_array)); - - return type( - std::move(detyped_array), - type::offset_from_sizes(sizes), - where_null(t) - ); + auto subranges = std::views::all(t); + return build(std::forward(subranges), std::forward(flags)...); } -}; - -template< translate_to_fixed_sized_list_layout T, class OPTION_FLAGS> -struct builder -{ - using type = sparrow::fixed_sized_list_array; - constexpr static std::size_t list_size = std::tuple_size_v>>; - using raw_value_type = std::ranges::range_value_t; - template - static type create(U && t) + namespace detail { - auto flat_list_view = std::ranges::views::join(ensure_value_range(t)); - // when the raw_value_type is a "express layout desire" we need to - // propagate this information to the builder. - using layout_policy_type = layout_flag_t; + // this is called by the nested recursive calls + template + auto build_impl(T&& t, [[maybe_unused]] sparrow::mpl::typelist typelist) + { + using option_flags_type = sparrow::mpl::typelist; + return builder::create(std::forward(t)); + } + + template + concept translates_to_primitive_layout = std::ranges::input_range + && std::is_scalar_v>; + + template + concept translate_to_variable_sized_list_layout = std::ranges::input_range + && std::ranges::input_range> + && !tuple_like> + && // tuples go to struct layout + // value type of inner should not be 'char-like'( + // char, byte, uint8), these are handled by + // variable_size_binary_array + !mpl::char_like>; + + template + concept translate_to_struct_layout = std::ranges::input_range && tuple_like> + && !all_elements_same>; + + template + concept translate_to_fixed_sized_list_layout = std::ranges::input_range + && tuple_like> + && all_elements_same>; + + template + concept translate_to_variable_sized_binary_layout = std::ranges::input_range + && std::ranges::input_range> + && !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_union_layout = std::ranges::input_range && + // value type must be a variant-like type + // *NOTE* we don't check for nullable here, as we want to handle + // nullable variants as in the arrow spec, the nulls are handled + // by the elements **in** the variant + variant_like>; + + template + struct builder + { + using type = sparrow::primitive_array>; - return type( - static_cast(list_size), - array(build_impl(flat_list_view, OPTION_FLAGS{})), - where_null(t) - ); - } -}; + template + static type create(U&& t) + { + return type(std::forward(t)); + } + }; -template< translate_to_struct_layout T, class OPTION_FLAGS> -struct builder{ - using type = sparrow::struct_array; - static constexpr std::size_t n_children = std::tuple_size_v>>; - using tuple_type = ensured_range_value_t; + template + struct builder + { + using raw_value_type = std::ranges::range_value_t; - template - static type create(U&& t) - { - std::vector detyped_children(n_children); - for_each_index([&](auto i) - { - auto tuple_i_col = t | std::views::transform([](const auto& maybe_nullable_tuple) + using type = std::conditional_t< + mpl::contains(OPTION_FLAGS{}), + sparrow::big_list_array, + sparrow::list_array>; + + template + static type create(U&& t) { - const auto & tuple_val = ensure_value(maybe_nullable_tuple); - return std::get(tuple_val); - }); - - using tuple_element_type = std::tuple_element_t; - using layout_policy_type = layout_flag_t; - detyped_children[decltype(i)::value] = array(build_impl(tuple_i_col, OPTION_FLAGS{})); - }); - - return type( - std::move(detyped_children), - where_null(t) - ); - } -}; + auto flat_list_view = std::ranges::views::join(ensure_value_range(t)); + + auto sizes = t + | std::views::transform( + [](const auto& l) + { + return get_size_save(l); + } + ); + + // when the raw_value_type is a "express layout desire" we need to + // propagate this information to the builder, so it can handle the + using layout_policy_type = layout_flag_t; + auto typed_array = build_impl(flat_list_view, OPTION_FLAGS{}); + auto detyped_array = array(std::move(typed_array)); + + return type(std::move(detyped_array), type::offset_from_sizes(sizes), where_null(t)); + } + }; -template< translate_to_variable_sized_binary_layout T, class OPTION_FLAGS> -struct builder -{ - using type = sparrow::string_array; + template + struct builder + { + using type = sparrow::fixed_sized_list_array; + static constexpr std::size_t + list_size = std::tuple_size_v>>; + using raw_value_type = std::ranges::range_value_t; - template - static type create(U && t) - { - auto flat_list_view = std::ranges::views::join(ensure_value_range(t)); - u8_buffer data_buffer(flat_list_view); - - auto sizes = t | std::views::transform([](const auto& l){ - return get_size_save(l); - }); - - return type( - std::move(data_buffer), - type::offset_from_sizes(sizes), - where_null(t) - ); - } -}; + template + static type create(U&& t) + { + auto flat_list_view = std::ranges::views::join(ensure_value_range(t)); -template< translate_to_union_layout T, class OPTION_FLAGS> -struct builder -{ - using type = sparrow::sparse_union_array; // TODO use options to select between sparse and dense - using variant_type = std::ranges::range_value_t; - static constexpr std::size_t variant_size = std::variant_size_v; + // when the raw_value_type is a "express layout desire" we need to + // propagate this information to the builder. + using layout_policy_type = layout_flag_t; + return type( + static_cast(list_size), + array(build_impl(flat_list_view, OPTION_FLAGS{})), + where_null(t) + ); + } + }; - template - static type create(U && t) requires(std::is_same_v) - { - std::vector detyped_children(variant_size); - for_each_index([&](auto i) + template + struct builder { - using type_at_index = std::variant_alternative_t; - auto type_i_col = t | std::views::transform([](const auto& variant) - { - return variant.index() == decltype(i)::value ? - std::get(variant) : type_at_index{}; - }); - - using layout_policy_type = layout_flag_t; - detyped_children[decltype(i)::value] = array(build_impl(type_i_col, OPTION_FLAGS{})); - }); - - // type-ids - auto type_id_range = t | std::views::transform([](const auto& v){ - return static_cast(v.index()); - }); - sparrow::u8_buffer type_id_buffer(type_id_range); - - return type( - std::move(detyped_children), - std::move(type_id_buffer) - ); - } -}; + using type = sparrow::struct_array; + static constexpr std::size_t n_children = std::tuple_size_v>>; + using tuple_type = ensured_range_value_t; -template< class T, class OPTION_FLAGS> -struct builder -{ - using key_type = std::uint64_t; - using type = sparrow::dictionary_encoded_array; - // keep the nulls - using raw_range_value_type = std::ranges::range_value_t; - - template - static type create(U && t) - { - const auto input_size = range_size(t); - key_type key = 0; - std::map> value_map; - std::vector values; - std::vector keys; - - values.reserve(input_size); - keys.reserve(input_size); - - for(const auto& v : t) - { - auto find_res = value_map.find(v); - if(find_res == value_map.end()) + template + static type create(U&& t) { - value_map.insert({v, key}); - values.push_back(v); - keys.push_back(key); - ++key; + std::vector detyped_children(n_children); + for_each_index( + [&](auto i) + { + auto tuple_i_col = t + | std::views::transform( + [](const auto& maybe_nullable_tuple) + { + const auto& tuple_val = ensure_value(maybe_nullable_tuple); + return std::get(tuple_val); + } + ); + + using tuple_element_type = std::tuple_element_t; + using layout_policy_type = layout_flag_t; + detyped_children[decltype(i)::value] = array( + build_impl(tuple_i_col, OPTION_FLAGS{}) + ); + } + ); + + return type(std::move(detyped_children), where_null(t)); } - else + }; + + template + struct builder + { + using type = sparrow::string_array; + + template + static type create(U&& t) { - keys.push_back(find_res->second); + auto flat_list_view = std::ranges::views::join(ensure_value_range(t)); + u8_buffer data_buffer(flat_list_view); + + auto sizes = t + | std::views::transform( + [](const auto& l) + { + return get_size_save(l); + } + ); + + return type(std::move(data_buffer), type::offset_from_sizes(sizes), where_null(t)); } - - } - auto keys_buffer = sparrow::u8_buffer(keys); + }; - // since we do not support dict[dict or dict[run_end - // we can hard code the layout policy here - using layout_policy_type = dont_enforce_layout; - - auto values_array = build_impl(values, OPTION_FLAGS{}); + template + struct builder + { + using type = sparrow::sparse_union_array; // TODO use options to select between sparse and dense + using variant_type = std::ranges::range_value_t; + static constexpr std::size_t variant_size = std::variant_size_v; - return type( - std::move(keys_buffer), - array(std::move(values_array)) - ); - } -}; + template + static type create(U&& t) + requires(std::is_same_v) + { + std::vector detyped_children(variant_size); + for_each_index( + [&](auto i) + { + using type_at_index = std::variant_alternative_t; + auto type_i_col = t + | std::views::transform( + [](const auto& variant) + { + return variant.index() == decltype(i)::value + ? std::get(variant) + : type_at_index{}; + } + ); + + using layout_policy_type = layout_flag_t; + detyped_children[decltype(i)::value] = array( + build_impl(type_i_col, OPTION_FLAGS{}) + ); + } + ); + + // type-ids + auto type_id_range = t + | std::views::transform( + [](const auto& v) + { + return static_cast(v.index()); + } + ); + sparrow::u8_buffer type_id_buffer(type_id_range); + + return type(std::move(detyped_children), std::move(type_id_buffer)); + } + }; -template< class T, class OPTION_FLAGS> -struct builder -{ - using type = sparrow::run_end_encoded_array; - using raw_range_value_type = std::ranges::range_value_t; + template + struct builder + { + using key_type = std::uint64_t; + using type = sparrow::dictionary_encoded_array; + // keep the nulls + using raw_range_value_type = std::ranges::range_value_t; - template - static type create(U && t) - { - using value_type = std::decay_t; + template + static type create(U&& t) + { + const auto input_size = range_size(t); + key_type key = 0; + std::map> value_map; + std::vector values; + std::vector keys; - const auto input_size = range_size(t); + values.reserve(input_size); + keys.reserve(input_size); - std::vector values{}; - std::vector acc_run_lengths{}; + for (const auto& v : t) + { + auto find_res = value_map.find(v); + if (find_res == value_map.end()) + { + value_map.insert({v, key}); + values.push_back(v); + keys.push_back(key); + ++key; + } + else + { + keys.push_back(find_res->second); + } + } + auto keys_buffer = sparrow::u8_buffer(keys); - values.reserve(input_size); - acc_run_lengths.reserve(input_size); + // since we do not support dict[dict or dict[run_end + // we can hard code the layout policy here + using layout_policy_type = dont_enforce_layout; - const auto eq = nested_eq{}; + auto values_array = build_impl(values, OPTION_FLAGS{}); - // accumulate the run lengths - std::size_t i = 0; - for(const auto& v : t) - { - // first value - if(i == 0) - { - values.push_back(v); + return type(std::move(keys_buffer), array(std::move(values_array))); } - // rest - else + }; + + template + struct builder + { + using type = sparrow::run_end_encoded_array; + using raw_range_value_type = std::ranges::range_value_t; + + template + static type create(U&& t) { - if(!eq(values.back(), v)) + using value_type = std::decay_t; + + const auto input_size = range_size(t); + + std::vector values{}; + std::vector acc_run_lengths{}; + + values.reserve(input_size); + acc_run_lengths.reserve(input_size); + + const auto eq = nested_eq{}; + + // accumulate the run lengths + std::size_t i = 0; + for (const auto& v : t) { - acc_run_lengths.push_back(i); - values.push_back(v); + // first value + if (i == 0) + { + values.push_back(v); + } + // rest + else + { + if (!eq(values.back(), v)) + { + acc_run_lengths.push_back(i); + values.push_back(v); + } + } + ++i; } + acc_run_lengths.push_back(i); + + auto run_length_typed_array = primitive_array(acc_run_lengths); + + // since we do not support dict[dict or dict[run_end + // we can hard code the layout policy here + using layout_policy_type = dont_enforce_layout; + auto values_array = build_impl(values, OPTION_FLAGS{}); + + return type(array(std::move(run_length_typed_array)), array(std::move(values_array))); } - ++i; - } - acc_run_lengths.push_back(i); - - auto run_length_typed_array = primitive_array(acc_run_lengths); - - // since we do not support dict[dict or dict[run_end - // we can hard code the layout policy here - using layout_policy_type = dont_enforce_layout; - auto values_array = build_impl(values, OPTION_FLAGS{}); - - return type( - array(std::move(run_length_typed_array)), - array(std::move(values_array)) - ); - } -}; + }; -} // namespace detail -}// namespace sparrow + } // namespace detail +} // namespace sparrow diff --git a/include/sparrow/builder/builder_utils.hpp b/include/sparrow/builder/builder_utils.hpp index 0fd7c58bd..ee659710f 100644 --- a/include/sparrow/builder/builder_utils.hpp +++ b/include/sparrow/builder/builder_utils.hpp @@ -15,352 +15,355 @@ #pragma once -#include -#include #include +#include +#include #include #include -#include +#include +#include #include #include -#include -#include - + namespace sparrow { -namespace detail -{ - template - class express_layout_desire + namespace detail { - public: - using self_type = express_layout_desire; - using value_type = T; - - // default constructor - express_layout_desire() = default; - - // variadic perfect forwarding constructor - template - express_layout_desire(Args&& ... args) - : m_value(std::forward(args)...) + template + class express_layout_desire { - } + public: - const T& get() const - { - return m_value; - } - T& get() - { - return m_value; - } - private: - T m_value = T{}; - }; -} + using self_type = express_layout_desire; + using value_type = T; + // default constructor + express_layout_desire() = default; -// express the desire to use a dictionary encoding layout for -// whatever is inside. Note that what is inside **is not yet** -// encoded. This is done once the complete data which is to be -// dict encoded is known -template -class dict_encode : public detail::express_layout_desire -{ - using base_type = detail::express_layout_desire; -public: - using base_type::base_type; - using key_type = KEY_TYPE; -}; - -// express the desire to use a run-length encoding layout for -// whatever is inside. Note that what is inside **is not yet** -// encoded. This is done once the complete data which is to be -// dict encoded is known -template -class run_end_encode : public detail::express_layout_desire -{ - using base_type = detail::express_layout_desire; -public: - using base_type::base_type; - using length_type = LENGTH_TYPE; -}; + // variadic perfect forwarding constructor + template + express_layout_desire(Args&&... args) + : m_value(std::forward(args)...) + { + } -namespace detail -{ - // might be changed later to also allowm for std::optional - template - concept is_nullable_like = sparrow::is_nullable_v; + const T& get() const + { + return m_value; + } - struct dont_enforce_layout{}; - struct enforce_dict_encoded_layout{}; - struct enforce_run_end_encoded_layout{}; + T& get() + { + return m_value; + } - template - concept is_dict_encode = sparrow::mpl::is_type_instance_of_v; + private: - template - concept is_run_end_encode = sparrow::mpl::is_type_instance_of_v; + T m_value = T{}; + }; + } - template - concept is_express_layout_desire = is_dict_encode || is_run_end_encode; + // express the desire to use a dictionary encoding layout for + // whatever is inside. Note that what is inside **is not yet** + // encoded. This is done once the complete data which is to be + // dict encoded is known + template + class dict_encode : public detail::express_layout_desire + { + using base_type = detail::express_layout_desire; - - template - concept is_plain_value_type = !is_express_layout_desire && !is_nullable_like; + public: - template - using decayed_range_value_t = std::decay_t>; + using base_type::base_type; + using key_type = KEY_TYPE; + }; - template - void for_each_index_impl(F&& f, std::index_sequence) - { - // Apply f to each index individually - (f(std::integral_constant{}), ...); - } - template - void for_each_index(F&& f) + // express the desire to use a run-length encoding layout for + // whatever is inside. Note that what is inside **is not yet** + // encoded. This is done once the complete data which is to be + // dict encoded is known + template + class run_end_encode : public detail::express_layout_desire { - for_each_index_impl(std::forward(f), std::make_index_sequence()); - } + using base_type = detail::express_layout_desire; + + public: - template - bool exitable_for_each_index_impl(F&& f, std::index_sequence) + using base_type::base_type; + using length_type = LENGTH_TYPE; + }; + + namespace detail { - return (f(std::integral_constant{}) && ...); - } + // might be changed later to also allowm for std::optional + template + concept is_nullable_like = sparrow::is_nullable_v; - template - bool exitable_for_each_index(F&& f) - { - return exitable_for_each_index_impl(std::forward(f), std::make_index_sequence()); - } + struct dont_enforce_layout + { + }; + struct enforce_dict_encoded_layout + { + }; - template - concept has_tuple_element = - requires(T t) { - typename std::tuple_element_t>; - { get(t) } -> std::convertible_to&>; - }; + struct enforce_run_end_encoded_layout + { + }; + template + concept is_dict_encode = sparrow::mpl::is_type_instance_of_v; + template + concept is_run_end_encode = sparrow::mpl::is_type_instance_of_v; - template - constexpr bool check_tuple_elements(std::index_sequence) { - return (has_tuple_element && ...); - } + template + concept is_express_layout_desire = is_dict_encode || is_run_end_encode; - template - constexpr bool is_tuple_like() { - return check_tuple_elements(std::make_index_sequence>()); - } + template + concept is_plain_value_type = !is_express_layout_desire && !is_nullable_like; - template - concept variant_like = - // Must not be a reference - !std::is_reference_v && + template + using decayed_range_value_t = std::decay_t>; - // Must have an index() member function returning a size_t - requires(const T& v) { - { v.index() } -> std::convertible_to; - } && + template + void for_each_index_impl(F&& f, std::index_sequence) + { + // Apply f to each index individually + (f(std::integral_constant{}), ...); + } - // Must work with std::visit - requires(T v) { - std::visit([](auto&&) {}, v); // Use a generic lambda to test visitation - } && + template + void for_each_index(F&& f) + { + for_each_index_impl(std::forward(f), std::make_index_sequence()); + } - // Must allow std::get with an index - requires(T v) { - { std::get<0>(v) }; // Access by index - } && + template + bool exitable_for_each_index_impl(F&& f, std::index_sequence) + { + return (f(std::integral_constant{}) && ...); + } - // Must allow std::get with a type - requires(T v) { - { std::get::type>(v) }; // Access by type + template + bool exitable_for_each_index(F&& f) + { + return exitable_for_each_index_impl(std::forward(f), std::make_index_sequence()); } - ; - template - concept tuple_like = !std::is_reference_v - && requires(T t) { - typename std::tuple_size::type; - requires std::derived_from, std::integral_constant>>; + + template + concept has_tuple_element = requires(T t) { + typename std::tuple_element_t>; + { get(t) } -> std::convertible_to&>; + }; + + template + constexpr bool check_tuple_elements(std::index_sequence) + { + return (has_tuple_element && ...); } - && is_tuple_like(); + template + constexpr bool is_tuple_like() + { + return check_tuple_elements(std::make_index_sequence>()); + } - template - constexpr bool all_elements_same_impl(std::index_sequence) { - return sizeof...(Is) == 0 || ((std::is_same_v< - std::tuple_element_t<0, Tuple>, - std::tuple_element_t - >) && ...); - } + template + concept variant_like = + // Must not be a reference + !std::is_reference_v && + + // Must have an index() member function returning a size_t + requires(const T& v) { + { v.index() } -> std::convertible_to; + } && + + // Must work with std::visit + requires(T v) { + std::visit([](auto&&) {}, v); // Use a generic lambda to test visitation + } && + + // Must allow std::get with an index + requires(T v) { + { std::get<0>(v) }; // Access by index + } && + + // Must allow std::get with a type + requires(T v) { + { std::get::type>(v) }; // Access by type + }; + + template + concept tuple_like = !std::is_reference_v && requires(T t) { + typename std::tuple_size::type; + requires std::derived_from, std::integral_constant>>; + } && is_tuple_like(); - template - concept all_elements_same = tuple_like && - all_elements_same_impl( - std::make_index_sequence>{} - ); + template + constexpr bool all_elements_same_impl(std::index_sequence) + { + return sizeof...(Is) == 0 + || ((std::is_same_v, std::tuple_element_t>) && ...); + } + template + concept all_elements_same = tuple_like + && all_elements_same_impl(std::make_index_sequence>{ + }); - template - struct maybe_nullable_value_type - { - using type = T; - }; + template + struct maybe_nullable_value_type + { + using type = T; + }; - template - struct maybe_nullable_value_type - { - using type = typename T::value_type; - }; + template + struct maybe_nullable_value_type + { + using type = typename T::value_type; + }; - // shorthand for maybe_nullable_value_type::type - template - using mnv_t = typename maybe_nullable_value_type::type; + // shorthand for maybe_nullable_value_type::type + template + using mnv_t = typename maybe_nullable_value_type::type; - template - struct maybe_express_layout_desire_value_type - { - using type = T; - }; + template + struct maybe_express_layout_desire_value_type + { + using type = T; + }; - template - struct maybe_express_layout_desire_value_type - { - using type = typename T::value_type; - }; - // shorthand for maybe_express_layout_desire_value_type::type - template - using meldv_t = typename maybe_express_layout_desire_value_type::type; - - - template - using layout_flag_t = std::conditional_t< - is_dict_encode>, - enforce_dict_encoded_layout, - std::conditional_t< - is_run_end_encode>, - enforce_run_end_encoded_layout, - dont_enforce_layout - > - >; - - template - using look_trough_t = meldv_t>>; - - // shorhand for look_trough_t> - template - using ensured_range_value_t = look_trough_t>; - - // helper to get inner value type of smth like a vector of vector of T - // we also translate any nullable to the inner type - template - using nested_ensured_range_inner_value_t = ensured_range_value_t>; - - // a save way to return .size from - // a possibly nullable object or "express layout desire object" - template - std::size_t get_size_save(T&& t) - { - using decayed = std::decay_t; - if constexpr(is_nullable_like) + template + struct maybe_express_layout_desire_value_type + { + using type = typename T::value_type; + }; + // shorthand for maybe_express_layout_desire_value_type::type + template + using meldv_t = typename maybe_express_layout_desire_value_type::type; + + + template + using layout_flag_t = std::conditional_t< + is_dict_encode>, + enforce_dict_encoded_layout, + std::conditional_t>, enforce_run_end_encoded_layout, dont_enforce_layout>>; + + template + using look_trough_t = meldv_t>>; + + // shorhand for look_trough_t> + template + using ensured_range_value_t = look_trough_t>; + + // helper to get inner value type of smth like a vector of vector of T + // we also translate any nullable to the inner type + template + using nested_ensured_range_inner_value_t = ensured_range_value_t>; + + // a save way to return .size from + // a possibly nullable object or "express layout desire object" + template + std::size_t get_size_save(T&& t) { - if (t.has_value()) + using decayed = std::decay_t; + if constexpr (is_nullable_like) + { + if (t.has_value()) + { + return get_size_save(t.get()); + } + else + { + return 0; + } + } + else if constexpr (is_express_layout_desire) { return get_size_save(t.get()); } else { - return 0; + return static_cast(t.size()); } } - else if constexpr(is_express_layout_desire) - { - return get_size_save(t.get()); - } - else - { - return static_cast(t.size()); - } - } - template - decltype(auto) ensure_value(T && t) - { - using decayed = std::decay_t; - if constexpr(is_nullable_like || is_express_layout_desire) + template + decltype(auto) ensure_value(T&& t) { - return ensure_value(std::forward(t).get()); - } - else{ - return std::forward(t); + using decayed = std::decay_t; + if constexpr (is_nullable_like || is_express_layout_desire) + { + return ensure_value(std::forward(t).get()); + } + else + { + return std::forward(t); + } } - } - template - requires(is_nullable_like< std::ranges::range_value_t>) - std::vector where_null(T && t) - { - std::vector result; - for (std::size_t i = 0; i < t.size(); ++i) + template + requires(is_nullable_like>) + std::vector where_null(T&& t) { - if (!t[i].has_value()) + std::vector result; + for (std::size_t i = 0; i < t.size(); ++i) { - result.push_back(i); + if (!t[i].has_value()) + { + result.push_back(i); + } } + return result; } - return result; - } - template - requires( - is_express_layout_desire< std::ranges::range_value_t> && - is_nullable_like< typename std::ranges::range_value_t::value_type > - ) - std::vector where_null(T && t) - { - std::vector result; - for (std::size_t i = 0; i < t.size(); ++i) + template + requires(is_express_layout_desire> && is_nullable_like::value_type>) + std::vector where_null(T&& t) { - if (!(t[i].get().has_value())) + std::vector result; + for (std::size_t i = 0; i < t.size(); ++i) { - result.push_back(i); + if (!(t[i].get().has_value())) + { + result.push_back(i); + } } + return result; } - return result; - } - - template - std::array where_null(T && ) - { - return {}; - } - template - requires(is_plain_value_type>) - decltype(auto) ensure_value_range(T && t) - { - return std::forward(t); - } + template + std::array where_null(T&&) + { + return {}; + } - template - requires(!is_plain_value_type>) - decltype(auto) ensure_value_range(T && t) - { - return t | std::views::transform([](auto && v) { - return ensure_value(std::forward(v)); - }); - } + template + requires(is_plain_value_type>) + decltype(auto) ensure_value_range(T&& t) + { + return std::forward(t); + } + + template + requires(!is_plain_value_type>) + decltype(auto) ensure_value_range(T&& t) + { + return t + | std::views::transform( + [](auto&& v) + { + return ensure_value(std::forward(v)); + } + ); + } -} // namespace detail + } // namespace detail -} // namespace sparrow \ No newline at end of file +} // namespace sparrow \ No newline at end of file diff --git a/include/sparrow/builder/nested_eq.hpp b/include/sparrow/builder/nested_eq.hpp index 8bf5fa0a0..38fdc6f18 100644 --- a/include/sparrow/builder/nested_eq.hpp +++ b/include/sparrow/builder/nested_eq.hpp @@ -19,29 +19,30 @@ #include #include + namespace sparrow { - namespace detail{ + namespace detail + { // nested eq / nested hash - template + template struct nested_eq; - // scalars - template - requires std::is_scalar_v + template + requires std::is_scalar_v struct nested_eq { bool operator()(const T& a, const T& b) const { return a == b; } - }; + }; - template + template struct nested_eq { bool operator()(const T& a, const T& b) const @@ -51,8 +52,8 @@ namespace sparrow }; // nullables - template - requires is_nullable_like + template + requires is_nullable_like struct nested_eq { bool operator()(const T& a, const T& b) const @@ -68,37 +69,40 @@ namespace sparrow { return false; } - else{ - // both are not null + else + { + // both are not null return nested_eq{}(a.value(), b.value()); } } }; - // tuple like - template - requires tuple_like + // tuple like + template + requires tuple_like struct nested_eq { bool operator()(const T& a, const T& b) const { constexpr std::size_t N = std::tuple_size_v; - return exitable_for_each_index([&](auto i) - { - constexpr std::size_t index = decltype(i)::value; - using tuple_element_type = std::decay_t>; - - const auto& a_val = std::get(a); - const auto& b_val = std::get(b); - - return nested_eq{}(a_val, b_val); - }); + return exitable_for_each_index( + [&](auto i) + { + constexpr std::size_t index = decltype(i)::value; + using tuple_element_type = std::decay_t>; + + const auto& a_val = std::get(a); + const auto& b_val = std::get(b); + + return nested_eq{}(a_val, b_val); + } + ); } }; // ranges (and not tuple like) - template - requires(std::ranges::input_range && !tuple_like) + template + requires(std::ranges::input_range && !tuple_like) struct nested_eq { bool operator()(const T& a, const T& b) const @@ -108,8 +112,8 @@ namespace sparrow }; // variants - template - requires variant_like + template + requires variant_like struct nested_eq { bool operator()(const T& a, const T& b) const @@ -118,19 +122,19 @@ namespace sparrow { return false; } - return std::visit([&](const auto& a_val) - { - using value_type = std::decay_t; - const auto & b_val = std::get(b); - return nested_eq{}(a_val, b_val); - }, a); + return std::visit( + [&](const auto& a_val) + { + using value_type = std::decay_t; + const auto& b_val = std::get(b); + return nested_eq{}(a_val, b_val); + }, + a + ); } }; - } // namespace detail - - - + } // namespace detail -} // namespace sparrow \ No newline at end of file +} // namespace sparrow \ No newline at end of file diff --git a/include/sparrow/builder/nested_less.hpp b/include/sparrow/builder/nested_less.hpp index b3116ce72..9dc7218e8 100644 --- a/include/sparrow/builder/nested_less.hpp +++ b/include/sparrow/builder/nested_less.hpp @@ -19,29 +19,30 @@ #include #include + namespace sparrow { - namespace detail{ + namespace detail + { // nested eq / nested hash - template + template struct nested_less; - // scalars - template - requires std::is_scalar_v + template + requires std::is_scalar_v struct nested_less { bool operator()(const T& a, const T& b) const { return a < b; } - }; + }; - template + template struct nested_less { bool operator()(const T& a, const T& b) const @@ -51,8 +52,8 @@ namespace sparrow }; // nullables - template - requires is_nullable_like + template + requires is_nullable_like struct nested_less { bool operator()(const T& a, const T& b) const @@ -73,56 +74,59 @@ namespace sparrow { return false; } - else{ - // both are not null + else + { + // both are not null return nested_less{}(a.value(), b.value()); } } }; - // tuple like - template - requires tuple_like + // tuple like + template + requires tuple_like struct nested_less { bool operator()(const T& a, const T& b) const { constexpr std::size_t N = std::tuple_size_v; bool is_less = false; - exitable_for_each_index([&](auto i) - { - constexpr std::size_t index = decltype(i)::value; - using tuple_element_type = std::decay_t>; - - const auto& a_val = std::get(a); - const auto& b_val = std::get(b); - - // a < b - if(nested_less{}(a_val, b_val)) - { - is_less = true; - return false; // break - } - // a >= b - else if(nested_less{}(b_val, a_val)) + exitable_for_each_index( + [&](auto i) { - is_less = false; - return false; // break + constexpr std::size_t index = decltype(i)::value; + using tuple_element_type = std::decay_t>; + + const auto& a_val = std::get(a); + const auto& b_val = std::get(b); + + // a < b + if (nested_less{}(a_val, b_val)) + { + is_less = true; + return false; // break + } + // a >= b + else if (nested_less{}(b_val, a_val)) + { + is_less = false; + return false; // break + } + // a == b + else + { + is_less = false; + return true; // continue + } } - // a == b - else - { - is_less = false; - return true; // continue - } - }); + ); return is_less; } }; // ranges (and not tuple like) - template - requires(std::ranges::input_range && !tuple_like) + template + requires(std::ranges::input_range && !tuple_like) struct nested_less { bool operator()(const T& a, const T& b) const @@ -133,8 +137,8 @@ namespace sparrow }; // variants - template - requires variant_like + template + requires variant_like struct nested_less { bool operator()(const T& a, const T& b) const @@ -143,19 +147,19 @@ namespace sparrow { return a.index() < b.index(); } - return std::visit([&](const auto& a_val) - { - using value_type = std::decay_t; - const auto & b_val = std::get(b); - return nested_less{}(a_val, b_val); - }, a); + return std::visit( + [&](const auto& a_val) + { + using value_type = std::decay_t; + const auto& b_val = std::get(b); + return nested_less{}(a_val, b_val); + }, + a + ); } }; - } // namespace detail - - - + } // namespace detail -} // namespace sparrow \ No newline at end of file +} // namespace sparrow \ No newline at end of file diff --git a/include/sparrow/config/config.hpp b/include/sparrow/config/config.hpp index 87698e34f..6968505bb 100644 --- a/include/sparrow/config/config.hpp +++ b/include/sparrow/config/config.hpp @@ -27,15 +27,15 @@ #endif #if defined(_WIN32) -# if defined(SPARROW_STATIC_LIB) -# define SPARROW_API -# elif defined(SPARROW_EXPORTS) -# define SPARROW_API __declspec(dllexport) -# else -# define SPARROW_API __declspec(dllimport) -# endif +# if defined(SPARROW_STATIC_LIB) +# define SPARROW_API +# elif defined(SPARROW_EXPORTS) +# define SPARROW_API __declspec(dllexport) +# else +# define SPARROW_API __declspec(dllimport) +# endif #else -# define SPARROW_API __attribute__((visibility("default"))) +# define SPARROW_API __attribute__((visibility("default"))) #endif consteval bool is_apple_compiler() diff --git a/include/sparrow/layout/array_access.hpp b/include/sparrow/layout/array_access.hpp index f81e447f5..2e7e75b03 100644 --- a/include/sparrow/layout/array_access.hpp +++ b/include/sparrow/layout/array_access.hpp @@ -18,18 +18,18 @@ namespace sparrow::detail { - + class array_access { public: - template - static const sparrow::arrow_proxy& get_arrow_proxy(const ARRAY& array) + template + static const sparrow::arrow_proxy& get_arrow_proxy(const ARRAY& array) { return array.get_arrow_proxy(); } - template + template static sparrow::arrow_proxy& get_arrow_proxy(ARRAY& array) { return array.get_arrow_proxy(); diff --git a/include/sparrow/layout/array_bitmap_base.hpp b/include/sparrow/layout/array_bitmap_base.hpp index 386547747..e006dab5d 100644 --- a/include/sparrow/layout/array_bitmap_base.hpp +++ b/include/sparrow/layout/array_bitmap_base.hpp @@ -185,12 +185,10 @@ namespace sparrow template template requires std::same_as::value_type, bool> - auto array_bitmap_base_impl::insert_bitmap( - const_bitmap_iterator pos, - InputIt first, - InputIt last - ) -> bitmap_iterator - requires is_mutable + auto + array_bitmap_base_impl::insert_bitmap(const_bitmap_iterator pos, InputIt first, InputIt last) + -> bitmap_iterator + requires is_mutable { SPARROW_ASSERT_TRUE(this->bitmap_cbegin() <= pos) SPARROW_ASSERT_TRUE(pos <= this->bitmap_cend()); @@ -201,8 +199,8 @@ namespace sparrow } template - auto - array_bitmap_base_impl::erase_bitmap(const_bitmap_iterator pos, size_type count) -> bitmap_iterator + auto array_bitmap_base_impl::erase_bitmap(const_bitmap_iterator pos, size_type count) + -> bitmap_iterator requires is_mutable { SPARROW_ASSERT_TRUE(this->bitmap_cbegin() <= pos) diff --git a/include/sparrow/layout/array_wrapper.hpp b/include/sparrow/layout/array_wrapper.hpp index ccf8c6914..d3f8e3774 100644 --- a/include/sparrow/layout/array_wrapper.hpp +++ b/include/sparrow/layout/array_wrapper.hpp @@ -26,11 +26,10 @@ namespace sparrow { template - concept layout = requires(T& t) - { + concept layout = requires(T& t) { // inner_value_type typename T::inner_value_type; - + t[std::size_t()]; t.size(); t.begin(); @@ -40,16 +39,16 @@ namespace sparrow }; namespace detail - { - // Helper struct to allow overloading on the type of ARRAY - // to get the data_type for an array. This is needed since + { + // Helper struct to allow overloading on the type of ARRAY + // to get the data_type for an array. This is needed since // some arrays (for instance run_length_encoded_array) // do not have a inner_value_type, therefore we specialize // this in their respecitve headers. - template + template struct get_data_type_from_array { - constexpr static sparrow::data_type get() + static constexpr sparrow::data_type get() { return arrow_traits::type_id; } @@ -58,7 +57,7 @@ namespace sparrow template struct is_dictionary_encoded_array { - constexpr static bool get() + static constexpr bool get() { return false; } @@ -115,7 +114,7 @@ namespace sparrow T& get_wrapped(); const T& get_wrapped() const; - + private: using wrapper_ptr = array_wrapper::wrapper_ptr; @@ -162,13 +161,12 @@ namespace sparrow { return get_arrow_proxy_impl(); } - + inline const arrow_proxy& array_wrapper::get_arrow_proxy() const { return get_arrow_proxy_impl(); } - inline array_wrapper::array_wrapper(enum data_type dt) : m_data_type(dt) { @@ -225,14 +223,21 @@ namespace sparrow : array_wrapper(rhs) , m_storage(rhs.m_storage) { - p_array = std::visit([](auto&& arg) - { - using U = std::decay_t; - if constexpr (std::is_same_v) - return arg; - else - return arg.get(); - }, m_storage); + p_array = std::visit( + [](auto&& arg) + { + using U = std::decay_t; + if constexpr (std::is_same_v) + { + return arg; + } + else + { + return arg.get(); + } + }, + m_storage + ); } template @@ -253,7 +258,6 @@ namespace sparrow return detail::array_access::get_arrow_proxy(*p_array); } - template auto array_wrapper_impl::clone_impl() const -> wrapper_ptr { @@ -272,4 +276,3 @@ namespace sparrow return static_cast&>(ar).get_wrapped(); } } - diff --git a/include/sparrow/layout/dispatch.hpp b/include/sparrow/layout/dispatch.hpp index 2aa600bb6..49b55baaa 100644 --- a/include/sparrow/layout/dispatch.hpp +++ b/include/sparrow/layout/dispatch.hpp @@ -17,16 +17,16 @@ #include #include "sparrow/layout/array_wrapper.hpp" -#include "sparrow/layout/null_array.hpp" +#include "sparrow/layout/decimal_array.hpp" #include "sparrow/layout/dictionary_encoded_array.hpp" -#include "sparrow/layout/primitive_array.hpp" +#include "sparrow/layout/list_layout/list_array.hpp" #include "sparrow/layout/nested_value_types.hpp" +#include "sparrow/layout/null_array.hpp" +#include "sparrow/layout/primitive_array.hpp" #include "sparrow/layout/run_end_encoded_layout/run_end_encoded_array.hpp" -#include "sparrow/layout/list_layout/list_array.hpp" #include "sparrow/layout/struct_layout/struct_array.hpp" -#include "sparrow/layout/variable_size_binary_layout/variable_size_binary_array.hpp" #include "sparrow/layout/union_array.hpp" -#include "sparrow/layout/decimal_array.hpp" +#include "sparrow/layout/variable_size_binary_layout/variable_size_binary_array.hpp" #include "sparrow/types/data_traits.hpp" namespace sparrow @@ -39,96 +39,96 @@ namespace sparrow { if (ar.is_dictionary()) { - switch(ar.data_type()) + switch (ar.data_type()) { - case data_type::UINT8: - return func(unwrap_array>(ar)); - case data_type::INT8: - return func(unwrap_array>(ar)); - case data_type::UINT16: - return func(unwrap_array>(ar)); - case data_type::INT16: - return func(unwrap_array>(ar)); - case data_type::UINT32: - return func(unwrap_array>(ar)); - case data_type::INT32: - return func(unwrap_array>(ar)); - case data_type::UINT64: - return func(unwrap_array>(ar)); - case data_type::INT64: - return func(unwrap_array>(ar)); - default: - throw std::runtime_error("data datype of dictionary encoded array must be an integer"); + case data_type::UINT8: + return func(unwrap_array>(ar)); + case data_type::INT8: + return func(unwrap_array>(ar)); + case data_type::UINT16: + return func(unwrap_array>(ar)); + case data_type::INT16: + return func(unwrap_array>(ar)); + case data_type::UINT32: + return func(unwrap_array>(ar)); + case data_type::INT32: + return func(unwrap_array>(ar)); + case data_type::UINT64: + return func(unwrap_array>(ar)); + case data_type::INT64: + return func(unwrap_array>(ar)); + default: + throw std::runtime_error("data datype of dictionary encoded array must be an integer"); } } else { - switch(ar.data_type()) + switch (ar.data_type()) { - case data_type::NA: - return func(unwrap_array(ar));; - case data_type::BOOL: - return func(unwrap_array>(ar)); - case data_type::UINT8: - return func(unwrap_array>(ar)); - case data_type::INT8: - return func(unwrap_array>(ar)); - case data_type::UINT16: - return func(unwrap_array>(ar)); - case data_type::INT16: - return func(unwrap_array>(ar)); - case data_type::UINT32: - return func(unwrap_array>(ar)); - case data_type::INT32: - return func(unwrap_array>(ar)); - case data_type::UINT64: - return func(unwrap_array>(ar)); - case data_type::INT64: - return func(unwrap_array>(ar)); - case data_type::HALF_FLOAT: - return func(unwrap_array>(ar)); - case data_type::FLOAT: - return func(unwrap_array>(ar)); - case data_type::DOUBLE: - return func(unwrap_array>(ar)); - case data_type::STRING: - return func(unwrap_array(ar)); - case data_type::LARGE_STRING: - return func(unwrap_array(ar)); - case data_type::BINARY: - return func(unwrap_array(ar)); - case data_type::LARGE_BINARY: - return func(unwrap_array(ar)); - case data_type::RUN_ENCODED: - return func(unwrap_array(ar)); - case data_type::LIST: - return func(unwrap_array(ar)); - case data_type::LARGE_LIST: - return func(unwrap_array(ar)); - case data_type::LIST_VIEW: - return func(unwrap_array(ar)); - case data_type::LARGE_LIST_VIEW: - return func(unwrap_array(ar)); - case data_type::FIXED_SIZED_LIST: - return func(unwrap_array(ar)); - case data_type::STRUCT: - return func(unwrap_array(ar)); - case data_type::DENSE_UNION: - return func(unwrap_array(ar)); - case data_type::SPARSE_UNION: - return func(unwrap_array(ar)); - case data_type::DECIMAL32: - return func(unwrap_array(ar)); - case data_type::DECIMAL64: - return func(unwrap_array(ar)); - case data_type::DECIMAL128: - return func(unwrap_array(ar)); - case data_type::DECIMAL256: - return func(unwrap_array(ar)); - default: - throw std::invalid_argument("array type not supported"); + case data_type::NA: + return func(unwrap_array(ar)); + ; + case data_type::BOOL: + return func(unwrap_array>(ar)); + case data_type::UINT8: + return func(unwrap_array>(ar)); + case data_type::INT8: + return func(unwrap_array>(ar)); + case data_type::UINT16: + return func(unwrap_array>(ar)); + case data_type::INT16: + return func(unwrap_array>(ar)); + case data_type::UINT32: + return func(unwrap_array>(ar)); + case data_type::INT32: + return func(unwrap_array>(ar)); + case data_type::UINT64: + return func(unwrap_array>(ar)); + case data_type::INT64: + return func(unwrap_array>(ar)); + case data_type::HALF_FLOAT: + return func(unwrap_array>(ar)); + case data_type::FLOAT: + return func(unwrap_array>(ar)); + case data_type::DOUBLE: + return func(unwrap_array>(ar)); + case data_type::STRING: + return func(unwrap_array(ar)); + case data_type::LARGE_STRING: + return func(unwrap_array(ar)); + case data_type::BINARY: + return func(unwrap_array(ar)); + case data_type::LARGE_BINARY: + return func(unwrap_array(ar)); + case data_type::RUN_ENCODED: + return func(unwrap_array(ar)); + case data_type::LIST: + return func(unwrap_array(ar)); + case data_type::LARGE_LIST: + return func(unwrap_array(ar)); + case data_type::LIST_VIEW: + return func(unwrap_array(ar)); + case data_type::LARGE_LIST_VIEW: + return func(unwrap_array(ar)); + case data_type::FIXED_SIZED_LIST: + return func(unwrap_array(ar)); + case data_type::STRUCT: + return func(unwrap_array(ar)); + case data_type::DENSE_UNION: + return func(unwrap_array(ar)); + case data_type::SPARSE_UNION: + return func(unwrap_array(ar)); + case data_type::DECIMAL32: + return func(unwrap_array(ar)); + case data_type::DECIMAL64: + return func(unwrap_array(ar)); + case data_type::DECIMAL128: + return func(unwrap_array(ar)); + case data_type::DECIMAL256: + return func(unwrap_array(ar)); + default: + throw std::invalid_argument("array type not supported"); } } } } - diff --git a/include/sparrow/layout/layout_utils.hpp b/include/sparrow/layout/layout_utils.hpp index 8dddff6f7..ccf3049c7 100644 --- a/include/sparrow/layout/layout_utils.hpp +++ b/include/sparrow/layout/layout_utils.hpp @@ -14,9 +14,9 @@ #pragma once -#include "sparrow/utils/ranges.hpp" -#include "sparrow/utils/functor_index_iterator.hpp" #include "sparrow/buffer/u8_buffer.hpp" +#include "sparrow/utils/functor_index_iterator.hpp" +#include "sparrow/utils/ranges.hpp" namespace sparrow::detail { @@ -24,7 +24,7 @@ namespace sparrow::detail // // This is usefull to create a iterator over the values of a layout. // This functor will be passed to the functor_index_iterator. - template + template class layout_value_functor { public: @@ -47,12 +47,11 @@ namespace sparrow::detail layout_type* p_layout; }; - // Functor to get the optional-value of the layout at index i. // // This is usefull to create a iterator over the nullable-values of a layout. // This functor will be passed to the functor_index_iterator. - template + template class layout_bracket_functor { public: @@ -75,16 +74,15 @@ namespace sparrow::detail layout_type* p_layout; }; - - template - requires(std::unsigned_integral>) - sparrow::u8_buffer offset_buffer_from_sizes(SIZES_RANGE && sizes) + template + requires(std::unsigned_integral>) + sparrow::u8_buffer offset_buffer_from_sizes(SIZES_RANGE&& sizes) { - sparrow::u8_buffer buffer( range_size(sizes) + 1); + sparrow::u8_buffer buffer(range_size(sizes) + 1); OFFSET_TYPE offset = 0; auto it = buffer.begin(); - for(auto size : sizes) + for (auto size : sizes) { *it = offset; offset += static_cast(size); @@ -94,4 +92,4 @@ namespace sparrow::detail return buffer; } -} // namespace sparrow +} // namespace sparrow diff --git a/include/sparrow/layout/list_layout/list_array.hpp b/include/sparrow/layout/list_layout/list_array.hpp index 2e2f4dd36..93997b293 100644 --- a/include/sparrow/layout/list_layout/list_array.hpp +++ b/include/sparrow/layout/list_layout/list_array.hpp @@ -680,8 +680,8 @@ namespace sparrow } template - inline auto - list_view_array_impl::offset_range(size_type i) const -> std::pair + inline auto list_view_array_impl::offset_range(size_type i) const + -> std::pair { const auto offset = p_list_offsets[i]; return std::make_pair(offset, offset + p_list_sizes[i]); diff --git a/include/sparrow/layout/list_layout/list_value.hpp b/include/sparrow/layout/list_layout/list_value.hpp index 778dbbceb..0e1d721fa 100644 --- a/include/sparrow/layout/list_layout/list_value.hpp +++ b/include/sparrow/layout/list_layout/list_value.hpp @@ -60,7 +60,8 @@ struct std::formatter return ctx.begin(); // Simple implementation } - SPARROW_API auto format(const sparrow::list_value& list_value, std::format_context& ctx) const -> decltype(ctx.out()); + SPARROW_API auto format(const sparrow::list_value& list_value, std::format_context& ctx) const + -> decltype(ctx.out()); }; #endif diff --git a/include/sparrow/layout/nested_value_types.hpp b/include/sparrow/layout/nested_value_types.hpp index ce6275fcb..4eaa535ec 100644 --- a/include/sparrow/layout/nested_value_types.hpp +++ b/include/sparrow/layout/nested_value_types.hpp @@ -16,7 +16,7 @@ // we bundle all nested value types in this file // otherwise one has to include **all** nested value types -// wherever the nested value type variant is used +// wherever the nested value type variant is used // (otherwise there will be incomplete type errors) #include "sparrow/layout/list_layout/list_value.hpp" #include "sparrow/layout/struct_layout/struct_value.hpp" diff --git a/include/sparrow/layout/primitive_array.hpp b/include/sparrow/layout/primitive_array.hpp index 3fcff6c4a..51c8c64d7 100644 --- a/include/sparrow/layout/primitive_array.hpp +++ b/include/sparrow/layout/primitive_array.hpp @@ -495,8 +495,8 @@ namespace sparrow template template InputIt> - auto - primitive_array::insert_values(const_value_iterator pos, InputIt first, InputIt last) -> value_iterator + auto primitive_array::insert_values(const_value_iterator pos, InputIt first, InputIt last) + -> value_iterator { SPARROW_ASSERT_TRUE(value_cbegin() <= pos) SPARROW_ASSERT_TRUE(pos <= value_cend()); diff --git a/include/sparrow/layout/run_end_encoded_layout/run_end_encoded_iterator.hpp b/include/sparrow/layout/run_end_encoded_layout/run_end_encoded_iterator.hpp index 8faafb855..bc485ff82 100644 --- a/include/sparrow/layout/run_end_encoded_layout/run_end_encoded_iterator.hpp +++ b/include/sparrow/layout/run_end_encoded_layout/run_end_encoded_iterator.hpp @@ -14,10 +14,10 @@ #pragma once -#include "sparrow/config/config.hpp" -#include "sparrow/layout/array_wrapper.hpp" #include "sparrow/array_factory.hpp" +#include "sparrow/config/config.hpp" #include "sparrow/layout/array_helper.hpp" +#include "sparrow/layout/array_wrapper.hpp" #include "sparrow/layout/layout_utils.hpp" #include "sparrow/layout/nested_value_types.hpp" #include "sparrow/utils/iterator.hpp" @@ -30,68 +30,73 @@ namespace sparrow class run_end_encoded_array; // this iteratas over the **actual** values of the run encoded array - // Ie nullabes values, not values !!! - template + // Ie nullabes values, not values !!! + template class run_encoded_array_iterator : public iterator_base< - run_encoded_array_iterator, - array_traits::const_reference, - std::forward_iterator_tag, - array_traits::const_reference - > - { - + run_encoded_array_iterator, + array_traits::const_reference, + std::forward_iterator_tag, + array_traits::const_reference> + { private: - using array_ptr_type = std::conditional_t; + + using array_ptr_type = std::conditional_t; + public: + run_encoded_array_iterator() = default; run_encoded_array_iterator(array_ptr_type array_ptr, std::uint64_t index, std::uint64_t run_end_index); + private: bool equal(const run_encoded_array_iterator& rhs) const; void increment(); array_traits::const_reference dereference() const; array_ptr_type p_array = nullptr; - array_wrapper * p_encoded_values_array = nullptr; - std::uint64_t m_index = 0 ; // the current index / the index the user sees + array_wrapper* p_encoded_values_array = nullptr; + std::uint64_t m_index = 0; // the current index / the index the user sees std::uint64_t m_run_end_index = 0; // the current index in the run ends array std::uint64_t m_runs_left = 0; // the number of runs left in the current run friend class iterator_access; }; - - template - run_encoded_array_iterator::run_encoded_array_iterator(array_ptr_type array_ptr, std::uint64_t index, std::uint64_t run_end_index) - : - p_array(array_ptr), - p_encoded_values_array(array_ptr->p_encoded_values_array.get()), - m_index(index), - m_run_end_index(run_end_index), - m_runs_left(array_ptr->get_run_length(index)) + + template + run_encoded_array_iterator::run_encoded_array_iterator( + array_ptr_type array_ptr, + std::uint64_t index, + std::uint64_t run_end_index + ) + : p_array(array_ptr) + , p_encoded_values_array(array_ptr->p_encoded_values_array.get()) + , m_index(index) + , m_run_end_index(run_end_index) + , m_runs_left(array_ptr->get_run_length(index)) { } - template + template bool run_encoded_array_iterator::equal(const run_encoded_array_iterator& rhs) const { return m_index == rhs.m_index; } - template + template void run_encoded_array_iterator::increment() { ++m_index; --m_runs_left; - if(m_runs_left == 0 && m_index < p_array->size()) + if (m_runs_left == 0 && m_index < p_array->size()) { ++m_run_end_index; m_runs_left = p_array->get_run_length(m_run_end_index); } } - template + template typename array_traits::const_reference run_encoded_array_iterator::dereference() const { return array_element(*p_encoded_values_array, static_cast(m_run_end_index)); } -} // namespace sparrow +} // namespace sparrow diff --git a/include/sparrow/layout/struct_layout/struct_value.hpp b/include/sparrow/layout/struct_layout/struct_value.hpp index 18181fe76..789fe56f9 100644 --- a/include/sparrow/layout/struct_layout/struct_value.hpp +++ b/include/sparrow/layout/struct_layout/struct_value.hpp @@ -65,7 +65,8 @@ struct std::formatter return ctx.begin(); // Simple implementation } - SPARROW_API auto format(const sparrow::struct_value& ar, std::format_context& ctx) const -> decltype(ctx.out()); + SPARROW_API auto format(const sparrow::struct_value& ar, std::format_context& ctx) const + -> decltype(ctx.out()); }; #endif diff --git a/include/sparrow/layout/union_array.hpp b/include/sparrow/layout/union_array.hpp index f0f6d78f3..a43e75ab2 100644 --- a/include/sparrow/layout/union_array.hpp +++ b/include/sparrow/layout/union_array.hpp @@ -250,8 +250,8 @@ namespace sparrow template template - auto - union_array_crtp_base::type_id_map_from_child_to_type_id(R&& child_index_to_type_id) -> type_id_map + auto union_array_crtp_base::type_id_map_from_child_to_type_id(R&& child_index_to_type_id) + -> type_id_map { const std::size_t n = std::ranges::size(child_index_to_type_id); std::array ret; diff --git a/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_array.hpp b/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_array.hpp index fc63defea..3878ac564 100644 --- a/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_array.hpp +++ b/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_array.hpp @@ -80,48 +80,51 @@ namespace sparrow class variable_size_binary_array_impl; using binary_traits = arrow_traits>; - - using string_array = variable_size_binary_array_impl; + + using string_array = variable_size_binary_array_impl; using big_string_array = variable_size_binary_array_impl; - using binary_array = variable_size_binary_array_impl; - using big_binary_array = variable_size_binary_array_impl; + using binary_array = variable_size_binary_array_impl; + using big_binary_array = variable_size_binary_array_impl< + binary_traits::value_type, + binary_traits::const_reference, + std::int64_t>; namespace detail { - template + template struct get_data_type_from_array; - template<> + template <> struct get_data_type_from_array { - constexpr static sparrow::data_type get() + static constexpr sparrow::data_type get() { return sparrow::data_type::STRING; } }; - template<> + template <> struct get_data_type_from_array { - constexpr static sparrow::data_type get() + static constexpr sparrow::data_type get() { return sparrow::data_type::LARGE_STRING; } }; - template<> + template <> struct get_data_type_from_array { - constexpr static sparrow::data_type get() + static constexpr sparrow::data_type get() { return sparrow::data_type::BINARY; } }; - template<> + template <> struct get_data_type_from_array { - constexpr static sparrow::data_type get() + static constexpr sparrow::data_type get() { return sparrow::data_type::LARGE_BINARY; } @@ -139,7 +142,7 @@ namespace sparrow */ template constexpr bool is_big_string_array_v = std::same_as; - + /** * Checks whether T is a binary_array type. */ @@ -206,8 +209,11 @@ namespace sparrow { private: - static_assert(sizeof(std::ranges::range_value_t) == sizeof(std::uint8_t), - "Only sequences of types with the same size as uint8_t are supported"); + static_assert( + sizeof(std::ranges::range_value_t) == sizeof(std::uint8_t), + "Only sequences of types with the same size as uint8_t are supported" + ); + public: using self_type = variable_size_binary_array_impl; @@ -373,7 +379,8 @@ namespace sparrow template template - auto variable_size_binary_array_impl::offset_from_sizes(SIZES_RANGE&& sizes) -> offset_buffer_type + auto variable_size_binary_array_impl::offset_from_sizes(SIZES_RANGE&& sizes) + -> offset_buffer_type { return detail::offset_buffer_from_sizes>(std::forward(sizes )); @@ -544,7 +551,13 @@ namespace sparrow } ); } - auto tmp = std::views::transform(rhs, [](const auto& val) { return static_cast(val); }); + auto tmp = std::views::transform( + rhs, + [](const auto& val) + { + return static_cast(val); + } + ); // Copy the new value into the buffer std::copy(std::ranges::begin(tmp), std::ranges::end(tmp), data_buffer.begin() + offset_beg); } diff --git a/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_iterator.hpp b/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_iterator.hpp index 6980b9f8c..934b0273a 100644 --- a/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_iterator.hpp +++ b/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_iterator.hpp @@ -114,8 +114,8 @@ namespace sparrow } template - auto variable_size_binary_value_iterator::distance_to(const self_type& rhs - ) const -> difference_type + auto variable_size_binary_value_iterator::distance_to(const self_type& rhs) const + -> difference_type { return rhs.m_index - m_index; } diff --git a/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_reference.hpp b/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_reference.hpp index 6ca1914ea..48afcbb44 100644 --- a/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_reference.hpp +++ b/include/sparrow/layout/variable_size_binary_layout/variable_size_binary_reference.hpp @@ -225,4 +225,3 @@ namespace sparrow return static_cast(offset(index)); } } - diff --git a/include/sparrow/record_batch.hpp b/include/sparrow/record_batch.hpp index 32d44dbd1..892b02355 100644 --- a/include/sparrow/record_batch.hpp +++ b/include/sparrow/record_batch.hpp @@ -194,18 +194,18 @@ struct std::formatter auto format(const sparrow::record_batch& rb, std::format_context& ctx) const { const auto values_by_columns = rb.columns() - | std::views::transform( - [&rb](const auto& ar) - { - return std::views::iota(0u, rb.nb_rows()) - | std::views::transform( - [&ar](const auto i) - { - return ar[i]; - } - ); - } - ); + | std::views::transform( + [&rb](const auto& ar) + { + return std::views::iota(0u, rb.nb_rows()) + | std::views::transform( + [&ar](const auto i) + { + return ar[i]; + } + ); + } + ); sparrow::to_table_with_columns(ctx.out(), rb.names(), values_by_columns); return ctx.out(); diff --git a/include/sparrow/types/data_traits.hpp b/include/sparrow/types/data_traits.hpp index 47546156d..a06881490 100644 --- a/include/sparrow/types/data_traits.hpp +++ b/include/sparrow/types/data_traits.hpp @@ -46,7 +46,6 @@ namespace sparrow static constexpr data_type type_id = data_type_from_size(); }; - template <> struct arrow_traits { @@ -119,8 +118,7 @@ namespace sparrow using value_type = decimal; using const_reference = decimal; }; - - + namespace detail { template @@ -142,24 +140,17 @@ namespace sparrow mpl::rename; // std::variant can not hold references, we need to write something based on variant and // reference_wrapper - //using inner_const_reference = /* std::variant */ + // using inner_const_reference = /* std::variant */ /* mpl::rename< mpl::transform< detail::array_inner_const_reference_t, all_base_types_t>, std::variant>;*/ using value_type = /* nullable_variant, nullable, nullable, ...> */ - mpl::rename< - mpl::transform< - detail::array_value_type_t, - all_base_types_t>, - nullable_variant>; - using const_reference = /* nullable_variant, nullable, nullable, ...> */ - mpl::rename< - mpl::transform< - detail::array_const_reference_t, - all_base_types_t>, - nullable_variant>; + mpl::rename, nullable_variant>; + using const_reference = /* nullable_variant, nullable, nullable, ...> */ + mpl::rename, nullable_variant>; }; namespace predicate diff --git a/include/sparrow/utils/bit.hpp b/include/sparrow/utils/bit.hpp index d494363a5..876bcd007 100644 --- a/include/sparrow/utils/bit.hpp +++ b/include/sparrow/utils/bit.hpp @@ -36,7 +36,7 @@ namespace sparrow std::ranges::reverse(value_representation); return std::bit_cast(value_representation); } - + template constexpr auto to_native_endian(std::integral auto value) noexcept { diff --git a/include/sparrow/utils/crtp_base.hpp b/include/sparrow/utils/crtp_base.hpp index 0ac21d44b..49ea7f5ef 100644 --- a/include/sparrow/utils/crtp_base.hpp +++ b/include/sparrow/utils/crtp_base.hpp @@ -24,7 +24,7 @@ namespace sparrow * * @tparam D The derived type. */ - template + template class crtp_base { protected: @@ -35,13 +35,13 @@ namespace sparrow const derived_type& derived_cast() const; }; - template + template auto crtp_base::derived_cast() -> derived_type& { return static_cast(*this); } - template + template auto crtp_base::derived_cast() const -> const derived_type& { return static_cast(*this); diff --git a/include/sparrow/utils/functor_index_iterator.hpp b/include/sparrow/utils/functor_index_iterator.hpp index 9be14f941..710aaf656 100644 --- a/include/sparrow/utils/functor_index_iterator.hpp +++ b/include/sparrow/utils/functor_index_iterator.hpp @@ -14,18 +14,18 @@ #pragma once -#include "sparrow/utils/iterator.hpp" #include "sparrow/utils/contracts.hpp" +#include "sparrow/utils/iterator.hpp" namespace sparrow { - template + template class functor_index_iterator : public iterator_base< - functor_index_iterator, // Derived - std::invoke_result_t, // Element - std::random_access_iterator_tag, - std::invoke_result_t // Reference - > + functor_index_iterator, // Derived + std::invoke_result_t, // Element + std::random_access_iterator_tag, + std::invoke_result_t // Reference + > { public: @@ -35,13 +35,13 @@ namespace sparrow using size_type = std::size_t; constexpr functor_index_iterator() = default; - + constexpr functor_index_iterator(FUNCTOR functor, size_type index) : m_functor(std::move(functor)) , m_index(index) { } - + private: result_type dereference() const @@ -71,7 +71,7 @@ namespace sparrow m_index -= static_cast(-n); } } - + difference_type distance_to(const self_type& rhs) const { return static_cast(rhs.m_index) - static_cast(m_index); @@ -93,4 +93,3 @@ namespace sparrow friend class iterator_access; }; } - diff --git a/include/sparrow/utils/iterator.hpp b/include/sparrow/utils/iterator.hpp index 2d2a971d1..ab3e8f9f7 100644 --- a/include/sparrow/utils/iterator.hpp +++ b/include/sparrow/utils/iterator.hpp @@ -21,7 +21,7 @@ #include namespace sparrow -{ +{ namespace detail { diff --git a/include/sparrow/utils/memory.hpp b/include/sparrow/utils/memory.hpp index dbfa9bf6c..cfcd6e6d4 100644 --- a/include/sparrow/utils/memory.hpp +++ b/include/sparrow/utils/memory.hpp @@ -36,6 +36,7 @@ namespace sparrow class value_ptr { using internal_pointer = std::unique_ptr; + public: using self_type = value_ptr; @@ -81,7 +82,7 @@ namespace sparrow internal_pointer value_; }; - + namespace detail { template @@ -107,17 +108,17 @@ namespace sparrow */ template concept clonable = std::derived_from()->clone())>> - && detail::is_unique_ptr_v()->clone())>; + && detail::is_unique_ptr_v()->clone())>; /** * Smart pointer behaving like a copiable std::unique_ptr. - * + * * `cloning_ptr` owns and manages another object through a pointer, like - * `std::unique_ptr`. The difference with `std::unique_ptr` is that + * `std::unique_ptr`. The difference with `std::unique_ptr` is that * `cloning_ptr`calls the `clone` method of the managed object upon copy. * `Therefore, `cloning_ptr` is meant to be used with hierarchies of * classes which provide a `clone` method which returns a unique pointer. - * + * * @tparam T The type of the object managed by the `cloning_ptr`. It must * satisfy the `clonable` concept. */ @@ -125,6 +126,7 @@ namespace sparrow class cloning_ptr { using internal_pointer = std::unique_ptr; + public: using self_type = cloning_ptr; @@ -141,14 +143,14 @@ namespace sparrow constexpr cloning_ptr(const self_type& rhs) noexcept; constexpr cloning_ptr(self_type&& rhs) noexcept = default; - + template - requires std::convertible_to + requires std::convertible_to constexpr cloning_ptr(const cloning_ptr& rhs) noexcept; template - requires std::convertible_to + requires std::convertible_to constexpr cloning_ptr(cloning_ptr&& rhs) noexcept; constexpr self_type& operator=(const self_type&) noexcept; @@ -156,11 +158,11 @@ namespace sparrow constexpr self_type& operator=(std::nullptr_t) noexcept; template - requires std::convertible_to + requires std::convertible_to constexpr self_type& operator=(const cloning_ptr& rhs) noexcept; template - requires std::convertible_to + requires std::convertible_to constexpr self_type& operator=(cloning_ptr&& rhs) noexcept; // Modifiers @@ -175,9 +177,8 @@ namespace sparrow constexpr explicit operator bool() const noexcept; - constexpr std::add_lvalue_reference_t - operator*() const noexcept(noexcept(*std::declval())); - + constexpr std::add_lvalue_reference_t operator*() const noexcept(noexcept(*std::declval())); + constexpr pointer operator->() const noexcept; private: @@ -192,30 +193,20 @@ namespace sparrow void swap(cloning_ptr& lhs, cloning_ptr& rhs) noexcept; template - requires std::equality_comparable_with< - typename cloning_ptr::pointer, - typename cloning_ptr::pointer> - constexpr - bool operator==(const cloning_ptr& lhs, const cloning_ptr& rhs) noexcept; + requires std::equality_comparable_with::pointer, typename cloning_ptr::pointer> + constexpr bool operator==(const cloning_ptr& lhs, const cloning_ptr& rhs) noexcept; template - requires std::three_way_comparable_with< - typename cloning_ptr::pointer, - typename cloning_ptr::pointer> - constexpr - std::compare_three_way_result_t< - typename cloning_ptr::pointer, - typename cloning_ptr::pointer> + requires std::three_way_comparable_with::pointer, typename cloning_ptr::pointer> + constexpr std::compare_three_way_result_t::pointer, typename cloning_ptr::pointer> operator<=>(const cloning_ptr& lhs, const cloning_ptr& rhs) noexcept; template - constexpr - bool operator==(const cloning_ptr& lhs, std::nullptr_t) noexcept; + constexpr bool operator==(const cloning_ptr& lhs, std::nullptr_t) noexcept; template - requires std::three_way_comparable::pointer> - constexpr - std::compare_three_way_result_t::pointer> + requires std::three_way_comparable::pointer> + constexpr std::compare_three_way_result_t::pointer> operator<=>(const cloning_ptr& lhs, std::nullptr_t) noexcept; template @@ -358,15 +349,15 @@ namespace sparrow template template - requires std::convertible_to + requires std::convertible_to constexpr cloning_ptr::cloning_ptr(const cloning_ptr& rhs) noexcept : m_data(rhs ? rhs->clone() : nullptr) { } - + template template - requires std::convertible_to + requires std::convertible_to constexpr cloning_ptr::cloning_ptr(cloning_ptr&& rhs) noexcept : m_data(rhs.release()) { @@ -388,7 +379,7 @@ namespace sparrow template template - requires std::convertible_to + requires std::convertible_to constexpr auto cloning_ptr::operator=(const cloning_ptr& rhs) noexcept -> self_type& { m_data = rhs ? rhs->clone() : nullptr; @@ -397,7 +388,7 @@ namespace sparrow template template - requires std::convertible_to + requires std::convertible_to constexpr auto cloning_ptr::operator=(cloning_ptr&& rhs) noexcept -> self_type& { reset(rhs.release()); @@ -436,18 +427,18 @@ namespace sparrow } template - constexpr std::add_lvalue_reference_t - cloning_ptr::operator*() const noexcept(noexcept(*std::declval())) + constexpr std::add_lvalue_reference_t cloning_ptr::operator*() const + noexcept(noexcept(*std::declval())) { return *get(); } - + template constexpr auto cloning_ptr::operator->() const noexcept -> pointer { return get(); } - + template constexpr auto cloning_ptr::ptr_impl() noexcept -> internal_pointer& { @@ -471,39 +462,29 @@ namespace sparrow } template - requires std::equality_comparable_with< - typename cloning_ptr::pointer, - typename cloning_ptr::pointer> - constexpr - bool operator==(const cloning_ptr& lhs, const cloning_ptr& rhs) noexcept + requires std::equality_comparable_with::pointer, typename cloning_ptr::pointer> + constexpr bool operator==(const cloning_ptr& lhs, const cloning_ptr& rhs) noexcept { return lhs.get() == rhs.get(); } template - requires std::three_way_comparable_with< - typename cloning_ptr::pointer, - typename cloning_ptr::pointer> - constexpr - std::compare_three_way_result_t< - typename cloning_ptr::pointer, - typename cloning_ptr::pointer> + requires std::three_way_comparable_with::pointer, typename cloning_ptr::pointer> + constexpr std::compare_three_way_result_t::pointer, typename cloning_ptr::pointer> operator<=>(const cloning_ptr& lhs, const cloning_ptr& rhs) noexcept { return lhs.get() <=> rhs.get(); } template - constexpr - bool operator==(const cloning_ptr& lhs, std::nullptr_t) noexcept + constexpr bool operator==(const cloning_ptr& lhs, std::nullptr_t) noexcept { return !lhs; } template - requires std::three_way_comparable::pointer> - constexpr - std::compare_three_way_result_t::pointer> + requires std::three_way_comparable::pointer> + constexpr std::compare_three_way_result_t::pointer> operator<=>(const cloning_ptr& lhs, std::nullptr_t) noexcept { using pointer = typename cloning_ptr::pointer; diff --git a/include/sparrow/utils/mp_utils.hpp b/include/sparrow/utils/mp_utils.hpp index 927f793a6..28929ccf1 100644 --- a/include/sparrow/utils/mp_utils.hpp +++ b/include/sparrow/utils/mp_utils.hpp @@ -479,26 +479,27 @@ namespace sparrow::mpl template typename Qualifier> concept T_matches_qualifier_if_Y_is = Qualifier::value || !Qualifier::value; - // helper class to exclude copy and move constructors beeing routed // to a constructor with variadic arguments / perfect forwarding - template + template struct excludes_copy_and_move_ctor - { - constexpr static bool value = true; + { + static constexpr bool value = true; }; - template + + template struct excludes_copy_and_move_ctor { - constexpr static bool value = true; + static constexpr bool value = true; }; - template + + template struct excludes_copy_and_move_ctor { - constexpr static bool value = !std::is_same_v>; + static constexpr bool value = !std::is_same_v>; }; - template + template constexpr bool excludes_copy_and_move_ctor_v = excludes_copy_and_move_ctor::value; /** @@ -513,12 +514,12 @@ namespace sparrow::mpl */ template concept iterator_of_type = std::input_iterator - + && std::same_as::value_type, T>; - // todo...make smth better based on sizeof and is pod - template + // todo...make smth better based on sizeof and is pod + template concept char_like = std::same_as || std::same_as || std::same_as; } diff --git a/include/sparrow/utils/offsets.hpp b/include/sparrow/utils/offsets.hpp index 41a4bfd07..64e6d133e 100644 --- a/include/sparrow/utils/offsets.hpp +++ b/include/sparrow/utils/offsets.hpp @@ -15,22 +15,28 @@ #include #include -#include "sparrow/types/data_type.hpp" #include "sparrow/buffer/buffer.hpp" +#include "sparrow/types/data_type.hpp" #pragma once namespace sparrow { - template - requires std::ranges::sized_range> + template + requires std::ranges::sized_range> buffer make_offset_buffer(const R& range) { const size_t range_size = std::ranges::size(range); buffer offsets(range_size + 1, 0); - std::transform(range.cbegin(), range.cend(), offsets.begin() + 1, [](const auto& elem) { - return static_cast(elem.size()); - }); + std::transform( + range.cbegin(), + range.cend(), + offsets.begin() + 1, + [](const auto& elem) + { + return static_cast(elem.size()); + } + ); std::partial_sum(offsets.begin(), offsets.end(), offsets.begin()); return offsets; } diff --git a/include/sparrow/utils/ranges.hpp b/include/sparrow/utils/ranges.hpp index 4d90dcb96..9961b10b9 100644 --- a/include/sparrow/utils/ranges.hpp +++ b/include/sparrow/utils/ranges.hpp @@ -16,17 +16,17 @@ #include namespace sparrow -{ - template - requires(std::ranges::sized_range) - std::size_t range_size(R && r) +{ + template + requires(std::ranges::sized_range) + std::size_t range_size(R&& r) { return static_cast(std::ranges::size(r)); } - template - requires(!std::ranges::sized_range) - std::size_t range_size(R && r) + template + requires(!std::ranges::sized_range) + std::size_t range_size(R&& r) { return static_cast(std::ranges::distance(r)); } diff --git a/include/sparrow/utils/vector_view.hpp b/include/sparrow/utils/vector_view.hpp index 2659e667d..8ddaae0e4 100644 --- a/include/sparrow/utils/vector_view.hpp +++ b/include/sparrow/utils/vector_view.hpp @@ -19,7 +19,7 @@ #include #if defined(__cpp_lib_format) -# include +# include #endif namespace sparrow @@ -59,8 +59,7 @@ namespace sparrow } template - constexpr std::compare_three_way_result - operator<=>(const vector_view& lhs, const vector_view& rhs) + constexpr std::compare_three_way_result operator<=>(const vector_view& lhs, const vector_view& rhs) { return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } diff --git a/src/array_factory.cpp b/src/array_factory.cpp index 9a6595899..af1fe25b9 100644 --- a/src/array_factory.cpp +++ b/src/array_factory.cpp @@ -12,18 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include "sparrow/array_factory.hpp" -#include "sparrow/layout/list_layout/list_array.hpp" -#include "sparrow/layout/struct_layout/struct_array.hpp" + +#include + +#include "sparrow/layout/decimal_array.hpp" #include "sparrow/layout/dictionary_encoded_array.hpp" -#include "sparrow/layout/primitive_array.hpp" +#include "sparrow/layout/list_layout/list_array.hpp" #include "sparrow/layout/null_array.hpp" -#include "sparrow/layout/variable_size_binary_layout/variable_size_binary_array.hpp" +#include "sparrow/layout/primitive_array.hpp" #include "sparrow/layout/run_end_encoded_layout/run_end_encoded_array.hpp" +#include "sparrow/layout/struct_layout/struct_array.hpp" #include "sparrow/layout/union_array.hpp" -#include "sparrow/layout/decimal_array.hpp" - +#include "sparrow/layout/variable_size_binary_layout/variable_size_binary_array.hpp" namespace sparrow { @@ -32,7 +33,7 @@ namespace sparrow template cloning_ptr make_wrapper_ptr(arrow_proxy proxy) { - return cloning_ptr{new array_wrapper_impl(T(std::move(proxy))) }; + return cloning_ptr{new array_wrapper_impl(T(std::move(proxy)))}; } } @@ -42,100 +43,102 @@ namespace sparrow if (proxy.dictionary()) { - switch(dt) + switch (dt) { - case data_type::INT8: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::UINT8: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::INT16: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::UINT16: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::INT32: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::UINT32: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::INT64: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::UINT64: - return detail::make_wrapper_ptr>(std::move(proxy)); - default: - throw std::runtime_error("data datype of dictionary encoded array must be an integer"); + case data_type::INT8: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::UINT8: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::INT16: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::UINT16: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::INT32: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::UINT32: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::INT64: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::UINT64: + return detail::make_wrapper_ptr>(std::move(proxy)); + default: + throw std::runtime_error("data datype of dictionary encoded array must be an integer"); } } else { - switch(dt) + switch (dt) { - case data_type::NA: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::BOOL: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::INT8: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::UINT8: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::INT16: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::UINT16: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::INT32: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::UINT32: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::INT64: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::UINT64: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::HALF_FLOAT: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::FLOAT: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::DOUBLE: - return detail::make_wrapper_ptr>(std::move(proxy)); - case data_type::LIST:{ - return detail::make_wrapper_ptr(std::move(proxy)); - } - case data_type::LARGE_LIST:{ - return detail::make_wrapper_ptr(std::move(proxy)); - } - case data_type::LIST_VIEW: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::LARGE_LIST_VIEW: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::FIXED_SIZED_LIST: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::STRUCT: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::STRING: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::LARGE_STRING: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::BINARY: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::LARGE_BINARY: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::RUN_ENCODED: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::DENSE_UNION: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::SPARSE_UNION: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::TIMESTAMP: - case data_type::MAP: - case data_type::DECIMAL32: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::DECIMAL64: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::DECIMAL128: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::DECIMAL256: - return detail::make_wrapper_ptr(std::move(proxy)); - case data_type::FIXED_WIDTH_BINARY: - throw std::runtime_error("not yet supported data type"); - default: - throw std::runtime_error("not supported data type"); + case data_type::NA: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::BOOL: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::INT8: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::UINT8: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::INT16: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::UINT16: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::INT32: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::UINT32: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::INT64: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::UINT64: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::HALF_FLOAT: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::FLOAT: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::DOUBLE: + return detail::make_wrapper_ptr>(std::move(proxy)); + case data_type::LIST: + { + return detail::make_wrapper_ptr(std::move(proxy)); + } + case data_type::LARGE_LIST: + { + return detail::make_wrapper_ptr(std::move(proxy)); + } + case data_type::LIST_VIEW: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::LARGE_LIST_VIEW: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::FIXED_SIZED_LIST: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::STRUCT: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::STRING: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::LARGE_STRING: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::BINARY: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::LARGE_BINARY: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::RUN_ENCODED: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::DENSE_UNION: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::SPARSE_UNION: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::TIMESTAMP: + case data_type::MAP: + case data_type::DECIMAL32: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::DECIMAL64: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::DECIMAL128: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::DECIMAL256: + return detail::make_wrapper_ptr(std::move(proxy)); + case data_type::FIXED_WIDTH_BINARY: + throw std::runtime_error("not yet supported data type"); + default: + throw std::runtime_error("not supported data type"); } } } diff --git a/src/array_helper.cpp b/src/array_helper.cpp index ff7157a84..c4575febb 100644 --- a/src/array_helper.cpp +++ b/src/array_helper.cpp @@ -13,32 +13,55 @@ // limitations under the License. #include "sparrow/layout/array_helper.hpp" + #include "sparrow/layout/dispatch.hpp" namespace sparrow { std::size_t array_size(const array_wrapper& ar) { - return visit([](const auto& impl) { return impl.size(); }, ar); + return visit( + [](const auto& impl) + { + return impl.size(); + }, + ar + ); } bool array_has_value(const array_wrapper& ar, std::size_t index) { - return visit([index](const auto& impl) { return impl[index].has_value(); }, ar); + return visit( + [index](const auto& impl) + { + return impl[index].has_value(); + }, + ar + ); } array_traits::const_reference array_element(const array_wrapper& ar, std::size_t index) { using return_type = array_traits::const_reference; - return visit([index](const auto& impl) -> return_type { return return_type(impl[index]); }, ar); + return visit( + [index](const auto& impl) -> return_type + { + return return_type(impl[index]); + }, + ar + ); } array_traits::inner_value_type array_default_element_value(const array_wrapper& ar) { using return_type = array_traits::inner_value_type; - return visit([](const auto& impl) -> return_type { - using value_type = typename std::decay_t::inner_value_type; - return value_type(); - }, ar); + return visit( + [](const auto& impl) -> return_type + { + using value_type = typename std::decay_t::inner_value_type; + return value_type(); + }, + ar + ); } } diff --git a/src/arrow_interface/arrow_array.cpp b/src/arrow_interface/arrow_array.cpp index 402cdc5e8..3d6e92acf 100644 --- a/src/arrow_interface/arrow_array.cpp +++ b/src/arrow_interface/arrow_array.cpp @@ -40,15 +40,12 @@ namespace sparrow SPARROW_ASSERT_TRUE(array->release == std::addressof(empty_release_arrow_array)); } - - template - auto static_const_ptr_cast(const void *ptr) + template + auto static_const_ptr_cast(const void* ptr) { return const_cast(static_cast(ptr)); } - - // get the bit width for fixed width binary from format std::size_t num_bytes_for_fixed_sized_binary(const char* format) { @@ -57,43 +54,43 @@ namespace sparrow // check if format+2 is a number - if(!all_digits(std::string_view(format + 2))) + if (!all_digits(std::string_view(format + 2))) { throw std::runtime_error("Invalid format for fixed width binary"); } const auto width = std::atoi(format + 2); - if(width <= 0) + if (width <= 0) { throw std::runtime_error("Invalid format for fixed width binary"); } return static_cast(width); } - std::vector> get_arrow_array_buffers(const ArrowArray& array, const ArrowSchema& schema) - { + { using buffer_view_type = sparrow::buffer_view; const auto size = static_cast(array.length + array.offset); auto make_valid_buffer = [&]() { const auto buffer_size = static_cast(size + 7) / 8; auto typed_buffer_ptr = static_const_ptr_cast(array.buffers[0]); - return typed_buffer_ptr != nullptr ? buffer_view_type(typed_buffer_ptr, buffer_size) : buffer_view_type(nullptr, 0); + return typed_buffer_ptr != nullptr ? buffer_view_type(typed_buffer_ptr, buffer_size) + : buffer_view_type(nullptr, 0); }; - auto make_buffer = [&](auto index, auto size) + auto make_buffer = [&](auto index, auto size) { auto buffer_ptr = static_const_ptr_cast(array.buffers[index]); return buffer_view_type(buffer_ptr, size); }; - switch(format_to_data_type(schema.format)) - { + switch (format_to_data_type(schema.format)) + { case data_type::NA: case data_type::RUN_ENCODED: case data_type::MAP: return {}; - case data_type::BOOL: + case data_type::BOOL: return {make_valid_buffer(), make_buffer(1, (size + 7) / 8)}; case data_type::UINT8: case data_type::INT8: @@ -112,10 +109,18 @@ namespace sparrow return {make_valid_buffer(), make_buffer(1, size * 8)}; case data_type::STRING: case data_type::BINARY: - return {make_valid_buffer(),make_buffer(1, (size + 1) * 4), make_buffer(2, static_const_ptr_cast(array.buffers[1])[size])}; + return { + make_valid_buffer(), + make_buffer(1, (size + 1) * 4), + make_buffer(2, static_const_ptr_cast(array.buffers[1])[size]) + }; case data_type::LARGE_STRING: case data_type::LARGE_BINARY: - return {make_valid_buffer(),make_buffer(1, (size + 1) * 4), make_buffer(2, static_const_ptr_cast(array.buffers[1])[size])}; + return { + make_valid_buffer(), + make_buffer(1, (size + 1) * 4), + make_buffer(2, static_const_ptr_cast(array.buffers[1])[size]) + }; case data_type::LIST: return {make_valid_buffer(), make_buffer(1, (size + 1) * 4)}; case data_type::LARGE_LIST: @@ -126,11 +131,11 @@ namespace sparrow return {make_valid_buffer(), make_buffer(1, size * 8), make_buffer(2, size * 8)}; case data_type::FIXED_SIZED_LIST: case data_type::STRUCT: - return {make_valid_buffer()}; + return {make_valid_buffer()}; case data_type::SPARSE_UNION: return {make_buffer(0, size)}; case data_type::DENSE_UNION: - return {make_buffer(0, size), make_buffer(1, size*4)}; + return {make_buffer(0, size), make_buffer(1, size * 4)}; case data_type::TIMESTAMP: return {make_valid_buffer(), make_buffer(1, size * 8)}; case data_type::DECIMAL32: @@ -138,24 +143,27 @@ namespace sparrow case data_type::DECIMAL64: return {make_valid_buffer(), make_buffer(1, size * 8)}; case data_type::DECIMAL128: - return {make_valid_buffer(), make_buffer(1, size * 16)}; + return {make_valid_buffer(), make_buffer(1, size * 16)}; case data_type::DECIMAL256: - return {make_valid_buffer(), make_buffer(1, size * 32)}; + return {make_valid_buffer(), make_buffer(1, size * 32)}; case data_type::FIXED_WIDTH_BINARY: - return {make_valid_buffer(), make_buffer(1, size * num_bytes_for_fixed_sized_binary(schema.format))}; + return { + make_valid_buffer(), + make_buffer(1, size * num_bytes_for_fixed_sized_binary(schema.format)) + }; case data_type::STRING_VIEW: case data_type::BINARY_VIEW: const auto buffer_count = static_cast(array.n_buffers); const auto num_extra_data_buffers = buffer_count - 3; std::vector buffers(buffer_count); - int64_t * var_buffer_sizes = static_const_ptr_cast(array.buffers[buffer_count - 1]); + int64_t* var_buffer_sizes = static_const_ptr_cast(array.buffers[buffer_count - 1]); buffers[0] = make_valid_buffer(); buffers[1] = make_buffer(1, size * 16); for (size_t i = 0; i < num_extra_data_buffers; ++i) { buffers[i + 2] = make_buffer(i + 2, var_buffer_sizes[i]); } - buffers.back() = make_buffer(buffer_count -1 , size * 4); + buffers.back() = make_buffer(buffer_count - 1, size * 4); return buffers; } // To avoid stupid warning "control reaches end of non-void function" diff --git a/src/arrow_interface/arrow_schema.cpp b/src/arrow_interface/arrow_schema.cpp index dcf587c5d..7ec5d91bb 100644 --- a/src/arrow_interface/arrow_schema.cpp +++ b/src/arrow_interface/arrow_schema.cpp @@ -16,7 +16,6 @@ #include "sparrow/arrow_interface/arrow_array_schema_utils.hpp" - namespace sparrow { void release_arrow_schema(ArrowSchema* schema) diff --git a/src/dummy32bit.cpp b/src/dummy32bit.cpp index b7b590c6d..6b3cf9f3e 100644 --- a/src/dummy32bit.cpp +++ b/src/dummy32bit.cpp @@ -1,4 +1,6 @@ #include -SPARROW_API int dummy() { return 1; } - +SPARROW_API int dummy() +{ + return 1; +} diff --git a/src/list_value.cpp b/src/list_value.cpp index 98e045955..242fc6aee 100644 --- a/src/list_value.cpp +++ b/src/list_value.cpp @@ -68,8 +68,8 @@ namespace sparrow #if defined(__cpp_lib_format) -auto std::formatter::format(const sparrow::list_value& list_value, std::format_context& ctx) - const -> decltype(ctx.out()) +auto std::formatter::format(const sparrow::list_value& list_value, std::format_context& ctx) const + -> decltype(ctx.out()) { std::format_to(ctx.out(), "<"); if (!list_value.empty()) diff --git a/src/struct_value.cpp b/src/struct_value.cpp index 7d4150554..353b021a0 100644 --- a/src/struct_value.cpp +++ b/src/struct_value.cpp @@ -15,7 +15,6 @@ #include "sparrow/layout/array_helper.hpp" #include "sparrow/layout/nested_value_types.hpp" - namespace sparrow { struct_value::struct_value(const std::vector& children, size_type index) @@ -64,8 +63,8 @@ namespace sparrow #if defined(__cpp_lib_format) -auto std::formatter::format(const sparrow::struct_value& ar, std::format_context& ctx) - const -> decltype(ctx.out()) +auto std::formatter::format(const sparrow::struct_value& ar, std::format_context& ctx) const + -> decltype(ctx.out()) { std::format_to(ctx.out(), "<"); if (!ar.empty()) diff --git a/test/better_junit_reporter.hpp b/test/better_junit_reporter.hpp index 038c8ed5c..3a9ceee26 100644 --- a/test/better_junit_reporter.hpp +++ b/test/better_junit_reporter.hpp @@ -309,6 +309,8 @@ void JUnitReporter::log_message(const doctest::MessageData& mb) ); } -void JUnitReporter::test_case_skipped(const doctest::TestCaseData&) {} +void JUnitReporter::test_case_skipped(const doctest::TestCaseData&) +{ +} DOCTEST_REGISTER_REPORTER("better_junit", 0, JUnitReporter); diff --git a/test/external_array_data_creation.cpp b/test/external_array_data_creation.cpp index 205c17810..64a0f4f86 100644 --- a/test/external_array_data_creation.cpp +++ b/test/external_array_data_creation.cpp @@ -89,12 +89,12 @@ namespace sparrow::test sparrow::buffer make_size_buffer(const std::vector& sizes, bool big) { - const auto buf_size = sizes.size() * (big ? sizeof(std::uint64_t) : sizeof(std::uint32_t)); + const auto buf_size = sizes.size() * (big ? sizeof(std::uint64_t) : sizeof(std::uint32_t)); std::uint8_t* buf = new std::uint8_t[buf_size]; - if(big) + if (big) { std::uint64_t* size_buf = reinterpret_cast(buf); - for(std::size_t i = 0; i < sizes.size(); ++i) + for (std::size_t i = 0; i < sizes.size(); ++i) { size_buf[i] = sizes[i]; } @@ -102,7 +102,7 @@ namespace sparrow::test else { std::uint32_t* size_buf = reinterpret_cast(buf); - for(std::size_t i = 0; i < sizes.size(); ++i) + for (std::size_t i = 0; i < sizes.size(); ++i) { size_buf[i] = static_cast(sizes[i]); } @@ -115,10 +115,11 @@ namespace sparrow::test ArrowArray& arr, ArrowSchema&& flat_value_schema, ArrowArray&& flat_value_arr, - const std::vector & list_lengths, - const std::vector & false_positions, + const std::vector& list_lengths, + const std::vector& false_positions, bool big_list - ){ + ) + { ArrowSchema** schema_children = new ArrowSchema*[1]; schema_children[0] = new ArrowSchema(std::move(flat_value_schema)); sparrow::fill_arrow_schema( @@ -133,12 +134,11 @@ namespace sparrow::test ); using buffer_type = sparrow::buffer; - std::vector arr_buffs = - { + std::vector arr_buffs = { sparrow::test::make_bitmap_buffer(list_lengths.size(), false_positions), make_offset_buffer_from_sizes(list_lengths, big_list) }; - + ArrowArray** array_children = new ArrowArray*[1]; array_children[0] = new ArrowArray(std::move(flat_value_arr)); sparrow::fill_arrow_array( @@ -158,9 +158,10 @@ namespace sparrow::test ArrowArray& arr, ArrowSchema&& flat_value_schema, ArrowArray&& flat_value_arr, - const std::vector & false_positions, + const std::vector& false_positions, std::size_t list_size - ){ + ) + { SPARROW_ASSERT(list_size > 0, "list size must be greater than 0"); SPARROW_ASSERT(list_size < 10, "just a test limitation st. format string can be on stack"); // convert list size to string @@ -180,11 +181,8 @@ namespace sparrow::test std::size_t arr_size = static_cast(flat_value_arr.length) / list_size; using buffer_type = sparrow::buffer; - std::vector arr_buffs = - { - sparrow::test::make_bitmap_buffer(arr_size, false_positions) - }; - + std::vector arr_buffs = {sparrow::test::make_bitmap_buffer(arr_size, false_positions)}; + ArrowArray** array_children = new ArrowArray*[1]; array_children[0] = new ArrowArray(std::move(flat_value_arr)); sparrow::fill_arrow_array( @@ -199,16 +197,16 @@ namespace sparrow::test ); } - void fill_schema_and_array_for_list_view_layout( ArrowSchema& schema, ArrowArray& arr, ArrowSchema&& flat_value_schema, ArrowArray&& flat_value_arr, - const std::vector & list_lengths, - const std::vector & false_positions, + const std::vector& list_lengths, + const std::vector& false_positions, bool big_list - ){ + ) + { ArrowSchema** schema_children = new ArrowSchema*[1]; schema_children[0] = new ArrowSchema(std::move(flat_value_schema)); sparrow::fill_arrow_schema( @@ -223,13 +221,12 @@ namespace sparrow::test ); using buffer_type = sparrow::buffer; - std::vector arr_buffs = - { + std::vector arr_buffs = { sparrow::test::make_bitmap_buffer(list_lengths.size(), false_positions), make_offset_buffer_from_sizes(list_lengths, big_list), make_size_buffer(list_lengths, big_list) }; - + ArrowArray** array_children = new ArrowArray*[1]; array_children[0] = new ArrowArray(std::move(flat_value_arr)); sparrow::fill_arrow_array( @@ -249,14 +246,19 @@ namespace sparrow::test ArrowArray& arr, std::vector&& children_schemas, std::vector&& children_arrays, - const std::vector & false_positions + const std::vector& false_positions ) { ArrowSchema** schema_children = new ArrowSchema*[children_schemas.size()]; - std::transform(std::make_move_iterator(children_schemas.begin()), - std::make_move_iterator(children_schemas.end()), - schema_children, - [](auto&& child) { return new ArrowSchema(std::move(child)); }); + std::transform( + std::make_move_iterator(children_schemas.begin()), + std::make_move_iterator(children_schemas.end()), + schema_children, + [](auto&& child) + { + return new ArrowSchema(std::move(child)); + } + ); sparrow::fill_arrow_schema( schema, std::string_view("+s"), @@ -268,19 +270,23 @@ namespace sparrow::test nullptr ); - + int64_t length = children_arrays.front().length; using buffer_type = sparrow::buffer; - std::vector arr_buffs = - { + std::vector arr_buffs = { sparrow::test::make_bitmap_buffer(static_cast(length), false_positions), }; ArrowArray** array_children = new ArrowArray*[children_arrays.size()]; - std::transform(std::make_move_iterator(children_arrays.begin()), - std::make_move_iterator(children_arrays.end()), - array_children, - [](auto&& child) { return new ArrowArray(std::move(child)); }); + std::transform( + std::make_move_iterator(children_arrays.begin()), + std::make_move_iterator(children_arrays.end()), + array_children, + [](auto&& child) + { + return new ArrowArray(std::move(child)); + } + ); sparrow::fill_arrow_array( arr, length, @@ -300,12 +306,18 @@ namespace sparrow::test std::vector&& children_arrays, const std::vector& type_ids, const std::string& format - ){ + ) + { ArrowSchema** schema_children = new ArrowSchema*[children_schemas.size()]; - std::transform(std::make_move_iterator(children_schemas.begin()), - std::make_move_iterator(children_schemas.end()), - schema_children, - [](auto&& child) { return new ArrowSchema(std::move(child)); }); + std::transform( + std::make_move_iterator(children_schemas.begin()), + std::make_move_iterator(children_schemas.end()), + schema_children, + [](auto&& child) + { + return new ArrowSchema(std::move(child)); + } + ); sparrow::fill_arrow_schema( schema, format, @@ -320,13 +332,18 @@ namespace sparrow::test using buffer_type = sparrow::buffer; buffer_type buf(type_ids.size()); std::copy(type_ids.begin(), type_ids.end(), buf.begin()); - std::vector arr_buffs = { std::move(buf) }; - + std::vector arr_buffs = {std::move(buf)}; + ArrowArray** array_children = new ArrowArray*[children_arrays.size()]; - std::transform(std::make_move_iterator(children_arrays.begin()), - std::make_move_iterator(children_arrays.end()), - array_children, - [](auto&& child) { return new ArrowArray(std::move(child)); }); + std::transform( + std::make_move_iterator(children_arrays.begin()), + std::make_move_iterator(children_arrays.end()), + array_children, + [](auto&& child) + { + return new ArrowArray(std::move(child)); + } + ); sparrow::fill_arrow_array( arr, @@ -345,15 +362,21 @@ namespace sparrow::test ArrowArray& arr, std::vector&& children_schemas, std::vector&& children_arrays, - const std::vector & type_ids, - const std::vector & offsets, - const std::string & format - ){ + const std::vector& type_ids, + const std::vector& offsets, + const std::string& format + ) + { ArrowSchema** schema_children = new ArrowSchema*[children_schemas.size()]; - std::transform(std::make_move_iterator(children_schemas.begin()), - std::make_move_iterator(children_schemas.end()), - schema_children, - [](auto&& child) { return new ArrowSchema(std::move(child)); }); + std::transform( + std::make_move_iterator(children_schemas.begin()), + std::make_move_iterator(children_schemas.end()), + schema_children, + [](auto&& child) + { + return new ArrowSchema(std::move(child)); + } + ); sparrow::fill_arrow_schema( schema, format, @@ -369,17 +392,22 @@ namespace sparrow::test buffer_type buf0(type_ids.size()); std::copy(type_ids.begin(), type_ids.end(), buf0.begin()); - + buffer_type buf1(offsets.size() * sizeof(std::int32_t)); std::copy(offsets.begin(), offsets.end(), buf1.data()); - - std::vector arr_buffs ={ std::move(buf0), std::move(buf1) }; - + + std::vector arr_buffs = {std::move(buf0), std::move(buf1)}; + ArrowArray** array_children = new ArrowArray*[children_arrays.size()]; - std::transform(std::make_move_iterator(children_arrays.begin()), - std::make_move_iterator(children_arrays.end()), - array_children, - [](auto&& child) { return new ArrowArray(std::move(child)); }); + std::transform( + std::make_move_iterator(children_arrays.begin()), + std::make_move_iterator(children_arrays.end()), + array_children, + [](auto&& child) + { + return new ArrowArray(std::move(child)); + } + ); sparrow::fill_arrow_array( arr, diff --git a/test/external_array_data_creation.hpp b/test/external_array_data_creation.hpp index 44987c933..b1e5f334e 100644 --- a/test/external_array_data_creation.hpp +++ b/test/external_array_data_creation.hpp @@ -24,7 +24,6 @@ #include "sparrow/types/data_traits.hpp" #include "sparrow/types/data_type.hpp" - namespace sparrow::test { void release_external_arrow_schema(ArrowSchema* schema); @@ -251,22 +250,22 @@ namespace sparrow::test res[0] = {byte_t(0), byte_t(1)}; for (size_t i = 1; i < n; ++i) { - std::byte b0 = res[i-1][1]; - auto b1 = static_cast(int(res[i-1][0]) + int(res[i-1][1])); + std::byte b0 = res[i - 1][1]; + auto b1 = static_cast(int(res[i - 1][0]) + int(res[i - 1][1])); if (i % 3 == 0) { res[i] = {b0, b1}; } else { - auto b2 = static_cast(int(res[i-1][0]) - int(res[i-1][1])); + auto b2 = static_cast(int(res[i - 1][0]) - int(res[i - 1][1])); if (i % 2 == 0) { res[i] = {b0, b1, b2}; } else { - std::byte b3 = res[i-1][0]; + std::byte b3 = res[i - 1][0]; res[i] = {b0, b1, b2, b3}; } } @@ -321,13 +320,12 @@ namespace sparrow::test } } - std::vector arr_buffs = - { + std::vector arr_buffs = { sparrow::test::make_bitmap_buffer(size, false_bitmap), std::move(offset_buf), std::move(value_buf) }; - + sparrow::fill_arrow_array( arr, static_cast(size - offset), diff --git a/test/junit_xml_writer.hpp b/test/junit_xml_writer.hpp index 8ec1439b0..2796f9333 100644 --- a/test/junit_xml_writer.hpp +++ b/test/junit_xml_writer.hpp @@ -66,7 +66,7 @@ namespace sparrow { m_xml_writer.writeAttribute("type", message.m_type); } - if(message.m_line != 0) + if (message.m_line != 0) { m_xml_writer.writeAttribute("line", message.m_line); } @@ -180,7 +180,7 @@ namespace sparrow .writeAttribute("assertions", test_suites.assertions_count()) .writeAttribute("time", test_suites.total_time()); - for (const auto& [_ , test_suite] : test_suites.m_test_suites) + for (const auto& [_, test_suite] : test_suites.m_test_suites) { write(test_suite); } diff --git a/test/test_array_wrapper.cpp b/test/test_array_wrapper.cpp index d260caa27..8b956a4dd 100644 --- a/test/test_array_wrapper.cpp +++ b/test/test_array_wrapper.cpp @@ -16,15 +16,14 @@ #include "sparrow/layout/null_array.hpp" #include "sparrow/layout/primitive_array.hpp" -#include "external_array_data_creation.hpp" - #include "doctest/doctest.h" +#include "external_array_data_creation.hpp" namespace sparrow { using test::make_arrow_proxy; using testing_types = std::tuple< - null_array, + null_array, primitive_array, primitive_array, primitive_array, @@ -35,8 +34,7 @@ namespace sparrow primitive_array, primitive_array, primitive_array, - primitive_array - >; + primitive_array>; TEST_SUITE("array_wrapper") { @@ -138,4 +136,4 @@ namespace sparrow } TEST_CASE_TEMPLATE_APPLY(array_wrapper_clone, testing_types); } -} +} diff --git a/test/test_binary_array.cpp b/test/test_binary_array.cpp index 345abd019..bb204ab9d 100644 --- a/test/test_binary_array.cpp +++ b/test/test_binary_array.cpp @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include + #include "sparrow/arrow_array_schema_proxy.hpp" #include "sparrow/c_interface.hpp" #include "sparrow/layout/variable_size_binary_layout/variable_size_binary_array.hpp" @@ -21,9 +24,6 @@ #include "doctest/doctest.h" #include "test_utils.hpp" -#include -#include - namespace sparrow { struct binary_array_fixture @@ -47,8 +47,7 @@ namespace sparrow static_assert(is_binary_array_v); static_assert(std::same_as); - static_assert(std::same_as>); + static_assert(std::same_as>); static_assert(std::same_as); using const_value_iterator = layout_type::const_value_iterator; static_assert(std::same_as); @@ -84,16 +83,11 @@ namespace sparrow std::vector word0 = {byte_t(0), byte_t(1)}; std::vector word1 = {byte_t(2)}; std::vector word4 = {byte_t(8), byte_t(9), byte_t(10)}; - std::vector> words{ - word0, - word1, - {byte_t(3), byte_t(4), byte_t(5)}, - {byte_t(6), byte_t(7)}, - word4 - }; - std::vector where_nulls{2,3}; + std::vector> + words{word0, word1, {byte_t(3), byte_t(4), byte_t(5)}, {byte_t(6), byte_t(7)}, word4}; + std::vector where_nulls{2, 3}; const binary_array array(words, std::move(where_nulls)); - + REQUIRE_EQ(array.size(), words.size()); // check nulls @@ -107,7 +101,7 @@ namespace sparrow CHECK_EQ(array[0].value(), word0); CHECK_EQ(array[1].value(), word1); CHECK_EQ(array[4].value(), word4); - } + } } TEST_CASE_FIXTURE(binary_array_fixture, "constructor") @@ -155,7 +149,7 @@ namespace sparrow TEST_CASE_FIXTURE(binary_array_fixture, "operator[]") { std::vector> words = test::make_testing_bytes(m_length); - + SUBCASE("const") { const layout_type array(std::move(m_arrow_proxy)); @@ -167,24 +161,24 @@ namespace sparrow REQUIRE_FALSE(cref1.has_value()); const auto cref2 = array[2]; REQUIRE(cref2.has_value()); - CHECK_EQ(cref2.get(), words[m_offset+2]); + CHECK_EQ(cref2.get(), words[m_offset + 2]); const auto cref3 = array[3]; REQUIRE(cref3.has_value()); - CHECK_EQ(cref3.get(), words[m_offset+3]); + CHECK_EQ(cref3.get(), words[m_offset + 3]); const auto cref4 = array[4]; REQUIRE_FALSE(cref4.has_value()); const auto cref5 = array[5]; REQUIRE(cref5.has_value()); - CHECK_EQ(cref5.get(), words[m_offset+5]); + CHECK_EQ(cref5.get(), words[m_offset + 5]); const auto cref6 = array[6]; REQUIRE(cref6.has_value()); - CHECK_EQ(cref6.get(), words[m_offset+6]); + CHECK_EQ(cref6.get(), words[m_offset + 6]); const auto cref7 = array[7]; REQUIRE(cref7.has_value()); - CHECK_EQ(cref7.get(), words[m_offset+7]); + CHECK_EQ(cref7.get(), words[m_offset + 7]); const auto cref8 = array[8]; REQUIRE(cref8.has_value()); - CHECK_EQ(cref8.get(), words[m_offset+8]); + CHECK_EQ(cref8.get(), words[m_offset + 8]); } SUBCASE("mutable") @@ -198,37 +192,37 @@ namespace sparrow REQUIRE_FALSE(ref1.has_value()); auto ref2 = array[2]; REQUIRE(ref2.has_value()); - CHECK_EQ(ref2.get(), words[m_offset+2]); + CHECK_EQ(ref2.get(), words[m_offset + 2]); auto ref3 = array[3]; REQUIRE(ref3.has_value()); - CHECK_EQ(ref3.get(), words[m_offset+3]); + CHECK_EQ(ref3.get(), words[m_offset + 3]); auto ref4 = array[4]; REQUIRE_FALSE(ref4.has_value()); auto ref5 = array[5]; REQUIRE(ref5.has_value()); - CHECK_EQ(ref5.get(), words[m_offset+5]); + CHECK_EQ(ref5.get(), words[m_offset + 5]); auto ref6 = array[6]; REQUIRE(ref6.has_value()); - CHECK_EQ(ref6.get(), words[m_offset+6]); + CHECK_EQ(ref6.get(), words[m_offset + 6]); auto ref7 = array[7]; REQUIRE(ref7.has_value()); - CHECK_EQ(ref7.get(), words[m_offset+7]); + CHECK_EQ(ref7.get(), words[m_offset + 7]); auto ref8 = array[8]; REQUIRE(ref8.has_value()); - CHECK_EQ(ref8.get(), words[m_offset+8]); + CHECK_EQ(ref8.get(), words[m_offset + 8]); using bytes_type = std::vector; bytes_type word61 = {byte_t(14), byte_t(15)}; array[6] = make_nullable(bytes_type(word61)); CHECK_EQ(ref6.get(), word61); - CHECK_EQ(ref7.get(), words[m_offset+7]); - CHECK_EQ(ref8.get(), words[m_offset+8]); + CHECK_EQ(ref7.get(), words[m_offset + 7]); + CHECK_EQ(ref8.get(), words[m_offset + 8]); bytes_type word62 = {byte_t(17)}; array[6] = make_nullable(bytes_type(word62)); CHECK_EQ(ref6.get(), word62); - CHECK_EQ(ref7.get(), words[m_offset+7]); - CHECK_EQ(ref8.get(), words[m_offset+8]); + CHECK_EQ(ref7.get(), words[m_offset + 7]); + CHECK_EQ(ref8.get(), words[m_offset + 8]); } } @@ -420,4 +414,3 @@ namespace sparrow #endif } } - diff --git a/test/test_buffer_adaptor.cpp b/test/test_buffer_adaptor.cpp index d7763377e..2472c53e6 100644 --- a/test/test_buffer_adaptor.cpp +++ b/test/test_buffer_adaptor.cpp @@ -23,7 +23,8 @@ #include "doctest/doctest.h" -constexpr uint8_t operator""_u8(unsigned long long int value) { +constexpr uint8_t operator""_u8(unsigned long long int value) +{ return static_cast(value); } diff --git a/test/test_builder.cpp b/test/test_builder.cpp index da255407d..fc7f5aab7 100644 --- a/test/test_builder.cpp +++ b/test/test_builder.cpp @@ -12,29 +12,28 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "sparrow/builder/builder.hpp" -#include "test_utils.hpp" - -#include +#include #include #include -#include +#include +#include "sparrow/builder/builder.hpp" + +#include "test_utils.hpp" namespace sparrow { // to keep everything very short for very deep nested types - template + template using nt = nullable; TEST_SUITE("builder") { - TEST_CASE("primitive-layout") { // arr[float] SUBCASE("float") - { + { std::vector v{1.0, 2.0, 3.0}; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -45,7 +44,7 @@ namespace sparrow } // arr[double] (with nulls) SUBCASE("float-with-nulls") - { + { std::vector> v{1.0, 2.0, sparrow::nullval, 3.0}; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -58,15 +57,14 @@ namespace sparrow CHECK_EQ(arr[0].value(), 1.0); CHECK_EQ(arr[1].value(), 2.0); CHECK_EQ(arr[3].value(), 3.0); - } } - + TEST_CASE("list-layout") { // list[float] SUBCASE("list[float]") - { + { std::vector> v{{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f}}; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -75,18 +73,17 @@ namespace sparrow REQUIRE_EQ(arr[0].value().size(), 3); REQUIRE_EQ(arr[1].value().size(), 2); - CHECK_NULLABLE_VARIANT_EQ(arr[0].value()[0], 1.0f); - CHECK_NULLABLE_VARIANT_EQ(arr[0].value()[1], 2.0f); - CHECK_NULLABLE_VARIANT_EQ(arr[0].value()[2], 3.0f); - CHECK_NULLABLE_VARIANT_EQ(arr[1].value()[0], 4.0f); - CHECK_NULLABLE_VARIANT_EQ(arr[1].value()[1], 5.0f); + CHECK_NULLABLE_VARIANT_EQ(arr[0].value()[0], 1.0f); + CHECK_NULLABLE_VARIANT_EQ(arr[0].value()[1], 2.0f); + CHECK_NULLABLE_VARIANT_EQ(arr[0].value()[2], 3.0f); + CHECK_NULLABLE_VARIANT_EQ(arr[1].value()[0], 4.0f); + CHECK_NULLABLE_VARIANT_EQ(arr[1].value()[1], 5.0f); // check that the children are **NOT** dict-encoded REQUIRE(!arr.raw_flat_array()->is_dictionary()); - } SUBCASE("list[list[float]]") - { + { std::vector>> v{ {{1.2f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f}}, {{7.0f, 8.0f, 9.0f}, {10.0f, 11.0f, 12.0f}} @@ -96,7 +93,7 @@ namespace sparrow REQUIRE_EQ(arr.size(), 2); } SUBCASE("options") - { + { SUBCASE("with_large_list_flag") { std::vector> v{{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f}}; @@ -112,25 +109,20 @@ namespace sparrow using array_type = std::decay_t; static_assert(std::is_same_v); } - } } - + TEST_CASE("struct-layout") { // struct - { - std::vector> v{ - {1.5f, 2}, - {3.5f, 4}, - {5.5f, 6} - }; + { + std::vector> v{{1.5f, 2}, {3.5f, 4}, {5.5f, 6}}; auto arr = sparrow::build(v); test::generic_consistency_test(arr); REQUIRE_EQ(arr.size(), 3); } // struct (with nulls) - { + { std::vector>> v{ std::tuple{1.5f, 2}, sparrow::nullval, @@ -141,8 +133,8 @@ namespace sparrow REQUIRE_EQ(arr.size(), 3); } // struct - { - std::vector,std::uint16_t>> v{ + { + std::vector, std::uint16_t>> v{ {{1.0f, 2.0f, 3.0f}, 1}, {{4.0f, 5.0f, 6.0f}, 2}, {{7.0f, 8.0f, 9.0f}, 3} @@ -152,22 +144,18 @@ namespace sparrow REQUIRE_EQ(arr.size(), 3); } } - + TEST_CASE("fixed-sized-list-layout") { // fixed_sized_list - { - std::vector> v{ - {1.0f, 2.0f, 3.0f}, - {4.0f, 5.0f, 6.0f}, - {7.0f, 8.0f, 9.0f} - }; + { + std::vector> v{{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f}, {7.0f, 8.0f, 9.0f}}; auto arr = sparrow::build(v); test::generic_consistency_test(arr); REQUIRE_EQ(arr.size(), 3); } // fixed_sized_list with nulls - { + { std::vector, 3>>> v{ std::array, 3>{1.0f, sparrow::nullval, 3.0f}, sparrow::nullval, @@ -175,14 +163,13 @@ namespace sparrow }; auto arr = sparrow::build(v); test::generic_consistency_test(arr); - } } - + TEST_CASE("variable-sized-binary") { // variable_size_binary - { + { std::vector v{ "hello", " ", @@ -196,15 +183,10 @@ namespace sparrow CHECK_EQ(arr[1].value(), " "); CHECK_EQ(arr[2].value(), "world"); CHECK_EQ(arr[3].value(), "!"); - } // variable_size_binary with nulls - { - std::vector> v{ - "hello", - sparrow::nullval, - "world!" - }; + { + std::vector> v{"hello", sparrow::nullval, "world!"}; auto arr = sparrow::build(v); test::generic_consistency_test(arr); REQUIRE_EQ(arr.size(), 3); @@ -214,20 +196,15 @@ namespace sparrow CHECK_EQ(arr[0].value(), "hello"); CHECK_EQ(arr[2].value(), "world!"); - } } - + TEST_CASE("sparse-union") { SUBCASE("simple") - { + { using variant_type = std::variant; - std::vector v{ - 1, - 2.0f, - "hello" - }; + std::vector v{1, 2.0f, "hello"}; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -243,4 +220,3 @@ namespace sparrow } } - diff --git a/test/test_builder_dict_encoded.cpp b/test/test_builder_dict_encoded.cpp index f1f6114b0..4371aed7f 100644 --- a/test/test_builder_dict_encoded.cpp +++ b/test/test_builder_dict_encoded.cpp @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "sparrow/builder/builder.hpp" -#include "test_utils.hpp" - -#include +#include #include #include -#include +#include +#include "sparrow/builder/builder.hpp" + +#include "test_utils.hpp" namespace sparrow { @@ -28,13 +28,11 @@ namespace sparrow { TEST_CASE("dict-encoded") { - SUBCASE("dict[int]") + SUBCASE("dict[int]") { SUBCASE("no-nulls") { - dict_encode> v{ - std::vector{1, 1, 1, 2} - }; + dict_encode> v{std::vector{1, 1, 1, 2}}; auto arr = sparrow::build(v); test::generic_consistency_test(arr); using array_type = std::decay_t; @@ -50,10 +48,8 @@ namespace sparrow SUBCASE("with-nulls") { dict_encode>> v{ - std::vector>{ - 1, 1, sparrow::nullval, 2 - } - }; + std::vector>{1, 1, sparrow::nullval, 2} + }; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -68,7 +64,6 @@ namespace sparrow } SUBCASE("dict[string]") { - dict_encode>> v{ std::vector>{"hello", "world", "hello", "world", nullable{}} }; @@ -83,22 +78,20 @@ namespace sparrow CHECK_NULLABLE_VARIANT_EQ(arr[2], std::string_view("hello")); CHECK_NULLABLE_VARIANT_EQ(arr[3], std::string_view("world")); CHECK(!arr[4].has_value()); - } SUBCASE("dict[struct[int,float]]") - { + { using tuple_type = std::tuple, std::uint16_t>; using nullable_tuple_type = nullable; using vector_type = std::vector; - dict_encode v{ - vector_type{ - nullable_tuple_type{tuple_type{nullable{1}, std::uint16_t(1)}}, - nullable_tuple_type{}, - nullable_tuple_type{tuple_type{nullable{}, std::uint16_t(42)}}, - nullable_tuple_type{tuple_type{nullable{}, std::uint16_t(42)}} - } - + dict_encode v{vector_type{ + nullable_tuple_type{tuple_type{nullable{1}, std::uint16_t(1)}}, + nullable_tuple_type{}, + nullable_tuple_type{tuple_type{nullable{}, std::uint16_t(42)}}, + nullable_tuple_type{tuple_type{nullable{}, std::uint16_t(42)}} + } + }; auto arr = sparrow::build(v); @@ -107,7 +100,7 @@ namespace sparrow static_assert(std::is_same_v>); REQUIRE_EQ(arr.size(), 4); - + // 0 auto arr0 = std::get>(arr[0]); REQUIRE(arr0.has_value()); @@ -129,15 +122,10 @@ namespace sparrow REQUIRE(arr3.has_value()); CHECK(!arr3.value()[0].has_value()); CHECK_NULLABLE_VARIANT_EQ(arr3.value()[1], std::uint16_t(42)); - } SUBCASE("dict[list[int]]") { - dict_encode>> v{ - std::vector>{ - {1, 2, 3}, - {4, 5, 6} - } + dict_encode>> v{std::vector>{{1, 2, 3}, {4, 5, 6}} }; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -148,8 +136,8 @@ namespace sparrow CHECK_EQ(std::get>(arr[0]).value().size(), 3); CHECK_NULLABLE_VARIANT_EQ(std::get>(arr[0]).value()[0], 1); CHECK_NULLABLE_VARIANT_EQ(std::get>(arr[0]).value()[1], 2); - CHECK_NULLABLE_VARIANT_EQ(std::get>(arr[0]).value()[2], 3); - } + CHECK_NULLABLE_VARIANT_EQ(std::get>(arr[0]).value()[2], 3); + } SUBCASE("dict[union[int, string]]") { dict_encode>> v{ @@ -177,15 +165,9 @@ namespace sparrow SUBCASE("without-nulls") { std::vector>> v{ - dict_encode>{ - std::vector{1, 2, 3} - }, - dict_encode>{ - std::vector{4, 5} - }, - dict_encode>{ - std::vector{6} - } + dict_encode>{std::vector{1, 2, 3}}, + dict_encode>{std::vector{4, 5}}, + dict_encode>{std::vector{6}} }; auto arr = sparrow::build(v); @@ -196,12 +178,12 @@ namespace sparrow // ensure that the child is dict-encoded REQUIRE(arr.raw_flat_array()->is_dictionary()); - for(std::size_t i = 0; i < 3; ++i) + for (std::size_t i = 0; i < 3; ++i) { auto arr_val = arr[i]; REQUIRE(arr_val.has_value()); REQUIRE_EQ(arr_val.value().size(), v[i].get().size()); - for(std::size_t j = 0; j < v[i].get().size(); ++j) + for (std::size_t j = 0; j < v[i].get().size(); ++j) { CHECK_NULLABLE_VARIANT_EQ(arr_val.value()[j], v[i].get()[j]); } @@ -210,16 +192,10 @@ namespace sparrow SUBCASE("with-nulls") { std::vector>>>> v{ - dict_encode>>{ - std::vector>{1, 2, 3} - }, + dict_encode>>{std::vector>{1, 2, 3}}, sparrow::nullval, - dict_encode>>{ - std::vector>{6} - }, - dict_encode>>{ - std::vector>{nullable{}} - }, + dict_encode>>{std::vector>{6}}, + dict_encode>>{std::vector>{nullable{}}}, }; auto arr = sparrow::build(v); @@ -251,15 +227,11 @@ namespace sparrow SUBCASE("without-nulls") { std::vector>> v{ - dict_encode>{ - std::array{"one", "two", "three"} + dict_encode>{std::array{"one", "two", "three"} }, - dict_encode>{ - std::array{"one", "two", "three"} + dict_encode>{std::array{"one", "two", "three"} }, - dict_encode>{ - std::array{"one", "two", "four"} - } + dict_encode>{std::array{"one", "two", "four"}} }; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -269,27 +241,24 @@ namespace sparrow // ensure that the child is dict-encoded REQUIRE(arr.raw_flat_array()->is_dictionary()); - for(std::size_t i = 0; i < 3; ++i) + for (std::size_t i = 0; i < 3; ++i) { auto arr_val = arr[i]; REQUIRE(arr_val.has_value()); REQUIRE_EQ(arr_val.value().size(), 3); - for(std::size_t j = 0; j < 3; ++j) + for (std::size_t j = 0; j < 3; ++j) { CHECK_NULLABLE_VARIANT_EQ(arr_val.value()[j], std::string_view(v[i].get()[j])); } } } SUBCASE("with-nulls") - { + { std::vector>>> v{ - dict_encode>{ - std::array{"one", "two", "three"} + dict_encode>{std::array{"one", "two", "three"} }, sparrow::nullval, - dict_encode>{ - std::array{"one", "two", "three"} - } + dict_encode>{std::array{"one", "two", "three"}} }; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -302,25 +271,25 @@ namespace sparrow REQUIRE(arr[0].has_value()); REQUIRE_FALSE(arr[1].has_value()); REQUIRE(arr[2].has_value()); - } - } + } + } SUBCASE("struct[dict[string], int]") - { + { SUBCASE("with-nulls") { - std::vector>,int>>> v - { + std::vector>, int>>> v{ std::tuple>, int>{ - dict_encode>{"hello"}, 1 + dict_encode>{"hello"}, + 1 }, nullable>, int>>{}, std::tuple>, int>{ - dict_encode>{"!"}, 3 + dict_encode>{"!"}, + 3 }, std::tuple>, int>{ - dict_encode>{ - nullable{} - }, 4 + dict_encode>{nullable{}}, + 4 } }; auto arr = sparrow::build(v); @@ -345,22 +314,17 @@ namespace sparrow REQUIRE(arr[3].has_value()); CHECK_NULLABLE_VARIANT_EQ(arr[3].value()[1], int(4)); REQUIRE_FALSE(arr[3].value()[0].has_value()); - } } SUBCASE("union[[dict[string], int]]") { SUBCASE("without-nulls") - { + { using variant_type = std::variant, int>; std::vector v{ - variant_type{ - dict_encode{"hello"} - }, - variant_type{ - int(42) - }, + variant_type{dict_encode{"hello"}}, + variant_type{int(42)}, }; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -372,11 +336,8 @@ namespace sparrow CHECK_NULLABLE_VARIANT_EQ(arr[1], int(42)); } SUBCASE("with-nulls") - { - using variant_type = std::variant< - dict_encode>, - nullable - >; + { + using variant_type = std::variant>, nullable>; std::vector v{ variant_type{nullable{"hello"}}, variant_type{nullable{}}, @@ -393,10 +354,8 @@ namespace sparrow CHECK(!arr[1].has_value()); CHECK(!arr[2].has_value()); - } } } } } - diff --git a/test/test_builder_run_end_encoded.cpp b/test/test_builder_run_end_encoded.cpp index d57970fe8..955a7253d 100644 --- a/test/test_builder_run_end_encoded.cpp +++ b/test/test_builder_run_end_encoded.cpp @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "sparrow/builder/builder.hpp" -#include "test_utils.hpp" - -#include +#include #include #include -#include +#include +#include "sparrow/builder/builder.hpp" + +#include "test_utils.hpp" namespace sparrow { @@ -27,13 +27,11 @@ namespace sparrow { TEST_CASE("run-end-encoded") { - SUBCASE("run_end_encode[int]") + SUBCASE("run_end_encode[int]") { SUBCASE("no-nulls") { - run_end_encode> v{ - std::vector{1, 1, 1, 2} - }; + run_end_encode> v{std::vector{1, 1, 1, 2}}; auto arr = sparrow::build(v); test::generic_consistency_test(arr); using array_type = std::decay_t; @@ -49,10 +47,8 @@ namespace sparrow SUBCASE("with-nulls") { run_end_encode>> v{ - std::vector>{ - 1, 1, sparrow::nullval, 2 - } - }; + std::vector>{1, 1, sparrow::nullval, 2} + }; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -65,10 +61,9 @@ namespace sparrow CHECK_NULLABLE_VARIANT_EQ(arr[3], 2); } } - + SUBCASE("run_end_encode[string]") { - run_end_encode>> v{ std::vector>{"hello", "world", "hello", "world", nullable{}} }; @@ -83,24 +78,22 @@ namespace sparrow CHECK_NULLABLE_VARIANT_EQ(arr[2], std::string_view("hello")); CHECK_NULLABLE_VARIANT_EQ(arr[3], std::string_view("world")); CHECK(!arr[4].has_value()); - } - + SUBCASE("run_end_encode[struct[int,float]]") - { + { using tuple_type = std::tuple, std::uint16_t>; using nullable_tuple_type = nullable; using vector_type = std::vector; - run_end_encode v{ - vector_type{ - nullable_tuple_type{tuple_type{nullable{1}, std::uint16_t(1)}}, - nullable_tuple_type{}, - nullable_tuple_type{tuple_type{nullable{}, std::uint16_t(42)}}, - nullable_tuple_type{tuple_type{nullable{}, std::uint16_t(42)}} - } - + run_end_encode v{vector_type{ + nullable_tuple_type{tuple_type{nullable{1}, std::uint16_t(1)}}, + nullable_tuple_type{}, + nullable_tuple_type{tuple_type{nullable{}, std::uint16_t(42)}}, + nullable_tuple_type{tuple_type{nullable{}, std::uint16_t(42)}} + } + }; auto arr = sparrow::build(v); @@ -110,7 +103,7 @@ namespace sparrow REQUIRE_EQ(arr.size(), 4); - + // 0 auto arr0 = std::get>(arr[0]); REQUIRE(arr0.has_value()); @@ -132,15 +125,11 @@ namespace sparrow REQUIRE(arr3.has_value()); CHECK(!arr3.value()[0].has_value()); CHECK_NULLABLE_VARIANT_EQ(arr3.value()[1], std::uint16_t(42)); - } - SUBCASE("run_end_encode[list[int]]") + SUBCASE("run_end_encode[list[int]]") { run_end_encode>> v{ - std::vector>{ - {1, 2, 3}, - {4, 5, 6} - } + std::vector>{{1, 2, 3}, {4, 5, 6}} }; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -183,15 +172,9 @@ namespace sparrow SUBCASE("without-nulls") { std::vector>> v{ - run_end_encode>{ - std::vector{1, 2, 3} - }, - run_end_encode>{ - std::vector{4, 5} - }, - run_end_encode>{ - std::vector{6} - } + run_end_encode>{std::vector{1, 2, 3}}, + run_end_encode>{std::vector{4, 5}}, + run_end_encode>{std::vector{6}} }; auto arr = sparrow::build(v); @@ -202,12 +185,12 @@ namespace sparrow // ensure that the child is run_end_encoded REQUIRE(arr.raw_flat_array()->data_type() == data_type::RUN_ENCODED); - for(std::size_t i = 0; i < 3; ++i) + for (std::size_t i = 0; i < 3; ++i) { auto arr_val = arr[i]; REQUIRE(arr_val.has_value()); REQUIRE_EQ(arr_val.value().size(), v[i].get().size()); - for(std::size_t j = 0; j < v[i].get().size(); ++j) + for (std::size_t j = 0; j < v[i].get().size(); ++j) { CHECK_NULLABLE_VARIANT_EQ(arr_val.value()[j], v[i].get()[j]); } @@ -215,18 +198,11 @@ namespace sparrow } SUBCASE("with-nulls") { - std::vector>>>> v{ - run_end_encode>>{ - std::vector>{1, 2, 3} - }, + run_end_encode>>{std::vector>{1, 2, 3}}, sparrow::nullval, - run_end_encode>>{ - std::vector>{6} - }, - run_end_encode>>{ - std::vector>{nullable{}} - }, + run_end_encode>>{std::vector>{6}}, + run_end_encode>>{std::vector>{nullable{}}}, }; auto arr = sparrow::build(v); @@ -262,9 +238,7 @@ namespace sparrow run_end_encode>{ std::array{"one", "two", "three"} }, - run_end_encode>{ - std::array{"one", "two", "four"} - } + run_end_encode>{std::array{"one", "two", "four"}} }; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -275,12 +249,12 @@ namespace sparrow // ensure that the child is run_end_encoded REQUIRE(arr.raw_flat_array()->data_type() == data_type::RUN_ENCODED); - for(std::size_t i = 0; i < 3; ++i) + for (std::size_t i = 0; i < 3; ++i) { auto arr_val = arr[i]; REQUIRE(arr_val.has_value()); REQUIRE_EQ(arr_val.value().size(), 3); - for(std::size_t j = 0; j < 3; ++j) + for (std::size_t j = 0; j < 3; ++j) { CHECK_NULLABLE_VARIANT_EQ(arr_val.value()[j], std::string_view(v[i].get()[j])); } @@ -309,25 +283,25 @@ namespace sparrow REQUIRE(arr[0].has_value()); REQUIRE_FALSE(arr[1].has_value()); REQUIRE(arr[2].has_value()); - } - } + } + } SUBCASE("struct[run_end_encode[string], int]") - { + { SUBCASE("with-nulls") { - std::vector>,int>>> v - { + std::vector>, int>>> v{ std::tuple>, int>{ - run_end_encode>{"hello"}, 1 + run_end_encode>{"hello"}, + 1 }, nullable>, int>>{}, std::tuple>, int>{ - run_end_encode>{"!"}, 3 + run_end_encode>{"!"}, + 3 }, std::tuple>, int>{ - run_end_encode>{ - nullable{} - }, 4 + run_end_encode>{nullable{}}, + 4 } }; auto arr = sparrow::build(v); @@ -351,21 +325,16 @@ namespace sparrow REQUIRE(arr[3].has_value()); CHECK_NULLABLE_VARIANT_EQ(arr[3].value()[1], int(4)); REQUIRE_FALSE(arr[3].value()[0].has_value()); - } } SUBCASE("union[[run_end_encode[string], int]]") { SUBCASE("without-nulls") - { + { using variant_type = std::variant, int>; std::vector v{ - variant_type{ - run_end_encode{"hello"} - }, - variant_type{ - int(42) - }, + variant_type{run_end_encode{"hello"}}, + variant_type{int(42)}, }; auto arr = sparrow::build(v); test::generic_consistency_test(arr); @@ -377,11 +346,8 @@ namespace sparrow CHECK_NULLABLE_VARIANT_EQ(arr[1], int(42)); } SUBCASE("with-nulls") - { - using variant_type = std::variant< - run_end_encode>, - nullable - >; + { + using variant_type = std::variant>, nullable>; std::vector v{ variant_type{nullable{"hello"}}, @@ -398,10 +364,9 @@ namespace sparrow CHECK_NULLABLE_VARIANT_EQ(arr[0], std::string_view("hello")); CHECK(!arr[1].has_value()); - CHECK(!arr[2].has_value()); + CHECK(!arr[2].has_value()); } } } } } - diff --git a/test/test_builder_utils.cpp b/test/test_builder_utils.cpp index fc97976b9..120e55e93 100644 --- a/test/test_builder_utils.cpp +++ b/test/test_builder_utils.cpp @@ -12,105 +12,120 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "sparrow/builder/builder_utils.hpp" -#include "test_utils.hpp" - -#include +#include #include #include -#include +#include + +#include "sparrow/builder/builder_utils.hpp" + +#include "test_utils.hpp" namespace sparrow -{ +{ class my_variant : public std::variant { public: + using std::variant::variant; }; } -template +template struct std::variant_alternative { using type = std::variant_alternative_t>; }; -namespace sparrow{ +namespace sparrow +{ TEST_SUITE("builder-utils") - { + { TEST_CASE("for_each_index") { SUBCASE("empty") { // the return type of for_each_index indicates if the loop was run to completion - detail::for_each_index<0>([](auto i) - { - // should not be called - CHECK_FALSE(decltype(i)::value, 0); - CHECK(false); - return true; // should not be called - }); + detail::for_each_index<0>( + [](auto i) + { + // should not be called + CHECK_FALSE(decltype(i)::value, 0); + CHECK(false); + return true; // should not be called + } + ); } SUBCASE("non-empty") { int c = 0; - detail::for_each_index<3>([&](auto i) - { - CHECK_EQ(decltype(i)::value, c); - ++c; - return true; - }); + detail::for_each_index<3>( + [&](auto i) + { + CHECK_EQ(decltype(i)::value, c); + ++c; + return true; + } + ); CHECK_EQ(c, 3); } } TEST_CASE("exitable_for_each_index") - { + { SUBCASE("empty") { // the return type of exitable_for_each_index indicates if the loop was run to completion - CHECK(detail::exitable_for_each_index<0>([](auto i) - { - // should not be called - CHECK_FALSE(decltype(i)::value, 0); - CHECK(false); - return true; // should not be called - })); + CHECK(detail::exitable_for_each_index<0>( + [](auto i) + { + // should not be called + CHECK_FALSE(decltype(i)::value, 0); + CHECK(false); + return true; // should not be called + } + )); } SUBCASE("exit right away") { // the return type of exitable_for_each_index indicates if the loop was run to completion - CHECK_FALSE(detail::exitable_for_each_index<3>([](auto i) - { - // exit right away - CHECK(decltype(i)::value == 0); - return false; - })); + CHECK_FALSE(detail::exitable_for_each_index<3>( + [](auto i) + { + // exit right away + CHECK(decltype(i)::value == 0); + return false; + } + )); } - + SUBCASE("full") { - int c=0; - CHECK(detail::exitable_for_each_index<3>([&](auto i) - { - // run to completion - CHECK_EQ(decltype(i)::value, c); - ++c; - return true; - })); + int c = 0; + CHECK(detail::exitable_for_each_index<3>( + [&](auto i) + { + // run to completion + CHECK_EQ(decltype(i)::value, c); + ++c; + return true; + } + )); CHECK_EQ(c, 3); } SUBCASE("half") { int c = 0; - CHECK_FALSE(detail::exitable_for_each_index<4>([&](auto i) - { - CHECK_EQ(decltype(i)::value, c); - ++c; - return decltype(i)::value < 2; - })); + CHECK_FALSE(detail::exitable_for_each_index<4>( + [&](auto i) + { + CHECK_EQ(decltype(i)::value, c); + ++c; + return decltype(i)::value < 2; + } + )); CHECK_EQ(c, 3); } } @@ -134,7 +149,7 @@ namespace sparrow{ // is tuple_like static_assert(detail::tuple_like>); - static_assert(detail::tuple_like>); + static_assert(detail::tuple_like>); static_assert(detail::tuple_like>); static_assert(detail::tuple_like>); static_assert(detail::tuple_like>); @@ -164,15 +179,19 @@ namespace sparrow{ static_assert(std::is_same_v>, int>); static_assert(std::is_same_v, int>); static_assert(std::is_same_v>, nullable>); - static_assert(std::is_same_v>> , nullable>>); + static_assert(std::is_same_v>>, nullable>>); // layout_flag_t static_assert(std::is_same_v, detail::dont_enforce_layout>); static_assert(std::is_same_v>, detail::enforce_run_end_encoded_layout>); - static_assert(std::is_same_v>>, detail::enforce_run_end_encoded_layout>); + static_assert(std::is_same_v< + detail::layout_flag_t>>, + detail::enforce_run_end_encoded_layout>); static_assert(std::is_same_v>, detail::enforce_dict_encoded_layout>); - static_assert(std::is_same_v>>, detail::enforce_dict_encoded_layout>); - + static_assert(std::is_same_v< + detail::layout_flag_t>>, + detail::enforce_dict_encoded_layout>); + // look trough static_assert(std::is_same_v>>, std::vector>>); static_assert(std::is_same_v>>, std::vector>); @@ -180,8 +199,7 @@ namespace sparrow{ static_assert(std::is_same_v>>, nullable>); static_assert(std::is_same_v>>, std::vector>); static_assert(std::is_same_v>>, int>); - - } + } TEST_CASE("get_size_save") { CHECK_EQ(detail::get_size_save(std::vector{1, 2, 3}), 3); @@ -197,7 +215,7 @@ namespace sparrow{ CHECK_EQ(detail::ensure_value(dict_encode{1}), 1); CHECK_EQ(detail::ensure_value(run_end_encode{1}), 1); CHECK_EQ(detail::ensure_value(nullable>{dict_encode{1}}), 1); - } + } TEST_CASE("where-null") { SUBCASE("vector-of-nullables") @@ -210,8 +228,8 @@ namespace sparrow{ SUBCASE("vector-of-scalar") { std::vector v{1, 2, 3, 4}; - std::array res = detail::where_null(v); - CHECK_EQ(res.size(), 0); // pointless but uses the return value + std::array res = detail::where_null(v); + CHECK_EQ(res.size(), 0); // pointless but uses the return value } SUBCASE("vector-of-nullabels-dict-encode") { @@ -228,9 +246,9 @@ namespace sparrow{ SUBCASE("vector-of-nullabels-dict-encode") { std::vector>> v{ - dict_encode>{nullable{int(1)}}, - dict_encode>{nullable{}}, - dict_encode>{nullable{int(2)}}, + dict_encode>{nullable{int(1)}}, + dict_encode>{nullable{}}, + dict_encode>{nullable{int(2)}}, dict_encode>{nullable{int(3)}} }; std::vector res = detail::where_null(v); @@ -240,4 +258,3 @@ namespace sparrow{ } } } - diff --git a/test/test_decimal_array.cpp b/test/test_decimal_array.cpp index de231cfca..32deb68b9 100644 --- a/test/test_decimal_array.cpp +++ b/test/test_decimal_array.cpp @@ -20,7 +20,6 @@ #include "test_utils.hpp" - namespace sparrow { diff --git a/test/test_dispatch.cpp b/test/test_dispatch.cpp index 1859fab2f..ecc5efd24 100644 --- a/test/test_dispatch.cpp +++ b/test/test_dispatch.cpp @@ -16,15 +16,14 @@ #include "sparrow/layout/array_helper.hpp" #include "sparrow/layout/dispatch.hpp" -#include "doctest/doctest.h" - #include "../test/external_array_data_creation.hpp" +#include "doctest/doctest.h" namespace sparrow { using test::make_arrow_proxy; using testing_types = std::tuple< - null_array, + null_array, primitive_array, primitive_array, primitive_array, @@ -35,9 +34,8 @@ namespace sparrow primitive_array, primitive_array, primitive_array, - primitive_array - >; - + primitive_array>; + TEST_SUITE("dispatch") { TEST_CASE_TEMPLATE_DEFINE("array_size", AR, array_size_id) diff --git a/test/test_high_level_constructors.cpp b/test/test_high_level_constructors.cpp index 9be78c808..63c29c7eb 100644 --- a/test/test_high_level_constructors.cpp +++ b/test/test_high_level_constructors.cpp @@ -13,25 +13,32 @@ // limitations under the License. -#include "sparrow/layout/primitive_array.hpp" -#include "sparrow/layout/list_layout/list_array.hpp" +#include + #include "sparrow/array.hpp" +#include "sparrow/layout/list_layout/list_array.hpp" +#include "sparrow/layout/primitive_array.hpp" + #include "doctest/doctest.h" #include "test_utils.hpp" -#include - namespace sparrow { TEST_SUITE("high_level_constructors") { TEST_CASE("list") - { + { // a primite array std::size_t flat_size = 10; - primitive_array primitive_arr(std::ranges::iota_view{std::size_t(0), std::size_t(10)} | std::views::transform([](auto i){ - return static_cast(i);}) + primitive_array primitive_arr( + std::ranges::iota_view{std::size_t(0), std::size_t(10)} + | std::views::transform( + [](auto i) + { + return static_cast(i); + } + ) ); // wrap into an detyped array @@ -49,34 +56,36 @@ namespace sparrow REQUIRE_EQ(size, n); auto flat_i = 0; - for(std::size_t i = 0; i < size; ++i) + for (std::size_t i = 0; i < size; ++i) { auto list = list_arr[i].value(); CHECK_EQ(list.size(), list_size); - for(std::size_t j = 0; j < list.size(); ++j) + for (std::size_t j = 0; j < list.size(); ++j) { auto opt_val_variant = list[j]; - std::visit([&](auto&& opt_val){ - using nullable_type = std::decay_t; - using inner_type = std::decay_t; - if constexpr(std::is_same_v) - { - REQUIRE(opt_val.has_value()); - CHECK_EQ(opt_val.value(), static_cast(flat_i)); - } - else + std::visit( + [&](auto&& opt_val) { - REQUIRE(false); - } - }, opt_val_variant); + using nullable_type = std::decay_t; + using inner_type = std::decay_t; + if constexpr (std::is_same_v) + { + REQUIRE(opt_val.has_value()); + CHECK_EQ(opt_val.value(), static_cast(flat_i)); + } + else + { + REQUIRE(false); + } + }, + opt_val_variant + ); ++flat_i; } - } } } - -} +} diff --git a/test/test_list_array.cpp b/test/test_list_array.cpp index 1e5f14941..37878190a 100644 --- a/test/test_list_array.cpp +++ b/test/test_list_array.cpp @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "sparrow/array.hpp" #include "sparrow/layout/list_layout/list_array.hpp" #include "sparrow/layout/primitive_array.hpp" #include "doctest/doctest.h" #include "external_array_data_creation.hpp" #include "test_utils.hpp" -#include "sparrow/array.hpp" namespace sparrow { @@ -30,12 +30,20 @@ namespace sparrow // first we create a flat array of integers ArrowArray flat_arr{}; ArrowSchema flat_schema{}; - test::fill_schema_and_array(flat_schema, flat_arr, n_flat, 0/*offset*/, {}); + test::fill_schema_and_array(flat_schema, flat_arr, n_flat, 0 /*offset*/, {}); flat_schema.name = "the flat array"; ArrowArray arr{}; ArrowSchema schema{}; - test::fill_schema_and_array_for_list_layout(schema, arr, std::move(flat_schema), std::move(flat_arr), sizes, {}, 0); + test::fill_schema_and_array_for_list_layout( + schema, + arr, + std::move(flat_schema), + std::move(flat_arr), + sizes, + {}, + 0 + ); return arrow_proxy(std::move(arr), std::move(schema)); } } @@ -57,8 +65,14 @@ namespace sparrow std::size_t n_flat = 11; // 2+2+3+4 // create flat array of integers - primitive_array flat_arr(std::ranges::iota_view{std::size_t(0), std::size_t(n_flat)} | std::views::transform([](auto i){ - return static_cast(i);}) + primitive_array flat_arr( + std::ranges::iota_view{std::size_t(0), std::size_t(n_flat)} + | std::views::transform( + [](auto i) + { + return static_cast(i); + } + ) ); // wrap into an detyped array @@ -69,19 +83,19 @@ namespace sparrow // check the size REQUIRE_EQ(list_arr.size(), sizes.size()); - + // check the sizes - for(std::size_t i = 0; i < sizes.size(); ++i) + for (std::size_t i = 0; i < sizes.size(); ++i) { CHECK_EQ(list_arr[i].value().size(), sizes[i]); } // check the values std::int16_t flat_index = 0; - for(std::size_t i = 0; i < sizes.size(); ++i) + for (std::size_t i = 0; i < sizes.size(); ++i) { auto list = list_arr[i].value(); - for(std::size_t j = 0; j < sizes[i]; ++j) + for (std::size_t j = 0; j < sizes[i]; ++j) { CHECK_NULLABLE_VARIANT_EQ(list[j], flat_index); ++flat_index; @@ -148,14 +162,14 @@ namespace sparrow for (std::size_t j = 0; j < sizes[i]; ++j) { auto value_variant = list[j]; - CHECK_NULLABLE_VARIANT_EQ(value_variant, static_cast(flat_index)); + CHECK_NULLABLE_VARIANT_EQ(value_variant, static_cast(flat_index)); ++flat_index; } } } SUBCASE("consistency") - { + { test::generic_consistency_test(list_arr); } @@ -174,14 +188,19 @@ namespace sparrow // check that flat values are "iota" if constexpr (std::is_integral_v) { - for(inner_scalar_type i = 0; i < static_cast(n_flat); ++i){ + for (inner_scalar_type i = 0; i < static_cast(n_flat); ++i) + { CHECK(flat_values_casted[static_cast(i)].value() == i); } } else { - for(inner_scalar_type i = 0; i < static_cast(n_flat); ++i){ - CHECK(flat_values_casted[static_cast(i)].value() == doctest::Approx(static_cast(i))); + for (inner_scalar_type i = 0; i < static_cast(n_flat); ++i) + { + CHECK( + flat_values_casted[static_cast(i)].value() + == doctest::Approx(static_cast(i)) + ); } } } @@ -196,12 +215,20 @@ namespace sparrow // first we create a flat array of integers ArrowArray flat_arr{}; ArrowSchema flat_schema{}; - test::fill_schema_and_array(flat_schema, flat_arr, n_flat, 0/*offset*/, {}); + test::fill_schema_and_array(flat_schema, flat_arr, n_flat, 0 /*offset*/, {}); flat_schema.name = "the flat array"; ArrowArray arr{}; ArrowSchema schema{}; - test::fill_schema_and_array_for_list_view_layout(schema, arr, std::move(flat_schema), std::move(flat_arr), sizes, {}, 0); + test::fill_schema_and_array_for_list_view_layout( + schema, + arr, + std::move(flat_schema), + std::move(flat_arr), + sizes, + {}, + 0 + ); return arrow_proxy(std::move(arr), std::move(schema)); } } @@ -216,20 +243,26 @@ namespace sparrow TEST_CASE("constructors") { - // flat data is [0,1,2,3,4] + // flat data is [0,1,2,3,4] std::size_t n_flat = 5; // create flat array of integers - primitive_array flat_arr(std::ranges::iota_view{std::size_t(0), std::size_t(n_flat)} | std::views::transform([](auto i){ - return static_cast(i);}) + primitive_array flat_arr( + std::ranges::iota_view{std::size_t(0), std::size_t(n_flat)} + | std::views::transform( + [](auto i) + { + return static_cast(i); + } + ) ); // the desired goal array is // [[3,4],[2,3],NAN, [0,1,2]] // vector of sizes - std::vector sizes = {2, 2,0, 3}; - std::vector offsets = {3, 2,0,0}; + std::vector sizes = {2, 2, 0, 3}; + std::vector offsets = {3, 2, 0, 0}; std::vector where_missing = {2}; @@ -255,7 +288,6 @@ namespace sparrow CHECK_EQ(list_view_arr[3].value().size(), sizes[3]); - // check the values CHECK_NULLABLE_VARIANT_EQ(list_view_arr[0].value()[0], std::int16_t(3)); CHECK_NULLABLE_VARIANT_EQ(list_view_arr[0].value()[1], std::int16_t(4)); @@ -281,7 +313,7 @@ namespace sparrow const std::size_t n_flat2 = 8; std::vector sizes2 = {2, 4, 2}; - + arrow_proxy proxy = test::make_list_view_proxy(n_flat, sizes); // create a list array @@ -336,7 +368,7 @@ namespace sparrow } SUBCASE("consistency") - { + { test::generic_consistency_test(list_arr); } @@ -355,14 +387,19 @@ namespace sparrow // check that flat values are "iota" if constexpr (std::is_integral_v) { - for(inner_scalar_type i = 0; i < static_cast(n_flat); ++i){ + for (inner_scalar_type i = 0; i < static_cast(n_flat); ++i) + { CHECK(flat_values_casted[static_cast(i)].value() == i); } } else { - for(inner_scalar_type i = 0; i < static_cast(n_flat); ++i){ - CHECK(flat_values_casted[static_cast(i)].value() == doctest::Approx(static_cast(i))); + for (inner_scalar_type i = 0; i < static_cast(n_flat); ++i) + { + CHECK( + flat_values_casted[static_cast(i)].value() + == doctest::Approx(static_cast(i)) + ); } } } @@ -377,12 +414,19 @@ namespace sparrow // first we create a flat array of integers ArrowArray flat_arr{}; ArrowSchema flat_schema{}; - test::fill_schema_and_array(flat_schema, flat_arr, n_flat, 0/*offset*/, {}); + test::fill_schema_and_array(flat_schema, flat_arr, n_flat, 0 /*offset*/, {}); flat_schema.name = "the flat array"; ArrowArray arr{}; ArrowSchema schema{}; - test::fill_schema_and_array_for_fixed_size_list_layout(schema, arr, std::move(flat_schema), std::move(flat_arr), {}, list_size); + test::fill_schema_and_array_for_fixed_size_list_layout( + schema, + arr, + std::move(flat_schema), + std::move(flat_arr), + {}, + list_size + ); return arrow_proxy(std::move(arr), std::move(schema)); } } @@ -410,7 +454,7 @@ namespace sparrow const std::size_t n_flat2 = 10; const std::size_t list_size2 = 4; - + arrow_proxy proxy = test::make_fixed_sized_list_proxy(n_flat, list_size); fixed_sized_list_array list_arr(std::move(proxy)); @@ -438,7 +482,7 @@ namespace sparrow } SUBCASE("consistency") - { + { test::generic_consistency_test(list_arr); } REQUIRE(list_arr.size() == n); diff --git a/test/test_list_value.cpp b/test/test_list_value.cpp index e2e8e10db..564b9606f 100644 --- a/test/test_list_value.cpp +++ b/test/test_list_value.cpp @@ -19,7 +19,6 @@ #include "../test/external_array_data_creation.hpp" #include "doctest/doctest.h" - namespace sparrow { using scalar_value_type = std::int32_t; diff --git a/test/test_memory.cpp b/test/test_memory.cpp index 0d459a819..52bc83f31 100644 --- a/test/test_memory.cpp +++ b/test/test_memory.cpp @@ -197,7 +197,10 @@ namespace sparrow::cloning_test return std::unique_ptr{new mock_derived(*this)}; } - static int instance_count() { return m_instance_count; } + static int instance_count() + { + return m_instance_count; + } private: @@ -416,7 +419,7 @@ namespace sparrow auto d2 = new mock_derived(); cloning_ptr p1(d1); cloning_ptr p2(d2); - + SUBCASE("method") { p1.swap(p2); @@ -474,7 +477,7 @@ namespace sparrow CHECK(p1 != nullptr); CHECK(p4 == nullptr); } - + SUBCASE("ordering") { CHECK(p1 <= p1); diff --git a/test/test_nested_comperators.cpp b/test/test_nested_comperators.cpp index 9bfddea0e..4049659cd 100644 --- a/test/test_nested_comperators.cpp +++ b/test/test_nested_comperators.cpp @@ -12,22 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "sparrow/builder/builder_utils.hpp" -#include "sparrow/builder/nested_less.hpp" -#include "sparrow/builder/nested_eq.hpp" -#include "test_utils.hpp" - -#include +#include #include #include -#include +#include +#include "sparrow/builder/builder_utils.hpp" +#include "sparrow/builder/nested_eq.hpp" +#include "sparrow/builder/nested_less.hpp" + +#include "test_utils.hpp" namespace sparrow -{ +{ TEST_SUITE("nested-less") - { + { TEST_CASE("nullable-less") { using type = nullable; @@ -42,20 +42,17 @@ namespace sparrow CHECK_FALSE(less_type{}(type{1}, type{1})); } TEST_CASE("tuple") - { - + { { using tuple_type = std::tuple; using less_type = detail::nested_less; CHECK(less_type{}(tuple_type{0}, tuple_type{1})); } { - using tuple_type = std::tuple; + using tuple_type = std::tuple; using less_type = detail::nested_less; CHECK(less_type{}(tuple_type{0, 2}, tuple_type{1, 0})); } - - } TEST_CASE("very-nested-less") { @@ -79,9 +76,10 @@ namespace sparrow CHECK_FALSE(less_type{}(c, a)); CHECK_FALSE(less_type{}(c, c)); } - } + } + TEST_SUITE("nested-eq") - { + { TEST_CASE("nullable-eq") { using type = nullable; @@ -96,8 +94,7 @@ namespace sparrow CHECK_FALSE(eq_type{}(type{1}, type{2})); } TEST_CASE("tuple") - { - + { { using tuple_type = std::tuple; using eq_type = detail::nested_eq; @@ -107,15 +104,13 @@ namespace sparrow CHECK_FALSE(eq_type{}(tuple_type{0}, tuple_type{1})); } { - using tuple_type = std::tuple; + using tuple_type = std::tuple; using eq_type = detail::nested_eq; CHECK(eq_type{}(tuple_type{0, 0}, tuple_type{0, 0})); CHECK_FALSE(eq_type{}(tuple_type{0, 1}, tuple_type{1, 0})); CHECK_FALSE(eq_type{}(tuple_type{1, 0}, tuple_type{1, 1})); CHECK(eq_type{}(tuple_type{1, 1}, tuple_type{1, 1})); } - - } TEST_CASE("very-nested-eq") { @@ -141,4 +136,3 @@ namespace sparrow } } } - diff --git a/test/test_null_array.cpp b/test/test_null_array.cpp index 496a23896..09ec385e7 100644 --- a/test/test_null_array.cpp +++ b/test/test_null_array.cpp @@ -17,7 +17,6 @@ #include "../test/external_array_data_creation.hpp" #include "doctest/doctest.h" - namespace sparrow { using test::make_arrow_proxy; diff --git a/test/test_record_batch.cpp b/test/test_record_batch.cpp index c6d91750d..db646e048 100644 --- a/test/test_record_batch.cpp +++ b/test/test_record_batch.cpp @@ -19,7 +19,6 @@ #include "doctest/doctest.h" - namespace sparrow { std::vector make_array_list(const std::size_t data_size) diff --git a/test/test_string_array.cpp b/test/test_string_array.cpp index 9d61f34c6..043110db1 100644 --- a/test/test_string_array.cpp +++ b/test/test_string_array.cpp @@ -77,7 +77,7 @@ namespace sparrow CHECK_EQ(array.name(), "name"); CHECK_EQ(array.metadata(), "metadata"); - + REQUIRE_EQ(array.size(), words.size()); // check nulls @@ -929,7 +929,7 @@ namespace sparrow } } } - + #if defined(__cpp_lib_format) TEST_CASE_FIXTURE(string_array_fixture, "formatting") { diff --git a/test/test_struct_array.cpp b/test/test_struct_array.cpp index ade473f49..4fcdbbc8b 100644 --- a/test/test_struct_array.cpp +++ b/test/test_struct_array.cpp @@ -54,7 +54,7 @@ namespace sparrow } TEST_SUITE("struct_array") - { + { static_assert(is_struc_array_v); TEST_CASE("constructors") diff --git a/test/test_traits.cpp b/test/test_traits.cpp index 85ae54553..7bcd14cd1 100644 --- a/test/test_traits.cpp +++ b/test/test_traits.cpp @@ -15,7 +15,6 @@ #include #include - ///////////////////////////////////////////////////////////////////////////////////////// // Opt-in support for custom C++ representations of arrow data types. @@ -42,15 +41,21 @@ namespace sparrow static_assert(mpl::all_of(all_base_types_t{}, predicate::has_arrow_traits)); -// Native basic standard types support + // Native basic standard types support using basic_native_types = mpl::typelist< bool, - char, unsigned char, signed char, - short, unsigned short, - int, unsigned int, - long, unsigned long, // `long long` could be bigger than 64bits and is not supported - float, double, // `long double` could be bigger than 64bit and is not supported + char, + unsigned char, + signed char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, // `long long` could be bigger than 64bits and is not supported + float, + double, // `long double` could be bigger than 64bit and is not supported std::uint8_t, std::int8_t, std::uint16_t, @@ -61,12 +66,10 @@ namespace sparrow std::int64_t, float16_t, float32_t, - float64_t - >; + float64_t>; template - consteval - bool is_possible_arrow_data_type(data_type type_id) + consteval bool is_possible_arrow_data_type(data_type type_id) { // NOTE: // `char` is not specified by the C and C++ standard to be `signed` or `unsigned`. @@ -121,8 +124,7 @@ namespace sparrow } template - consteval - bool is_possible_arrow_data_type(data_type type_id) + consteval bool is_possible_arrow_data_type(data_type type_id) { switch (type_id) { @@ -142,8 +144,7 @@ namespace sparrow { template requires has_arrow_type_traits - consteval - bool operator()(mpl::typelist) + consteval bool operator()(mpl::typelist) { constexpr auto deduced_type_id = data_type_from_size(); static_assert(deduced_type_id == arrow_traits::type_id); diff --git a/test/test_utils.cpp b/test/test_utils.cpp index 63a685758..8f4a08704 100644 --- a/test/test_utils.cpp +++ b/test/test_utils.cpp @@ -2,4 +2,4 @@ namespace sparrow { -} // namespace sparrow \ No newline at end of file +} // namespace sparrow \ No newline at end of file diff --git a/test/test_utils.hpp b/test/test_utils.hpp index ba433a1c2..361dae903 100644 --- a/test/test_utils.hpp +++ b/test/test_utils.hpp @@ -1,25 +1,29 @@ #pragma once -#include "doctest/doctest.h" +#include -#include "sparrow/utils/nullable.hpp" #include "sparrow/array.hpp" -#include +#include "sparrow/utils/nullable.hpp" + +#include "doctest/doctest.h" namespace sparrow::test { - template - void generic_consistency_test_impl(ARRAY_TYPE && typed_arr){ + template + void generic_consistency_test_impl(ARRAY_TYPE&& typed_arr) + { using array_type = std::decay_t; const auto size = typed_arr.size(); // check that iterators sizes are consistent - SUBCASE("iterators"){ + SUBCASE("iterators") + { auto it = typed_arr.begin(); auto it_end = typed_arr.end(); CHECK(std::distance(it, it_end) == size); } - SUBCASE("const iterators"){ + SUBCASE("const iterators") + { auto it = typed_arr.cbegin(); auto it_end = typed_arr.cend(); CHECK(std::distance(it, it_end) == size); @@ -32,64 +36,73 @@ namespace sparrow::test sparrow::array arr(std::move(arr_copy)); // detyped visit - arr.visit([&](auto && v) { - using typed_array_type = std::decay_t; - CHECK(std::is_same_v); - if constexpr(std::is_same_v) + arr.visit( + [&](auto&& v) { - CHECK(v == typed_arr); + using typed_array_type = std::decay_t; + CHECK(std::is_same_v); + if constexpr (std::is_same_v) + { + CHECK(v == typed_arr); + } } - }); - + ); } } - template - void generic_consistency_test(ARRAY_TYPE & array){ - - // array as array + template + void generic_consistency_test(ARRAY_TYPE& array) + { + // array as array generic_consistency_test_impl(array); - // const array - const auto & const_array = array; + // const array + const auto& const_array = array; generic_consistency_test_impl(const_array); } +// ensure that the variant (of nullables) has a value +// and that the value is equal to the expected value +// (including the type) +#define CHECK_NULLABLE_VARIANT_EQ(variant, value) \ + sparrow::test::check_nullable_variant_eq(variant, value, __FILE__, __LINE__) - // ensure that the variant (of nullables) has a value - // and that the value is equal to the expected value - // (including the type) - #define CHECK_NULLABLE_VARIANT_EQ(variant, value) sparrow::test::check_nullable_variant_eq(variant, value, __FILE__, __LINE__) - template - static void check_nullable_variant_eq(const V & variant, const T & value,const char* file, int line) + static void check_nullable_variant_eq(const V& variant, const T& value, const char* file, int line) { - return std::visit([&](auto && v) { - - // v is a nullable - using nullable_type = std::decay_t; - using inner_type = std::decay_t; - - if constexpr(std::is_same_v) + return std::visit( + [&](auto&& v) { - if (v.has_value()) + // v is a nullable + using nullable_type = std::decay_t; + using inner_type = std::decay_t; + + if constexpr (std::is_same_v) { - if(v.value() != value) + if (v.has_value()) + { + if (v.value() != value) + { + ADD_FAIL_AT( + file, + line, + "value mismatch: expected " << value << " but got " << v.value() + ); + } + } + else { - ADD_FAIL_AT(file, line, "value mismatch: expected " << value << " but got " << v.value()); + ADD_FAIL_AT(file, line, "value is null"); } } else { - ADD_FAIL_AT(file, line, "value is null"); + ADD_FAIL_AT(file, line, "type mismatch"); } - } - else - { - ADD_FAIL_AT(file, line, "type mismatch"); - } - }, variant); + }, + variant + ); } - + }; \ No newline at end of file diff --git a/test/test_utils_buffers.cpp b/test/test_utils_buffers.cpp index 0b3a98a2d..a85dbcba1 100644 --- a/test/test_utils_buffers.cpp +++ b/test/test_utils_buffers.cpp @@ -18,7 +18,6 @@ #include "doctest/doctest.h" - namespace sparrow { TEST_SUITE("number_of_bytes") diff --git a/test/test_utils_offsets.cpp b/test/test_utils_offsets.cpp index 78c566fdb..542ffdac5 100644 --- a/test/test_utils_offsets.cpp +++ b/test/test_utils_offsets.cpp @@ -14,9 +14,10 @@ #include -#include "doctest/doctest.h" #include "sparrow/utils/offsets.hpp" +#include "doctest/doctest.h" + namespace sparrow { TEST_SUITE("make_offset_buffer") diff --git a/test/test_variable_size_binary_view_array.cpp b/test/test_variable_size_binary_view_array.cpp index 29c0ceba8..26338aade 100644 --- a/test/test_variable_size_binary_view_array.cpp +++ b/test/test_variable_size_binary_view_array.cpp @@ -11,11 +11,12 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +#include +#include + #include "sparrow/layout/variable_size_binary_view_array.hpp" -#include "test_utils.hpp" -#include -#include +#include "test_utils.hpp" using namespace std::literals; @@ -28,9 +29,9 @@ namespace sparrow std::vector words{ "short", "longer", - "abcdefghijk", // exactly 11 - "abcdefghijkl", // exactly 12 - "123456789101112", // longer than 12, + "abcdefghijk", // exactly 11 + "abcdefghijkl", // exactly 12 + "123456789101112", // longer than 12, "hello world this is a long string" }; @@ -40,9 +41,9 @@ namespace sparrow CHECK_EQ(array.name(), "name"); CHECK_EQ(array.metadata(), "metadata"); - for(std::size_t i = 0; i < words.size(); ++i) + for (std::size_t i = 0; i < words.size(); ++i) { - if(i == 1) + if (i == 1) { CHECK_FALSE(array[i].has_value()); }