From 15728b20307f91cac2eb4709e4d012ce7da40569 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Tue, 17 Dec 2024 10:50:45 +0100 Subject: [PATCH 1/2] precommit-fixes --- .pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 987e5aa1..3e99ab08 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,4 +2,5 @@ repos: - repo: https://github.com/pre-commit/mirrors-clang-format rev: v19.1.5 hooks: - - id: clang-format \ No newline at end of file + - id: clang-format + exclude_types: [javascript, json] \ No newline at end of file From bb20ce720a00afed4c9f989d78aa07fc6d56a21e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:51:21 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/builder_example.cpp | 120 ++- examples/typed_array_high_level.cpp | 17 +- examples/typed_array_low_level.cpp | 5 +- include/sparrow/array.hpp | 2 +- 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 | 4 +- 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 +- .../buffer/dynamic_bitset/dynamic_bitset.hpp | 61 +- .../dynamic_bitset/dynamic_bitset_base.hpp | 17 +- .../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_base.hpp | 16 +- include/sparrow/layout/array_bitmap_base.hpp | 14 +- include/sparrow/layout/array_wrapper.hpp | 47 +- .../layout/dictionary_encoded_array.hpp | 5 +- include/sparrow/layout/dispatch.hpp | 164 ++-- include/sparrow/layout/layout_utils.hpp | 22 +- .../sparrow/layout/list_layout/list_array.hpp | 208 ++--- .../sparrow/layout/list_layout/list_value.hpp | 1 - include/sparrow/layout/nested_value_types.hpp | 2 +- include/sparrow/layout/null_array.hpp | 2 +- .../run_end_encoded_array.hpp | 61 +- .../run_end_encoded_iterator.hpp | 61 +- .../layout/struct_layout/struct_array.hpp | 59 +- .../layout/struct_layout/struct_value.hpp | 3 +- include/sparrow/layout/union_array.hpp | 272 +++---- .../variable_size_binary_array.hpp | 27 +- .../variable_size_binary_iterator.hpp | 4 +- .../variable_size_binary_reference.hpp | 1 - .../variable_size_binary_view_array.hpp | 186 ++--- include/sparrow/record_batch.hpp | 3 +- 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/large_int.hpp | 63 +- include/sparrow/utils/memory.hpp | 93 +-- include/sparrow/utils/mp_utils.hpp | 25 +- include/sparrow/utils/nullable.hpp | 271 +++---- include/sparrow/utils/offsets.hpp | 18 +- include/sparrow/utils/ranges.hpp | 14 +- src/array_factory.cpp | 183 ++--- src/array_helper.cpp | 37 +- src/arrow_array_schema_proxy.cpp | 3 +- src/arrow_interface/arrow_array.cpp | 48 +- src/arrow_interface/arrow_schema.cpp | 1 - src/dummy32bit.cpp | 6 +- src/list_value.cpp | 5 +- src/run_encoded_array.cpp | 86 +-- src/struct_value.cpp | 4 +- test/better_junit_reporter.hpp | 4 +- test/external_array_data_creation.cpp | 154 ++-- test/external_array_data_creation.hpp | 1 - test/junit_xml_writer.hpp | 4 +- test/test_array_wrapper.cpp | 10 +- test/test_arrow_array.cpp | 10 +- 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.cpp | 110 +-- test/test_decimal_array.cpp | 31 +- test/test_dispatch.cpp | 10 +- test/test_high_level_constructors.cpp | 57 +- test/test_list_array.cpp | 106 ++- test/test_list_value.cpp | 14 +- test/test_memory.cpp | 9 +- test/test_nested_comperators.cpp | 38 +- test/test_null_array.cpp | 4 +- test/test_nullable.cpp | 96 ++- test/test_record_batch.cpp | 26 +- test/test_run_end_encoded_array.cpp | 92 ++- test/test_struct_array.cpp | 55 +- test/test_traits.cpp | 31 +- test/test_union_array.cpp | 332 ++++---- 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 +- 97 files changed, 2929 insertions(+), 2790 deletions(-) diff --git a/examples/builder_example.cpp b/examples/builder_example.cpp index 36aebf2d..6406c016 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 57bcf95a..b1256fbd 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 c19e5bd2..2d84725e 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 1766e5cf..58ffe80e 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))) { diff --git a/include/sparrow/array_factory.hpp b/include/sparrow/array_factory.hpp index 4672d9dd..ed4ba700 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 277dcf33..68c65919 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 ce625c84..d6539a57 100644 --- a/include/sparrow/arrow_interface/arrow_array_schema_info_utils.hpp +++ b/include/sparrow/arrow_interface/arrow_array_schema_info_utils.hpp @@ -31,7 +31,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 dd095af1..2af6fa6a 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 67bf60e5..309760bb 100644 --- a/include/sparrow/arrow_interface/arrow_schema.hpp +++ b/include/sparrow/arrow_interface/arrow_schema.hpp @@ -20,7 +20,6 @@ #include "sparrow/config/config.hpp" #include "sparrow/utils/contracts.hpp" - namespace sparrow { /** @@ -65,7 +64,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 a0dc13a4..a965e937 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 a91b47bd..ddcf5354 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 d4d46a84..28ccdecd 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 69535b5f..c06b3493 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 78038abd..70d8251f 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 05470832..aaf8cdbd 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 ef7585ad..98b8f893 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.hpp b/include/sparrow/buffer/dynamic_bitset/dynamic_bitset.hpp index b1dcf204..971e8cf1 100644 --- a/include/sparrow/buffer/dynamic_bitset/dynamic_bitset.hpp +++ b/include/sparrow/buffer/dynamic_bitset/dynamic_bitset.hpp @@ -14,8 +14,8 @@ #pragma once -#include "sparrow/buffer/dynamic_bitset/dynamic_bitset_base.hpp" #include "sparrow/buffer/buffer.hpp" +#include "sparrow/buffer/dynamic_bitset/dynamic_bitset_base.hpp" #include "sparrow/utils/ranges.hpp" namespace sparrow @@ -38,15 +38,16 @@ namespace sparrow using value_type = typename base_type::value_type; using size_type = typename base_type::size_type; - template - requires std::convertible_to, value_type> + template + requires std::convertible_to, value_type> explicit dynamic_bitset(const R& r) : dynamic_bitset(std::ranges::size(r), true) { std::size_t i = 0; - for(auto value : r) + for (auto value : r) { - if(!value){ + if (!value) + { this->set(i, false); } i++; @@ -109,25 +110,24 @@ namespace sparrow { } - using validity_bitmap = dynamic_bitset; - namespace detail { using validity_bitmap = sparrow::validity_bitmap; - inline validity_bitmap ensure_validity_bitmap_impl(std::size_t size, const validity_bitmap & bitmap) + + inline validity_bitmap ensure_validity_bitmap_impl(std::size_t size, const validity_bitmap& bitmap) { - if(bitmap.size() == 0) + if (bitmap.size() == 0) { return validity_bitmap(size, true); } - return bitmap; // copy + return bitmap; // copy } - - inline validity_bitmap ensure_validity_bitmap_impl(std::size_t size, validity_bitmap && bitmap) + + inline validity_bitmap ensure_validity_bitmap_impl(std::size_t size, validity_bitmap&& bitmap) { - if(bitmap.size() == 0) + if (bitmap.size() == 0) { bitmap.resize(size, true); } @@ -136,15 +136,16 @@ namespace sparrow // range of booleans template - requires(std::same_as, bool>) + requires(std::same_as, bool>) validity_bitmap ensure_validity_bitmap_impl(std::size_t size, R&& range) - { + { SPARROW_ASSERT_TRUE(size == range_size(range) || range_size(range) == 0); validity_bitmap bitmap(size, true); std::size_t i = 0; - for(auto value : range) + for (auto value : range) { - if(!value){ + if (!value) + { bitmap.set(i, false); } i++; @@ -154,33 +155,29 @@ namespace sparrow // range of indices / integers (but not booleans) template - requires( - std::unsigned_integral> && - !std::same_as, bool> && - !std::same_as, validity_bitmap> - ) + requires(std::unsigned_integral> && !std::same_as, bool> && !std::same_as, validity_bitmap>) validity_bitmap ensure_validity_bitmap_impl(std::size_t size, R&& range_of_indices) - { + { validity_bitmap bitmap(size, true); - for(auto index : range_of_indices) + for (auto index : range_of_indices) { bitmap.set(index, false); } return bitmap; } - } // namespace detail + } // namespace detail template - concept validity_bitmap_input = - std::same_as || - std::same_as || - (std::ranges::input_range && std::same_as, bool>) || - (std::ranges::input_range && std::unsigned_integral> ); + concept validity_bitmap_input = std::same_as || std::same_as + || (std::ranges::input_range + && std::same_as, bool>) + || (std::ranges::input_range + && std::unsigned_integral>); template validity_bitmap ensure_validity_bitmap(std::size_t size, R&& validity_input) { return detail::ensure_validity_bitmap_impl(size, std::forward(validity_input)); } - -} // namespace sparrow \ No newline at end of file + +} // namespace sparrow \ No newline at end of file diff --git a/include/sparrow/buffer/dynamic_bitset/dynamic_bitset_base.hpp b/include/sparrow/buffer/dynamic_bitset/dynamic_bitset_base.hpp index 074b537f..a5c55746 100644 --- a/include/sparrow/buffer/dynamic_bitset/dynamic_bitset_base.hpp +++ b/include/sparrow/buffer/dynamic_bitset/dynamic_bitset_base.hpp @@ -110,10 +110,11 @@ namespace sparrow } } - static constexpr size_type compute_block_count(size_type bits_count) noexcept; + static constexpr size_type compute_block_count(size_type bits_count) noexcept; - // storage_type is a value_type - storage_type extract_storage() noexcept requires std::same_as + // storage_type is a value_type + storage_type extract_storage() noexcept + requires std::same_as { return std::move(m_buffer); } @@ -208,7 +209,7 @@ namespace sparrow constexpr bool dynamic_bitset_base::test(size_type pos) const { SPARROW_ASSERT_TRUE(pos < size()); - if(data() == nullptr) + if (data() == nullptr) { return true; } @@ -350,7 +351,7 @@ namespace sparrow constexpr auto dynamic_bitset_base::front() const -> const_reference { SPARROW_ASSERT_TRUE(size() >= 1); - if(data() == nullptr) + if (data() == nullptr) { return true; } @@ -370,7 +371,7 @@ namespace sparrow constexpr auto dynamic_bitset_base::back() const -> const_reference { SPARROW_ASSERT_TRUE(size() >= 1); - if(data() == nullptr) + if (data() == nullptr) { return true; } @@ -437,7 +438,7 @@ namespace sparrow requires std::ranges::random_access_range> auto dynamic_bitset_base::count_non_null() const noexcept -> size_type { - if(data() == nullptr) + if (data() == nullptr) { return m_size; } @@ -474,7 +475,7 @@ namespace sparrow requires std::ranges::random_access_range> constexpr void dynamic_bitset_base::zero_unused_bits() { - if(data() == nullptr) + if (data() == nullptr) { return; } diff --git a/include/sparrow/buffer/dynamic_bitset/dynamic_bitset_view.hpp b/include/sparrow/buffer/dynamic_bitset/dynamic_bitset_view.hpp index 56faff72..037fa34b 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 4c3e2f37..6d014b44 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 ff306fa0..7a881a11 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 0fd7c58b..ee659710 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 8bf5fa0a..38fdc6f1 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 b3116ce7..9dc7218e 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 87698e34..6968505b 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 f81e447f..2e7e75b0 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_base.hpp b/include/sparrow/layout/array_base.hpp index 29053b6b..65187883 100644 --- a/include/sparrow/layout/array_base.hpp +++ b/include/sparrow/layout/array_base.hpp @@ -22,9 +22,9 @@ #include "sparrow/arrow_array_schema_proxy.hpp" #include "sparrow/buffer/dynamic_bitset/dynamic_bitset_view.hpp" +#include "sparrow/layout/array_access.hpp" #include "sparrow/layout/layout_iterator.hpp" #include "sparrow/utils/crtp_base.hpp" -#include "sparrow/layout/array_access.hpp" #include "sparrow/utils/iterator.hpp" #include "sparrow/utils/nullable.hpp" @@ -217,8 +217,7 @@ namespace sparrow if (i >= size()) { std::ostringstream oss117; - oss117 << "Index " << i << "is greater or equal to size of array (" - << size() << ")"; + oss117 << "Index " << i << "is greater or equal to size of array (" << size() << ")"; throw std::out_of_range(oss117.str()); } return (*this)[i]; @@ -241,7 +240,7 @@ namespace sparrow /** * Returns a constant reference to the first element in the container. - * Calling `front` on an empty container causes undefined behavior. + * Calling `front` on an empty container causes undefined behavior. */ template auto array_crtp_base::front() const -> const_reference @@ -252,7 +251,7 @@ namespace sparrow /** * Returns a constant reference to the last element in the container. - * Calling `back` on an empty container causes undefined behavior. + * Calling `back` on an empty container causes undefined behavior. */ template auto array_crtp_base::back() const -> const_reference @@ -293,7 +292,7 @@ namespace sparrow /** * Returns a constant iterator to the element following the last - * element of the array. This method ensures that a constant iterator + * element of the array. This method ensures that a constant iterator * is returned, even when called on a non-const array. */ template @@ -323,10 +322,11 @@ namespace sparrow { return crend(); } + /** * Returns a constant reverse iterator to the first element of the * reversed array. It corresponds to the last element of the non- - * reversed array. This method ensures that a constant reverse + * reversed array. This method ensures that a constant reverse * iterator is returned, even when called on a non-const array. */ template @@ -347,7 +347,7 @@ namespace sparrow { return const_reverse_iterator(cbegin()); } - + /** * Returns the validity bitmap of the array (i.e. the "has_value" part of the * nullable elements) as a constant range. diff --git a/include/sparrow/layout/array_bitmap_base.hpp b/include/sparrow/layout/array_bitmap_base.hpp index 38654774..e006dab5 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 ccf8c691..d3f8e377 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/dictionary_encoded_array.hpp b/include/sparrow/layout/dictionary_encoded_array.hpp index c31dbc21..08c7411e 100644 --- a/include/sparrow/layout/dictionary_encoded_array.hpp +++ b/include/sparrow/layout/dictionary_encoded_array.hpp @@ -28,7 +28,6 @@ #include "sparrow/utils/functor_index_iterator.hpp" #include "sparrow/utils/memory.hpp" - namespace sparrow { template @@ -167,8 +166,8 @@ namespace sparrow private: template - static auto - create_proxy(keys_buffer_type&& keys, array&& values, R&& bitmaps = validity_bitmap{}) -> arrow_proxy; + static auto create_proxy(keys_buffer_type&& keys, array&& values, R&& bitmaps = validity_bitmap{}) + -> arrow_proxy; using keys_layout = primitive_array; using values_layout = cloning_ptr; diff --git a/include/sparrow/layout/dispatch.hpp b/include/sparrow/layout/dispatch.hpp index c28fa62c..f84aa4cb 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,90 +39,90 @@ 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::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::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 8dddff6f..ccf3049c 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 d1fda9f9..ac29e0e7 100644 --- a/include/sparrow/layout/list_layout/list_array.hpp +++ b/include/sparrow/layout/list_layout/list_array.hpp @@ -15,11 +15,13 @@ #pragma once #include // for std::stoull -#include +#include +#include "sparrow/array_api.hpp" +#include "sparrow/array_factory.hpp" #include "sparrow/arrow_interface/arrow_array.hpp" #include "sparrow/arrow_interface/arrow_schema.hpp" -#include "sparrow/array_factory.hpp" +#include "sparrow/buffer/dynamic_bitset.hpp" #include "sparrow/layout/array_bitmap_base.hpp" #include "sparrow/layout/array_wrapper.hpp" #include "sparrow/layout/layout_utils.hpp" @@ -29,9 +31,6 @@ #include "sparrow/utils/iterator.hpp" #include "sparrow/utils/memory.hpp" #include "sparrow/utils/nullable.hpp" -#include "sparrow/array_api.hpp" -#include "sparrow/buffer/dynamic_bitset.hpp" -#include "sparrow/layout/layout_utils.hpp" namespace sparrow { @@ -84,49 +83,49 @@ namespace sparrow 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::LIST; } }; - 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_LIST; } }; - template<> + template <> struct get_data_type_from_array { - constexpr static sparrow::data_type get() + static constexpr sparrow::data_type get() { return sparrow::data_type::LIST_VIEW; } }; - 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_LIST_VIEW; } }; - template<> + template <> struct get_data_type_from_array { - constexpr static sparrow::data_type get() + static constexpr sparrow::data_type get() { return sparrow::data_type::FIXED_SIZED_LIST; } @@ -183,7 +182,7 @@ namespace sparrow // - big-list-array // - list-view-array // - big-list-view-array - // - fixed-size-list-array + // - fixed-size-list-array template class list_array_crtp_base : public array_bitmap_base { @@ -261,7 +260,7 @@ namespace sparrow using list_size_type = inner_types::list_size_type; using size_type = typename base_type::size_type; using offset_type = std::conditional_t; - using offset_buffer_type = u8_buffer>; + using offset_buffer_type = u8_buffer>; explicit list_array_impl(arrow_proxy proxy); @@ -271,18 +270,24 @@ namespace sparrow list_array_impl(self_type&&) = default; list_array_impl& operator=(self_type&&) = default; - template - requires(mpl::excludes_copy_and_move_ctor_v, ARGS...>) - explicit list_array_impl(ARGS && ... args): self_type(create_proxy(std::forward(args)...)) - {} + template + requires(mpl::excludes_copy_and_move_ctor_v, ARGS...>) + explicit list_array_impl(ARGS&&... args) + : self_type(create_proxy(std::forward(args)...)) + { + } - template - static auto offset_from_sizes(SIZES_RANGE && sizes) -> offset_buffer_type; + template + static auto offset_from_sizes(SIZES_RANGE&& sizes) -> offset_buffer_type; private: - template - static arrow_proxy create_proxy(array && flat_values, offset_buffer_type && list_offsets,VB && validity_input = validity_bitmap{}); + template + static arrow_proxy create_proxy( + array&& flat_values, + offset_buffer_type&& list_offsets, + VB&& validity_input = validity_bitmap{} + ); static constexpr std::size_t OFFSET_BUFFER_INDEX = 1; std::pair offset_range(size_type i) const; @@ -307,7 +312,7 @@ namespace sparrow using list_size_type = inner_types::list_size_type; using size_type = typename base_type::size_type; using offset_type = std::conditional_t; - using offset_buffer_type = u8_buffer>; + using offset_buffer_type = u8_buffer>; using size_buffer_type = u8_buffer>; explicit list_view_array_impl(arrow_proxy proxy); @@ -318,15 +323,22 @@ namespace sparrow list_view_array_impl(self_type&&) = default; list_view_array_impl& operator=(self_type&&) = default; - template - requires(mpl::excludes_copy_and_move_ctor_v, ARGS...>) - list_view_array_impl(ARGS&& ...args): self_type(create_proxy(std::forward(args)...)) - {} + template + requires(mpl::excludes_copy_and_move_ctor_v, ARGS...>) + list_view_array_impl(ARGS&&... args) + : self_type(create_proxy(std::forward(args)...)) + { + } private: - template - static arrow_proxy create_proxy(array && flat_values, offset_buffer_type && list_offsets,size_buffer_type && list_sizes,VB && validity_input = validity_bitmap{}); + template + static arrow_proxy create_proxy( + array&& flat_values, + offset_buffer_type&& list_offsets, + size_buffer_type&& list_sizes, + VB&& validity_input = validity_bitmap{} + ); static constexpr std::size_t OFFSET_BUFFER_INDEX = 1; static constexpr std::size_t SIZES_BUFFER_INDEX = 2; @@ -362,14 +374,18 @@ namespace sparrow fixed_sized_list_array(self_type&&) = default; fixed_sized_list_array& operator=(self_type&&) = default; - template - requires(mpl::excludes_copy_and_move_ctor_v) - fixed_sized_list_array(ARGS&& ...args): self_type(create_proxy(std::forward(args)...)) - {} + template + requires(mpl::excludes_copy_and_move_ctor_v) + fixed_sized_list_array(ARGS&&... args) + : self_type(create_proxy(std::forward(args)...)) + { + } private: - template - static arrow_proxy create_proxy(std::uint64_t list_size, array && flat_values, R && validity_input = validity_bitmap{}); + + template + static arrow_proxy + create_proxy(std::uint64_t list_size, array&& flat_values, R&& validity_input = validity_bitmap{}); static uint64_t list_size_from_format(const std::string_view format); std::pair offset_range(size_type i) const; @@ -491,15 +507,17 @@ namespace sparrow } template - template - auto list_array_impl::offset_from_sizes(SIZES_RANGE && sizes) -> offset_buffer_type + template + auto list_array_impl::offset_from_sizes(SIZES_RANGE&& sizes) -> offset_buffer_type { - return detail::offset_buffer_from_sizes>(std::forward(sizes)); + return detail::offset_buffer_from_sizes>(std::forward(sizes + )); } template - template - arrow_proxy list_array_impl::create_proxy(array && flat_values, offset_buffer_type && list_offsets,VB && validity_input) + template + arrow_proxy + list_array_impl::create_proxy(array&& flat_values, offset_buffer_type&& list_offsets, VB&& validity_input) { const auto size = list_offsets.size() - 1; validity_bitmap vbitmap = ensure_validity_bitmap(size, std::forward(validity_input)); @@ -509,13 +527,13 @@ namespace sparrow const auto null_count = vbitmap.null_count(); ArrowSchema schema = make_arrow_schema( - BIG ? std::string("+L") : std::string("+l"), // format - std::nullopt, // name - std::nullopt, // metadata - std::nullopt, // flags, - 1, // n_children - new ArrowSchema*[1]{new ArrowSchema(std::move(flat_schema))}, // children - nullptr // dictionary + BIG ? std::string("+L") : std::string("+l"), // format + std::nullopt, // name + std::nullopt, // metadata + std::nullopt, // flags, + 1, // n_children + new ArrowSchema*[1]{new ArrowSchema(std::move(flat_schema))}, // children + nullptr // dictionary ); std::vector> arr_buffs = { @@ -524,13 +542,13 @@ namespace sparrow }; ArrowArray arr = make_arrow_array( - static_cast(size), // length + static_cast(size), // length static_cast(null_count), - 0, // offset + 0, // offset std::move(arr_buffs), - 1, // n_children - new ArrowArray*[1]{new ArrowArray(std::move(flat_arr))}, // children - nullptr // dictionary + 1, // n_children + new ArrowArray*[1]{new ArrowArray(std::move(flat_arr))}, // children + nullptr // dictionary ); return arrow_proxy{std::move(arr), std::move(schema)}; } @@ -563,7 +581,7 @@ namespace sparrow auto list_array_impl::make_list_offsets() -> offset_type* { return reinterpret_cast( - this->get_arrow_proxy().buffers()[OFFSET_BUFFER_INDEX].data() + this->get_arrow_proxy().offset() + this->get_arrow_proxy().buffers()[OFFSET_BUFFER_INDEX].data() + this->get_arrow_proxy().offset() ); } @@ -580,16 +598,16 @@ namespace sparrow } template - template + template arrow_proxy list_view_array_impl::create_proxy( - array && flat_values, - offset_buffer_type && list_offsets, - size_buffer_type && list_sizes, - VB && validity_input + array&& flat_values, + offset_buffer_type&& list_offsets, + size_buffer_type&& list_sizes, + VB&& validity_input ) { - SPARROW_ASSERT(list_offsets.size() == list_sizes.size() , "sizes and offset must have the same size"); - + SPARROW_ASSERT(list_offsets.size() == list_sizes.size(), "sizes and offset must have the same size"); + const auto size = list_sizes.size(); validity_bitmap vbitmap = ensure_validity_bitmap(size, std::forward(validity_input)); @@ -598,13 +616,13 @@ namespace sparrow const auto null_count = vbitmap.null_count(); ArrowSchema schema = make_arrow_schema( - BIG ? std::string("+vL") : std::string("+vl"), // format - std::nullopt, // name - std::nullopt, // metadata - std::nullopt, // flags, - 1, // n_children - new ArrowSchema*[1]{new ArrowSchema(std::move(flat_schema))}, // children - nullptr // dictionary + BIG ? std::string("+vL") : std::string("+vl"), // format + std::nullopt, // name + std::nullopt, // metadata + std::nullopt, // flags, + 1, // n_children + new ArrowSchema*[1]{new ArrowSchema(std::move(flat_schema))}, // children + nullptr // dictionary ); std::vector> arr_buffs = { @@ -614,13 +632,13 @@ namespace sparrow }; ArrowArray arr = make_arrow_array( - static_cast(size), // length + static_cast(size), // length static_cast(null_count), - 0, // offset + 0, // offset std::move(arr_buffs), - 1, // n_children - new ArrowArray*[1]{new ArrowArray(std::move(flat_arr))}, // children - nullptr // dictionary + 1, // n_children + new ArrowArray*[1]{new ArrowArray(std::move(flat_arr))}, // children + nullptr // dictionary ); return arrow_proxy{std::move(arr), std::move(schema)}; } @@ -646,8 +664,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]); @@ -657,7 +675,7 @@ namespace sparrow auto list_view_array_impl::make_list_offsets() -> offset_type* { return reinterpret_cast( - this->get_arrow_proxy().buffers()[OFFSET_BUFFER_INDEX].data() + this->get_arrow_proxy().offset() + this->get_arrow_proxy().buffers()[OFFSET_BUFFER_INDEX].data() + this->get_arrow_proxy().offset() ); } @@ -665,7 +683,7 @@ namespace sparrow auto list_view_array_impl::make_list_sizes() -> offset_type* { return reinterpret_cast( - this->get_arrow_proxy().buffers()[SIZES_BUFFER_INDEX].data() + this->get_arrow_proxy().offset() + this->get_arrow_proxy().buffers()[SIZES_BUFFER_INDEX].data() + this->get_arrow_proxy().offset() ); } @@ -697,11 +715,9 @@ namespace sparrow return std::make_pair(offset, offset + m_list_size); } - template - inline arrow_proxy fixed_sized_list_array::create_proxy( - std::uint64_t list_size, array && flat_values, - R && validity_input - ) + template + inline arrow_proxy + fixed_sized_list_array::create_proxy(std::uint64_t list_size, array&& flat_values, R&& validity_input) { const auto size = flat_values.size() / static_cast(list_size); auto vbitmap = ensure_validity_bitmap(size, std::forward(validity_input)); @@ -713,24 +729,24 @@ namespace sparrow std::string format = "+w:" + std::to_string(list_size); ArrowSchema schema = make_arrow_schema( format, - std::nullopt, // name - std::nullopt, // metadata - std::nullopt, // flags, - 1, // n_children - new ArrowSchema*[1]{new ArrowSchema(std::move(flat_schema))}, // children - nullptr // dictionary + std::nullopt, // name + std::nullopt, // metadata + std::nullopt, // flags, + 1, // n_children + new ArrowSchema*[1]{new ArrowSchema(std::move(flat_schema))}, // children + nullptr // dictionary ); std::vector> arr_buffs = {vbitmap.extract_storage()}; ArrowArray arr = make_arrow_array( - static_cast(size), // length + static_cast(size), // length static_cast(null_count), - 0, // offset + 0, // offset std::move(arr_buffs), - 1, // n_children - new ArrowArray*[1]{new ArrowArray(std::move(flat_arr))}, // children - nullptr // dictionary + 1, // n_children + new ArrowArray*[1]{new ArrowArray(std::move(flat_arr))}, // children + nullptr // dictionary ); return arrow_proxy{std::move(arr), std::move(schema)}; } diff --git a/include/sparrow/layout/list_layout/list_value.hpp b/include/sparrow/layout/list_layout/list_value.hpp index 2ada3ac9..08babcf5 100644 --- a/include/sparrow/layout/list_layout/list_value.hpp +++ b/include/sparrow/layout/list_layout/list_value.hpp @@ -44,4 +44,3 @@ namespace sparrow SPARROW_API bool operator==(const list_value& lhs, const list_value& rhs); } - diff --git a/include/sparrow/layout/nested_value_types.hpp b/include/sparrow/layout/nested_value_types.hpp index ce6275fc..4eaa535e 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/null_array.hpp b/include/sparrow/layout/null_array.hpp index 239c96ae..5c508adb 100644 --- a/include/sparrow/layout/null_array.hpp +++ b/include/sparrow/layout/null_array.hpp @@ -17,11 +17,11 @@ #include #include +#include "sparrow/layout/array_access.hpp" #include "sparrow/layout/array_base.hpp" #include "sparrow/utils/contracts.hpp" #include "sparrow/utils/iterator.hpp" #include "sparrow/utils/nullable.hpp" -#include "sparrow/layout/array_access.hpp" namespace sparrow { diff --git a/include/sparrow/layout/run_end_encoded_layout/run_end_encoded_array.hpp b/include/sparrow/layout/run_end_encoded_layout/run_end_encoded_array.hpp index 4f528325..4e172035 100644 --- a/include/sparrow/layout/run_end_encoded_layout/run_end_encoded_array.hpp +++ b/include/sparrow/layout/run_end_encoded_layout/run_end_encoded_array.hpp @@ -14,13 +14,13 @@ #pragma once +#include "sparrow/array_api.hpp" +#include "sparrow/array_factory.hpp" #include "sparrow/config/config.hpp" +#include "sparrow/layout/array_access.hpp" #include "sparrow/layout/array_wrapper.hpp" -#include "sparrow/array_factory.hpp" -#include "sparrow/utils/memory.hpp" #include "sparrow/layout/run_end_encoded_layout/run_end_encoded_iterator.hpp" -#include "sparrow/layout/array_access.hpp" -#include "sparrow/array_api.hpp" +#include "sparrow/utils/memory.hpp" namespace sparrow { @@ -34,20 +34,20 @@ namespace sparrow 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::RUN_ENCODED; } }; } - class run_end_encoded_array + class run_end_encoded_array { public: @@ -56,19 +56,19 @@ namespace sparrow using inner_value_type = array_traits::inner_value_type; using iterator = run_encoded_array_iterator; using const_iterator = run_encoded_array_iterator; - - SPARROW_API explicit run_end_encoded_array(arrow_proxy proxy); - template - requires(mpl::excludes_copy_and_move_ctor_v) - explicit run_end_encoded_array(Args&& ... args) - : run_end_encoded_array(create_proxy(std::forward(args) ...)) - {} + SPARROW_API explicit run_end_encoded_array(arrow_proxy proxy); + template + requires(mpl::excludes_copy_and_move_ctor_v) + explicit run_end_encoded_array(Args&&... args) + : run_end_encoded_array(create_proxy(std::forward(args)...)) + { + } SPARROW_API run_end_encoded_array(const self_type&); SPARROW_API self_type& operator=(const self_type&); - + SPARROW_API run_end_encoded_array(self_type&&) = default; SPARROW_API self_type& operator=(self_type&&) = default; @@ -88,14 +88,12 @@ namespace sparrow private: - SPARROW_API static auto create_proxy( - array && acc_lengths, - array && encoded_values - ) -> arrow_proxy; + SPARROW_API static auto create_proxy(array&& acc_lengths, array&& encoded_values) -> arrow_proxy; - using acc_length_ptr_variant_type = std::variant< const std::uint16_t*, const std::uint32_t*,const std::uint64_t*> ; + using acc_length_ptr_variant_type = std::variant; - SPARROW_API static std::pair extract_length_and_null_count( const array&, const array&); + SPARROW_API static std::pair + extract_length_and_null_count(const array&, const array&); SPARROW_API static acc_length_ptr_variant_type get_acc_lengths_ptr(const array_wrapper& ar); SPARROW_API std::uint64_t get_run_length(std::uint64_t run_index) const; @@ -104,7 +102,7 @@ namespace sparrow arrow_proxy m_proxy; std::uint64_t m_encoded_length; - + cloning_ptr p_acc_lengths_array; cloning_ptr p_encoded_values_array; acc_length_ptr_variant_type m_acc_lengths; @@ -122,7 +120,7 @@ namespace sparrow * run_end_encoded_array implementation * ****************************************/ - inline run_end_encoded_array::run_end_encoded_array(arrow_proxy proxy) + inline run_end_encoded_array::run_end_encoded_array(arrow_proxy proxy) : m_proxy(std::move(proxy)) , m_encoded_length(m_proxy.children()[0].length()) , p_acc_lengths_array(array_factory(m_proxy.children()[0].view())) @@ -156,24 +154,25 @@ namespace sparrow inline auto run_end_encoded_array::get_run_length(std::uint64_t run_index) const -> std::uint64_t { - - auto ret = std::visit( + auto ret = std::visit( [run_index](auto&& acc_lengths_ptr) -> std::uint64_t { - if(run_index == 0) - { + if (run_index == 0) + { return static_cast(acc_lengths_ptr[run_index]); } else { - return static_cast(acc_lengths_ptr[run_index] - acc_lengths_ptr[run_index - 1]); + return static_cast( + acc_lengths_ptr[run_index] - acc_lengths_ptr[run_index - 1] + ); } }, m_acc_lengths ); return ret; } - + inline arrow_proxy& run_end_encoded_array::get_arrow_proxy() { return m_proxy; @@ -223,4 +222,4 @@ namespace sparrow { return std::ranges::equal(lhs, rhs); } -} // namespace sparrow +} // namespace sparrow 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 8faafb85..bc485ff8 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_array.hpp b/include/sparrow/layout/struct_layout/struct_array.hpp index 97067e5c..08b7761b 100644 --- a/include/sparrow/layout/struct_layout/struct_array.hpp +++ b/include/sparrow/layout/struct_layout/struct_array.hpp @@ -14,6 +14,7 @@ #pragma once +#include "sparrow/array_api.hpp" #include "sparrow/array_factory.hpp" #include "sparrow/arrow_array_schema_proxy.hpp" #include "sparrow/layout/array_bitmap_base.hpp" @@ -24,7 +25,6 @@ #include "sparrow/utils/iterator.hpp" #include "sparrow/utils/memory.hpp" #include "sparrow/utils/nullable.hpp" -#include "sparrow/array_api.hpp" namespace sparrow { @@ -75,12 +75,12 @@ namespace sparrow explicit struct_array(arrow_proxy proxy); - - template - requires(mpl::excludes_copy_and_move_ctor_v) - explicit struct_array(Args&& ... args) - : struct_array(create_proxy(std::forward(args) ...)) - {} + template + requires(mpl::excludes_copy_and_move_ctor_v) + explicit struct_array(Args&&... args) + : struct_array(create_proxy(std::forward(args)...)) + { + } struct_array(const struct_array&); struct_array& operator=(const struct_array&); @@ -94,10 +94,8 @@ namespace sparrow private: template - static auto create_proxy( - std::vector && children, - VB && bitmaps = validity_bitmap{} - ) -> arrow_proxy; + static auto create_proxy(std::vector&& children, VB&& bitmaps = validity_bitmap{}) + -> arrow_proxy; using children_type = std::vector>; @@ -144,20 +142,17 @@ namespace sparrow } template - auto struct_array::create_proxy( - std::vector && children, - VB && validity_input - ) -> arrow_proxy + auto struct_array::create_proxy(std::vector&& children, VB&& validity_input) -> arrow_proxy { const auto n_children = children.size(); ArrowSchema** child_schemas = new ArrowSchema*[n_children]; ArrowArray** child_arrays = new ArrowArray*[n_children]; const auto size = children[0].size(); - - for(std::size_t i=0; i(validity_input)); const auto null_count = vbitmap.null_count(); - + ArrowSchema schema = make_arrow_schema( - std::string("+s"), // format - std::nullopt, // name - std::nullopt, // metadata - std::nullopt, // flags, + std::string("+s"), // format + std::nullopt, // name + std::nullopt, // metadata + std::nullopt, // flags, static_cast(n_children), - child_schemas, // children - nullptr // dictionary + child_schemas, // children + nullptr // dictionary ); - std::vector> arr_buffs = { - std::move(vbitmap).extract_storage() - }; + std::vector> arr_buffs = {std::move(vbitmap).extract_storage()}; ArrowArray arr = make_arrow_array( - static_cast(size), // length + static_cast(size), // length static_cast(null_count), - 0, // offset + 0, // offset std::move(arr_buffs), - static_cast(n_children), // n_children - child_arrays, // children - nullptr // dictionary + static_cast(n_children), // n_children + child_arrays, // children + nullptr // dictionary ); return arrow_proxy{std::move(arr), std::move(schema)}; } diff --git a/include/sparrow/layout/struct_layout/struct_value.hpp b/include/sparrow/layout/struct_layout/struct_value.hpp index c2b2486d..4b89ea55 100644 --- a/include/sparrow/layout/struct_layout/struct_value.hpp +++ b/include/sparrow/layout/struct_layout/struct_value.hpp @@ -37,7 +37,7 @@ namespace sparrow const_reference operator[](size_type i) const; private: - + const std::vector* p_children = nullptr; size_type m_index = 0u; }; @@ -45,4 +45,3 @@ namespace sparrow SPARROW_API bool operator==(const struct_value& lhs, const struct_value& rhs); } - diff --git a/include/sparrow/layout/union_array.hpp b/include/sparrow/layout/union_array.hpp index 0bd32b97..b897394f 100644 --- a/include/sparrow/layout/union_array.hpp +++ b/include/sparrow/layout/union_array.hpp @@ -14,40 +14,41 @@ #pragma once +#include "sparrow/array_api.hpp" +#include "sparrow/array_factory.hpp" #include "sparrow/config/config.hpp" +#include "sparrow/layout/array_access.hpp" +#include "sparrow/layout/array_helper.hpp" #include "sparrow/layout/array_wrapper.hpp" -#include "sparrow/array_factory.hpp" #include "sparrow/layout/layout_utils.hpp" #include "sparrow/layout/nested_value_types.hpp" -#include "sparrow/utils/memory.hpp" -#include "sparrow/layout/array_helper.hpp" #include "sparrow/utils/crtp_base.hpp" #include "sparrow/utils/functor_index_iterator.hpp" -#include "sparrow/layout/array_access.hpp" -#include "sparrow/array_api.hpp" +#include "sparrow/utils/memory.hpp" namespace sparrow -{ +{ class dense_union_array; class sparse_union_array; 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::DENSE_UNION; } }; - template<> + + template <> struct get_data_type_from_array { - constexpr static sparrow::data_type get() + static constexpr sparrow::data_type get() { return sparrow::data_type::SPARSE_UNION; } @@ -67,10 +68,10 @@ namespace sparrow constexpr bool is_sparse_union_array_v = std::same_as; // helper crtp-base to have sparse and dense and dense union share most of their code - template + template class union_array_crtp_base : public crtp_base { - public: + public: using self_type = union_array_crtp_base; using derived_type = DERIVED; @@ -81,7 +82,7 @@ namespace sparrow using iterator = functor_index_iterator; using const_iterator = functor_index_iterator; - using type_id_buffer_type = u8_buffer; + using type_id_buffer_type = u8_buffer; value_type operator[](std::size_t i) const; value_type operator[](std::size_t i); @@ -104,7 +105,7 @@ namespace sparrow static type_id_map type_id_map_from_child_to_type_id(R&& child_index_to_type_id); template - requires(std::convertible_to, std::uint8_t>) + requires(std::convertible_to, std::uint8_t>) static std::string make_format_string(bool dense, std::size_t n, R&& child_index_to_type_id); using children_type = std::vector>; @@ -122,14 +123,14 @@ namespace sparrow [[nodiscard]] const arrow_proxy& get_arrow_proxy() const; arrow_proxy m_proxy; - const std::uint8_t * p_type_ids; + const std::uint8_t* p_type_ids; children_type m_children; // map from type-id to child-index std::array m_type_id_map; friend class detail::array_access; - }; + }; template bool operator==(const union_array_crtp_base& lhs, const union_array_crtp_base& rhs); @@ -139,14 +140,15 @@ namespace sparrow public: using base_type = union_array_crtp_base; - using offset_buffer_type = u8_buffer; - using type_id_buffer_type = typename base_type::type_id_buffer_type; + using offset_buffer_type = u8_buffer; + using type_id_buffer_type = typename base_type::type_id_buffer_type; - template - requires(mpl::excludes_copy_and_move_ctor_v) - explicit dense_union_array(Args&& ... args) - : dense_union_array(create_proxy(std::forward(args) ...)) - {} + template + requires(mpl::excludes_copy_and_move_ctor_v) + explicit dense_union_array(Args&&... args) + : dense_union_array(create_proxy(std::forward(args)...)) + { + } explicit dense_union_array(arrow_proxy proxy); @@ -158,49 +160,47 @@ namespace sparrow private: - template < - std::ranges::input_range TYPE_MAPPING = std::vector - > - requires(std::convertible_to, std::uint8_t>) + template > + requires(std::convertible_to, std::uint8_t>) static auto create_proxy( - std::vector && children, - type_id_buffer_type && element_type, - offset_buffer_type && offsets, - TYPE_MAPPING && type_mapping = TYPE_MAPPING{} + std::vector&& children, + type_id_buffer_type&& element_type, + offset_buffer_type&& offsets, + TYPE_MAPPING&& type_mapping = TYPE_MAPPING{} ) -> arrow_proxy; std::size_t element_offset(std::size_t i) const; - const std::int32_t * p_offsets; + const std::int32_t* p_offsets; friend class union_array_crtp_base; }; class sparse_union_array : public union_array_crtp_base { public: - + using base_type = union_array_crtp_base; - using type_id_buffer_type = typename base_type::type_id_buffer_type; + using type_id_buffer_type = typename base_type::type_id_buffer_type; - template - requires(mpl::excludes_copy_and_move_ctor_v) - explicit sparse_union_array(Args&& ... args) - : sparse_union_array(create_proxy(std::forward(args) ...)) - {} + template + requires(mpl::excludes_copy_and_move_ctor_v) + explicit sparse_union_array(Args&&... args) + : sparse_union_array(create_proxy(std::forward(args)...)) + { + } explicit sparse_union_array(arrow_proxy proxy); - template < - std::ranges::input_range TYPE_MAPPING = std::vector - > - requires(std::convertible_to, std::uint8_t>) + template > + requires(std::convertible_to, std::uint8_t>) static auto create_proxy( - std::vector && children, - type_id_buffer_type && element_type, - TYPE_MAPPING && type_mapping = TYPE_MAPPING{} + std::vector&& children, + type_id_buffer_type&& element_type, + TYPE_MAPPING&& type_mapping = TYPE_MAPPING{} ) -> arrow_proxy; private: + std::size_t element_offset(std::size_t i) const; friend class union_array_crtp_base; }; @@ -210,34 +210,39 @@ namespace sparrow { type_id_map ret; // remove +du: / +su: prefix - format_string.remove_prefix(4); - - constexpr std::string_view delim { "," }; - std::size_t child_index = 0; - std::ranges::for_each(format_string | std::views::split(delim), [&](const auto& s) { - const auto as_int = std::atoi(std::string(s.begin(), s.end()).c_str()); - ret[static_cast(as_int)] = static_cast(child_index); - ++child_index; - }); + format_string.remove_prefix(4); + + constexpr std::string_view delim{","}; + std::size_t child_index = 0; + std::ranges::for_each( + format_string | std::views::split(delim), + [&](const auto& s) + { + const auto as_int = std::atoi(std::string(s.begin(), s.end()).c_str()); + ret[static_cast(as_int)] = static_cast(child_index); + ++child_index; + } + ); return ret; } 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; - if(n == 0) + if (n == 0) { - for(std::size_t i = 0; i < 256; ++i) + for (std::size_t i = 0; i < 256; ++i) { ret[i] = static_cast(i); } } else { - for(std::size_t i = 0; i < n; ++i) + for (std::size_t i = 0; i < n; ++i) { ret[child_index_to_type_id[i]] = static_cast(i); } @@ -247,16 +252,16 @@ namespace sparrow template template - requires(std::convertible_to, std::uint8_t>) + requires(std::convertible_to, std::uint8_t>) std::string union_array_crtp_base::make_format_string(bool dense, const std::size_t n, R&& range) - { + { const auto range_size = std::ranges::size(range); - if(range_size == n || range_size == 0) - { + if (range_size == n || range_size == 0) + { std::string ret = dense ? "+ud:" : "+us:"; - if(range_size == 0) + if (range_size == 0) { - for(std::size_t i = 0; i < n; ++i) + for (std::size_t i = 0; i < n; ++i) { ret += std::to_string(i) + ","; } @@ -269,7 +274,7 @@ namespace sparrow } } ret.pop_back(); - return ret; + return ret; } else { @@ -277,7 +282,6 @@ namespace sparrow } } - /**************************************** * union_array_crtp_base implementation * ****************************************/ @@ -297,7 +301,7 @@ namespace sparrow template union_array_crtp_base::union_array_crtp_base(arrow_proxy proxy) : m_proxy(std::move(proxy)) - , p_type_ids(reinterpret_cast(m_proxy.buffers()[0/*index of type-ids*/].data())) + , p_type_ids(reinterpret_cast(m_proxy.buffers()[0 /*index of type-ids*/].data())) , m_children(make_children(m_proxy)) , m_type_id_map(parse_type_id_map(m_proxy.format())) { @@ -315,7 +319,7 @@ namespace sparrow if (this != &rhs) { m_proxy = rhs.m_proxy; - p_type_ids = reinterpret_cast(m_proxy.buffers()[0/*index of type-ids*/].data()); + p_type_ids = reinterpret_cast(m_proxy.buffers()[0 /*index of type-ids*/].data()); m_children = make_children(m_proxy); m_type_id_map = parse_type_id_map(m_proxy.format()); } @@ -324,7 +328,7 @@ namespace sparrow template auto union_array_crtp_base::operator[](std::size_t i) const -> value_type - { + { const auto type_id = static_cast(p_type_ids[i]); const auto child_index = m_type_id_map[type_id]; const auto offset = this->derived_cast().element_offset(i); @@ -333,7 +337,7 @@ namespace sparrow template auto union_array_crtp_base::operator[](std::size_t i) -> value_type - { + { return static_cast(*this)[i]; } @@ -356,25 +360,25 @@ namespace sparrow } template - auto union_array_crtp_base::begin() const -> const_iterator + auto union_array_crtp_base::begin() const -> const_iterator { return cbegin(); } template - auto union_array_crtp_base::end() const -> const_iterator + auto union_array_crtp_base::end() const -> const_iterator { return cend(); } template - auto union_array_crtp_base::cbegin() const -> const_iterator + auto union_array_crtp_base::cbegin() const -> const_iterator { return const_iterator(const_functor_type{&(this->derived_cast())}, 0); } template - auto union_array_crtp_base::cend() const -> const_iterator + auto union_array_crtp_base::cend() const -> const_iterator { return const_iterator(const_functor_type{&(this->derived_cast())}, this->size()); } @@ -400,13 +404,13 @@ namespace sparrow * dense_union_array implementation * ************************************/ - #ifdef __GNUC__ - # pragma GCC diagnostic push - # pragma GCC diagnostic ignored "-Wcast-align" - #endif +#ifdef __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wcast-align" +#endif inline dense_union_array::dense_union_array(arrow_proxy proxy) : base_type(std::move(proxy)) - , p_offsets(reinterpret_cast(m_proxy.buffers()[1/*index of offsets*/].data())) + , p_offsets(reinterpret_cast(m_proxy.buffers()[1 /*index of offsets*/].data())) { } @@ -417,23 +421,21 @@ namespace sparrow inline dense_union_array& dense_union_array::operator=(const dense_union_array& rhs) { - if (this !=&rhs) + if (this != &rhs) { base_type::operator=(rhs); - p_offsets = reinterpret_cast(m_proxy.buffers()[1/*index of offsets*/].data()); + p_offsets = reinterpret_cast(m_proxy.buffers()[1 /*index of offsets*/].data()); } return *this; } - template < - std::ranges::input_range TYPE_MAPPING - > - requires(std::convertible_to, std::uint8_t>) + template + requires(std::convertible_to, std::uint8_t>) auto dense_union_array::create_proxy( - std::vector && children, - type_id_buffer_type && element_type, - offset_buffer_type && offsets, - TYPE_MAPPING && child_index_to_type_id + std::vector&& children, + type_id_buffer_type&& element_type, + offset_buffer_type&& offsets, + TYPE_MAPPING&& child_index_to_type_id ) -> arrow_proxy { const auto n_children = children.size(); @@ -446,7 +448,7 @@ namespace sparrow // count nulls (expensive!) int64_t null_count = 0; - for(std::size_t i = 0; i < size; ++i) + for (std::size_t i = 0; i < size; ++i) { // child_id from type_id const auto type_id = static_cast(element_type[i]); @@ -459,24 +461,28 @@ namespace sparrow } } - for(std::size_t i=0; i(child_index_to_type_id)); - + std::string format = make_format_string( + true /*dense union*/, + n_children, + std::forward(child_index_to_type_id) + ); + ArrowSchema schema = make_arrow_schema( format, - std::nullopt, // name - std::nullopt, // metadata - std::nullopt, // flags, + std::nullopt, // name + std::nullopt, // metadata + std::nullopt, // flags, static_cast(n_children), - child_schemas, // children - nullptr // dictionary + child_schemas, // children + nullptr // dictionary ); std::vector> arr_buffs = { @@ -485,20 +491,20 @@ namespace sparrow }; ArrowArray arr = make_arrow_array( - static_cast(size), // length + static_cast(size), // length static_cast(null_count), - 0, // offset + 0, // offset std::move(arr_buffs), - static_cast(n_children), // n_children - child_arrays, // children - nullptr // dictionary + static_cast(n_children), // n_children + child_arrays, // children + nullptr // dictionary ); return arrow_proxy{std::move(arr), std::move(schema)}; } - #ifdef __GNUC__ - # pragma GCC diagnostic pop - #endif +#ifdef __GNUC__ +# pragma GCC diagnostic pop +#endif inline std::size_t dense_union_array::element_offset(std::size_t i) const { @@ -514,14 +520,12 @@ namespace sparrow { } - template < - std::ranges::input_range TYPE_MAPPING - > - requires(std::convertible_to, std::uint8_t>) + template + requires(std::convertible_to, std::uint8_t>) auto sparse_union_array::create_proxy( - std::vector && children, - type_id_buffer_type && element_type, - TYPE_MAPPING && child_index_to_type_id + std::vector&& children, + type_id_buffer_type&& element_type, + TYPE_MAPPING&& child_index_to_type_id ) -> arrow_proxy { const auto n_children = children.size(); @@ -534,7 +538,7 @@ namespace sparrow // count nulls (expensive!) int64_t null_count = 0; - for(std::size_t i = 0; i < size; ++i) + for (std::size_t i = 0; i < size; ++i) { // child_id from type_id const auto type_id = static_cast(element_type[i]); @@ -546,38 +550,40 @@ namespace sparrow } } - for(std::size_t i=0; i(child_index_to_type_id)); + std::string format = make_format_string( + false /*is dense union*/, + n_children, + std::forward(child_index_to_type_id) + ); ArrowSchema schema = make_arrow_schema( format, - std::nullopt, // name - std::nullopt, // metadata - std::nullopt, // flags, + std::nullopt, // name + std::nullopt, // metadata + std::nullopt, // flags, static_cast(n_children), - child_schemas, // children - nullptr // dictionary + child_schemas, // children + nullptr // dictionary ); - std::vector> arr_buffs = { - std::move(element_type).extract_storage() - }; + std::vector> arr_buffs = {std::move(element_type).extract_storage()}; ArrowArray arr = make_arrow_array( - static_cast(size), // length + static_cast(size), // length static_cast(null_count), - 0, // offset + 0, // offset std::move(arr_buffs), - static_cast(n_children), // n_children - child_arrays, // children - nullptr // dictionary + static_cast(n_children), // n_children + child_arrays, // children + nullptr // dictionary ); return arrow_proxy{std::move(arr), std::move(schema)}; } 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 2e18f15d..83f6e6e2 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 @@ -300,7 +300,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 )); @@ -376,19 +377,19 @@ namespace sparrow { // split into values and is_non_null ranges const auto values = range - | std::views::transform( - [](const auto& v) - { - return v.get(); - } - ); + | std::views::transform( + [](const auto& v) + { + return v.get(); + } + ); const auto is_non_null = range - | std::views::transform( - [](const auto& v) - { - return v.has_value(); - } - ); + | std::views::transform( + [](const auto& v) + { + return v.has_value(); + } + ); return self_type::create_proxy(values, is_non_null); } 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 6980b9f8..934b0273 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 6ca1914e..48afcbb4 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/layout/variable_size_binary_view_array.hpp b/include/sparrow/layout/variable_size_binary_view_array.hpp index a39c201e..75b26e06 100644 --- a/include/sparrow/layout/variable_size_binary_view_array.hpp +++ b/include/sparrow/layout/variable_size_binary_view_array.hpp @@ -17,18 +17,17 @@ #include #include +#include "sparrow/arrow_array_schema_proxy.hpp" #include "sparrow/arrow_interface/arrow_array.hpp" #include "sparrow/arrow_interface/arrow_schema.hpp" -#include "sparrow/utils/functor_index_iterator.hpp" -#include "sparrow/arrow_interface/arrow_schema.hpp" -#include "sparrow/arrow_array_schema_proxy.hpp" +#include "sparrow/buffer/dynamic_bitset.hpp" +#include "sparrow/buffer/u8_buffer.hpp" +#include "sparrow/layout/array_access.hpp" #include "sparrow/layout/array_bitmap_base.hpp" #include "sparrow/layout/layout_utils.hpp" +#include "sparrow/utils/functor_index_iterator.hpp" #include "sparrow/utils/iterator.hpp" #include "sparrow/utils/nullable.hpp" -#include "sparrow/layout/array_access.hpp" -#include "sparrow/buffer/dynamic_bitset.hpp" -#include "sparrow/buffer/u8_buffer.hpp" #include "sparrow/utils/ranges.hpp" namespace sparrow @@ -42,21 +41,22 @@ namespace sparrow 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_VIEW; } }; - 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_VIEW; } @@ -70,7 +70,7 @@ namespace sparrow using inner_value_type = T; using inner_reference = T; using inner_const_reference = inner_reference; - + using value_iterator = functor_index_iterator>; using const_value_iterator = functor_index_iterator< detail::layout_value_functor>; @@ -94,7 +94,8 @@ namespace sparrow constexpr bool is_variable_size_binary_view_array = is_variable_size_binary_view_array_impl::value; template - class variable_size_binary_view_array_impl final : public mutable_array_bitmap_base> + class variable_size_binary_view_array_impl final + : public mutable_array_bitmap_base> { public: @@ -130,17 +131,17 @@ namespace sparrow explicit variable_size_binary_view_array_impl(arrow_proxy); - template - requires(mpl::excludes_copy_and_move_ctor_v, Args...>) - explicit variable_size_binary_view_array_impl(Args&& ... args) - : variable_size_binary_view_array_impl(create_proxy(std::forward(args) ...)) + template + requires(mpl::excludes_copy_and_move_ctor_v, Args...>) + explicit variable_size_binary_view_array_impl(Args&&... args) + : variable_size_binary_view_array_impl(create_proxy(std::forward(args)...)) { } private: - template - requires std::convertible_to, T> + template + requires std::convertible_to, T> static arrow_proxy create_proxy(R&& range, VB&& bitmap_input = validity_bitmap{}); inner_reference value(size_type i); @@ -161,11 +162,10 @@ namespace sparrow static constexpr std::ptrdiff_t BUFFER_INDEX_OFFSET = 8; static constexpr std::ptrdiff_t BUFFER_OFFSET_OFFSET = 12; static constexpr std::size_t FIRST_VAR_DATA_BUFFER_INDEX = 2; - + friend base_type; friend base_type::base_type; - }; template @@ -175,32 +175,32 @@ namespace sparrow } template - template - requires std::convertible_to, T> - arrow_proxy variable_size_binary_view_array_impl::create_proxy( - R && range, - VB && validity_input - ) - { - - #ifdef __GNUC__ - # pragma GCC diagnostic push - # pragma GCC diagnostic ignored "-Wcast-align" - #endif + template + requires std::convertible_to, T> + arrow_proxy variable_size_binary_view_array_impl::create_proxy(R&& range, VB&& validity_input) + { +#ifdef __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wcast-align" +#endif const auto size = range_size(range); validity_bitmap vbitmap = ensure_validity_bitmap(size, std::forward(validity_input)); const auto null_count = vbitmap.null_count(); buffer length_buffer(size * DATA_BUFFER_SIZE); - + std::size_t long_string_storage_size = 0; std::size_t i = 0; - for(auto && val : range) - { - auto val_casted = val | std::ranges::views::transform([](const auto& v) { - return static_cast(v); - }); + for (auto&& val : range) + { + auto val_casted = val + | std::ranges::views::transform( + [](const auto& v) + { + return static_cast(v); + } + ); const auto length = val.size(); auto length_ptr = length_buffer.data() + (i * DATA_BUFFER_SIZE); @@ -208,7 +208,7 @@ namespace sparrow // write length *reinterpret_cast(length_ptr) = static_cast(length); - if(length <= SHORT_STRING_SIZE) + if (length <= SHORT_STRING_SIZE) { // write data itself std::ranges::copy(val_casted, length_ptr + SHORT_STRING_OFFSET); @@ -220,49 +220,60 @@ namespace sparrow std::ranges::copy(prefix_sub_range, length_ptr + PREFIX_OFFSET); // write the buffer index - *reinterpret_cast(length_ptr + BUFFER_INDEX_OFFSET) = static_cast(FIRST_VAR_DATA_BUFFER_INDEX); + *reinterpret_cast( + length_ptr + BUFFER_INDEX_OFFSET + ) = static_cast(FIRST_VAR_DATA_BUFFER_INDEX); // write the buffer offset - *reinterpret_cast(length_ptr + BUFFER_OFFSET_OFFSET) = static_cast(long_string_storage_size); - + *reinterpret_cast( + length_ptr + BUFFER_OFFSET_OFFSET + ) = static_cast(long_string_storage_size); + // count the size of the long string storage long_string_storage_size += length; } ++i; - } + } // write the long string storage buffer long_string_storage(long_string_storage_size); std::size_t long_string_storage_offset = 0; - for(auto && val : range) + for (auto&& val : range) { const auto length = val.size(); - if(length > SHORT_STRING_SIZE) + if (length > SHORT_STRING_SIZE) { - auto val_casted = val | std::ranges::views::transform([](const auto& v) { - return static_cast(v); - }); + auto val_casted = val + | std::ranges::views::transform( + [](const auto& v) + { + return static_cast(v); + } + ); std::ranges::copy(val_casted, long_string_storage.data() + long_string_storage_offset); long_string_storage_offset += length; } } - // For binary or utf-8 view arrays, an extra buffer is appended which stores - // the lengths of each variadic data buffer as int64_t. + // For binary or utf-8 view arrays, an extra buffer is appended which stores + // the lengths of each variadic data buffer as int64_t. // This buffer is necessary since these buffer lengths are not trivially // extractable from other data in an array of binary or utf-8 view type. - u8_buffer buffer_sizes(static_cast(1), static_cast(long_string_storage_size)); + u8_buffer buffer_sizes( + static_cast(1), + static_cast(long_string_storage_size) + ); // create arrow schema and array ArrowSchema schema = make_arrow_schema( std::is_same::value ? std::string_view("vu") : std::string_view("vz"), - std::nullopt, // name - std::nullopt, // metadata - std::nullopt, // flags - 0, // n_children - nullptr, // children - nullptr // dictionary + std::nullopt, // name + std::nullopt, // metadata + std::nullopt, // flags + 0, // n_children + nullptr, // children + nullptr // dictionary ); std::vector> buffers{ @@ -274,21 +285,20 @@ namespace sparrow // create arrow array ArrowArray arr = make_arrow_array( - static_cast(size), // length + static_cast(size), // length static_cast(null_count), - 0, // offset + 0, // offset std::move(buffers), - 0, // n_children - nullptr, // children - nullptr // dictionary + 0, // n_children + nullptr, // children + nullptr // dictionary ); - - return arrow_proxy{std::move(arr), std::move(schema)}; - #ifdef __GNUC__ - # pragma GCC diagnostic pop - #endif + return arrow_proxy{std::move(arr), std::move(schema)}; +#ifdef __GNUC__ +# pragma GCC diagnostic pop +#endif } template @@ -300,39 +310,44 @@ namespace sparrow template auto variable_size_binary_view_array_impl::value(size_type i) const -> inner_const_reference { - #ifdef __GNUC__ - # pragma GCC diagnostic push - # pragma GCC diagnostic ignored "-Wcast-align" - #endif +#ifdef __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wcast-align" +#endif SPARROW_ASSERT_TRUE(i < this->size()); constexpr std::size_t element_size = 16; - auto data_ptr = this->get_arrow_proxy().buffers()[LENGTH_BUFFER_INDEX].template data() + (i * element_size); + auto data_ptr = this->get_arrow_proxy().buffers()[LENGTH_BUFFER_INDEX].template data() + + (i * element_size); auto length = static_cast(*reinterpret_cast(data_ptr)); using char_or_byte = typename inner_const_reference::value_type; - if(length <= 12) + if (length <= 12) { constexpr std::ptrdiff_t data_offset = 4; auto ptr = reinterpret_cast(data_ptr); - const auto ret = inner_const_reference(ptr + data_offset, length); + const auto ret = inner_const_reference(ptr + data_offset, length); return ret; } else { constexpr std::ptrdiff_t buffer_index_offset = 8; constexpr std::ptrdiff_t buffer_offset_offset = 12; - auto buffer_index = static_cast(*reinterpret_cast(data_ptr + buffer_index_offset)); - auto buffer_offset = static_cast(*reinterpret_cast(data_ptr + buffer_offset_offset)); + auto buffer_index = static_cast( + *reinterpret_cast(data_ptr + buffer_index_offset) + ); + auto buffer_offset = static_cast( + *reinterpret_cast(data_ptr + buffer_offset_offset) + ); auto buffer = this->get_arrow_proxy().buffers()[buffer_index].template data(); - return inner_const_reference(buffer + buffer_offset, length); + return inner_const_reference(buffer + buffer_offset, length); } - #ifdef __GNUC__ - # pragma GCC diagnostic pop - #endif +#ifdef __GNUC__ +# pragma GCC diagnostic pop +#endif } template @@ -344,18 +359,13 @@ namespace sparrow template auto variable_size_binary_view_array_impl::value_end() -> value_iterator { - return value_iterator( - detail::layout_value_functor(this), this->size() - ); + return value_iterator(detail::layout_value_functor(this), this->size()); } template auto variable_size_binary_view_array_impl::value_cbegin() const -> const_value_iterator { - return const_value_iterator( - detail::layout_value_functor(this), - 0 - ); + return const_value_iterator(detail::layout_value_functor(this), 0); } template diff --git a/include/sparrow/record_batch.hpp b/include/sparrow/record_batch.hpp index c6f3e75e..0835079c 100644 --- a/include/sparrow/record_batch.hpp +++ b/include/sparrow/record_batch.hpp @@ -96,7 +96,8 @@ namespace sparrow /** * @returns the name mapped to the column at the given index. - * @param index The index of the column in the \ref record_batch. The index must be less than the number of columns. + * @param index The index of the column in the \ref record_batch. The index must be less than the + * number of columns. */ SPARROW_API const name_type& get_column_name(size_type index) const; diff --git a/include/sparrow/types/data_traits.hpp b/include/sparrow/types/data_traits.hpp index 25341162..07681ae8 100644 --- a/include/sparrow/types/data_traits.hpp +++ b/include/sparrow/types/data_traits.hpp @@ -45,7 +45,6 @@ namespace sparrow static constexpr data_type type_id = data_type_from_size(); }; - template <> struct arrow_traits { @@ -117,8 +116,7 @@ namespace sparrow using value_type = decimal; using const_reference = decimal; }; - - + namespace detail { template @@ -140,24 +138,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 d494363a..876bcd00 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 0ac21d44..49ea7f5e 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 9be14f94..710aaf65 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 2d2a971d..ab3e8f9f 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/large_int.hpp b/include/sparrow/utils/large_int.hpp index a1b6bde4..e4ec7083 100644 --- a/include/sparrow/utils/large_int.hpp +++ b/include/sparrow/utils/large_int.hpp @@ -3,19 +3,19 @@ #ifndef SPARROW_USE_LARGE_INT_PLACEHOLDERS // disabe warnings -Wold-style-cast sign-conversion for clang and gcc -#if defined(__clang__) || defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wshadow" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#endif -#include -#include - -#if defined(__clang__) || defined(__GNUC__) -#pragma GCC diagnostic pop -#endif +# if defined(__clang__) || defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wold-style-cast" +# pragma GCC diagnostic ignored "-Wsign-conversion" +# pragma GCC diagnostic ignored "-Wshadow" +# pragma GCC diagnostic ignored "-Wsign-conversion" +# endif +# include +# include + +# if defined(__clang__) || defined(__GNUC__) +# pragma GCC diagnostic pop +# endif #endif @@ -23,52 +23,57 @@ namespace sparrow { - - #ifdef SPARROW_USE_LARGE_INT_PLACEHOLDERS - constexpr bool large_int_placeholders = true; +#ifdef SPARROW_USE_LARGE_INT_PLACEHOLDERS + constexpr bool large_int_placeholders = true; struct int128_t { int128_t() = default; std::uint64_t words[2]; - bool operator == (const int128_t& other) const + + bool operator==(const int128_t& other) const { return words[0] == other.words[0] && words[1] == other.words[1]; } - bool operator != (const int128_t& other) const + + bool operator!=(const int128_t& other) const { return !(*this == other); } }; + struct int256_t { int256_t() = default; std::uint64_t words[4]; - bool operator == (const int256_t& other) const + + bool operator==(const int256_t& other) const { - return words[0] == other.words[0] && words[1] == other.words[1] && words[2] == other.words[2] && words[3] == other.words[3]; + return words[0] == other.words[0] && words[1] == other.words[1] && words[2] == other.words[2] + && words[3] == other.words[3]; } - bool operator != (const int256_t& other) const + + bool operator!=(const int256_t& other) const { return !(*this == other); } }; - template + template constexpr bool is_int_placeholder_v = std::is_same_v || std::is_same_v; - #else - - template +#else + + template constexpr bool is_int_placeholder_v = false; constexpr bool large_int_placeholders = false; using int128_t = primesum::int128_t; using int256_t = primesum::int256_t; - template - requires (std::is_same_v || std::is_same_v) + template + requires(std::is_same_v || std::is_same_v) inline std::ostream& operator<<(std::ostream& stream, T n) { std::string str; @@ -93,5 +98,5 @@ namespace sparrow return stream; } - #endif -} // namespace sparrow \ No newline at end of file +#endif +} // namespace sparrow \ No newline at end of file diff --git a/include/sparrow/utils/memory.hpp b/include/sparrow/utils/memory.hpp index dbfa9bf6..cfcd6e6d 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 579e0f59..8355d62a 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/nullable.hpp b/include/sparrow/utils/nullable.hpp index 2d908600..cdd1c3dd 100644 --- a/include/sparrow/utils/nullable.hpp +++ b/include/sparrow/utils/nullable.hpp @@ -23,7 +23,7 @@ #include "sparrow/utils/mp_utils.hpp" #if defined(SPARROW_CONSTEXPR) -#error "SPARROW_CONSTEXPR already defined" +# error "SPARROW_CONSTEXPR already defined" #endif // clang workaround: clang instantiates the constructor in SFINAE context, @@ -31,9 +31,9 @@ // are not libc++. This leads to wrong compilation errors. Making the constructor // not constexpr prevents the compiler from instantiating it. #if defined(__clang__) && not defined(_LIBCPP_VERSION) -# define SPARROW_CONSTEXPR +# define SPARROW_CONSTEXPR #else -# define SPARROW_CONSTEXPR constexpr +# define SPARROW_CONSTEXPR constexpr #endif namespace sparrow @@ -42,30 +42,34 @@ namespace sparrow class nullable; template - struct is_nullable : std::false_type {}; + struct is_nullable : std::false_type + { + }; template - struct is_nullable> : std::true_type {}; + struct is_nullable> : std::true_type + { + }; template inline constexpr bool is_nullable_v = is_nullable::value; - template + template concept is_nullable_of = is_nullable_v && std::same_as; - template - concept is_nullable_of_convertible_to = is_nullable_v && std::convertible_to; + template + concept is_nullable_of_convertible_to = is_nullable_v && std::convertible_to; /* - * Matches a range of nullables objects. - * - * A range is considered a range of nullables if it is a range and its value type is a nullable. - * - * @tparam RangeOfNullables The range to check. - */ - template - concept range_of_nullables = std::ranges::range && is_nullable>::value; - + * Matches a range of nullables objects. + * + * A range is considered a range of nullables if it is a range and its value type is a nullable. + * + * @tparam RangeOfNullables The range to check. + */ + template + concept range_of_nullables = std::ranges::range + && is_nullable>::value; /* * Default traits for the nullable class. These traits should be specialized @@ -135,7 +139,9 @@ namespace sparrow // a is a nullable would lead to an ambiguous call // where both operator=(nullable&&) and operator=(nullval_t) // are valid. - constexpr explicit nullval_t(int) {} + constexpr explicit nullval_t(int) + { + } }; inline constexpr nullval_t nullval(0); @@ -146,65 +152,60 @@ namespace sparrow * Concepts used to disambiguate the nullable class constructors. */ template - concept both_constructible_from_cref = - std::constructible_from> and - std::constructible_from>; + concept both_constructible_from_cref = std::constructible_from> + and std::constructible_from>; template - concept both_convertible_from_cref = - std::convertible_to, To1> and - std::convertible_to, To2>; + concept both_convertible_from_cref = std::convertible_to, To1> + and std::convertible_to, To2>; template - concept constructible_from_one = - (std::constructible_from || ...); + concept constructible_from_one = (std::constructible_from || ...); template - concept convertible_from_one = - (std::convertible_to || ...); + concept convertible_from_one = (std::convertible_to || ...); template - concept initializable_from_one = - constructible_from_one || - convertible_from_one; + concept initializable_from_one = constructible_from_one || convertible_from_one; template - concept initializable_from_refs = - initializable_from_one; + concept initializable_from_refs = initializable_from_one; // We prefer std::is_assignable_v to std::assignable_from because // std::assignable_from requires the existence of an implicit conversion // from From to To template - concept assignable_from_one = - (std::is_assignable_v, Args> && ...); + concept assignable_from_one = (std::is_assignable_v, Args> && ...); template - concept assignable_from_refs = - assignable_from_one; + concept assignable_from_refs = assignable_from_one; template using conditional_ref_t = std::conditional_t, const std::decay_t&, std::decay_t&&>; template - concept both_constructible_from_cond_ref = - std::constructible_from> and - std::constructible_from>; + concept both_constructible_from_cond_ref = std::constructible_from> + and std::constructible_from>; template - concept both_convertible_from_cond_ref = - std::convertible_to, To1> and - std::convertible_to, To2>; + concept both_convertible_from_cond_ref = std::convertible_to, To1> + and std::convertible_to, To2>; template - concept both_assignable_from_cref = - std::is_assignable_v, mpl::add_const_lvalue_reference_t> and - std::is_assignable_v, mpl::add_const_lvalue_reference_t>; + concept both_assignable_from_cref = std::is_assignable_v< + std::add_lvalue_reference_t, + mpl::add_const_lvalue_reference_t> + and std::is_assignable_v< + std::add_lvalue_reference_t, + mpl::add_const_lvalue_reference_t>; template - concept both_assignable_from_cond_ref = - std::is_assignable_v, conditional_ref_t> and - std::is_assignable_v, conditional_ref_t>; + concept both_assignable_from_cond_ref = std::is_assignable_v< + std::add_lvalue_reference_t, + conditional_ref_t> + and std::is_assignable_v< + std::add_lvalue_reference_t, + conditional_ref_t>; template static constexpr bool is_nullable_v = mpl::is_type_instance_of_v; @@ -236,7 +237,7 @@ namespace sparrow * private: * std::vector m_values; * std::vector m_flags; - * + * * public: * * using reference = nullable; @@ -287,28 +288,25 @@ namespace sparrow using flag_const_reference = typename flag_traits::const_reference; using flag_rvalue_reference = typename flag_traits::rvalue_reference; using flag_const_rvalue_reference = typename flag_traits::const_rvalue_reference; - + template constexpr nullable() noexcept : m_value() , m_null_flag(false) { } - + template constexpr nullable(nullval_t) noexcept : m_value() , m_null_flag(false) { } - + template - requires ( - not std::same_as> and - std::constructible_from - ) - explicit (not std::convertible_to) - constexpr nullable(U&& value) noexcept(noexcept(T(std::declval()))) + requires(not std::same_as> and std::constructible_from) + explicit(not std::convertible_to) constexpr nullable(U&& value + ) noexcept(noexcept(T(std::declval()))) : m_value(std::forward(value)) , m_null_flag(true) { @@ -317,12 +315,10 @@ namespace sparrow constexpr nullable(const self_type&) = default; template - requires ( - impl::both_constructible_from_cref and - not impl::initializable_from_refs> - ) - explicit(not impl::both_convertible_from_cref) - SPARROW_CONSTEXPR nullable(const nullable& rhs) + requires(impl::both_constructible_from_cref + and not impl::initializable_from_refs>) + explicit(not impl::both_convertible_from_cref) SPARROW_CONSTEXPR + nullable(const nullable& rhs) : m_value(rhs.get()) , m_null_flag(rhs.null_flag()) { @@ -330,12 +326,9 @@ namespace sparrow #ifdef __clang__ template - requires ( - impl::both_constructible_from_cref and - std::same_as, bool> - ) - explicit(not impl::both_convertible_from_cref) - SPARROW_CONSTEXPR nullable(const nullable& rhs) + requires(impl::both_constructible_from_cref and std::same_as, bool>) + explicit(not impl::both_convertible_from_cref) SPARROW_CONSTEXPR + nullable(const nullable& rhs) : m_value(rhs.get()) , m_null_flag(rhs.null_flag()) { @@ -345,12 +338,10 @@ namespace sparrow constexpr nullable(self_type&&) noexcept = default; template - requires ( - impl::both_constructible_from_cond_ref and - not impl::initializable_from_refs> - ) - explicit(not impl::both_convertible_from_cond_ref) - SPARROW_CONSTEXPR nullable(nullable&& rhs) + requires(impl::both_constructible_from_cond_ref + and not impl::initializable_from_refs>) + explicit(not impl::both_convertible_from_cond_ref) SPARROW_CONSTEXPR + nullable(nullable&& rhs) : m_value(std::move(rhs).get()) , m_null_flag(std::move(rhs).null_flag()) { @@ -358,18 +349,16 @@ namespace sparrow #ifdef __clang__ template - requires ( - impl::both_constructible_from_cond_ref and - std::same_as, bool> - ) - explicit(not impl::both_convertible_from_cond_ref) - SPARROW_CONSTEXPR nullable(nullable&& rhs) + requires(impl::both_constructible_from_cond_ref + and std::same_as, bool>) + explicit(not impl::both_convertible_from_cond_ref) SPARROW_CONSTEXPR + nullable(nullable&& rhs) : m_value(std::move(rhs).get()) , m_null_flag(std::move(rhs).null_flag()) { } #endif - + constexpr nullable(value_type&& value, flag_type&& null_flag) : m_value(std::move(value)) , m_null_flag(std::move(null_flag)) @@ -401,10 +390,7 @@ namespace sparrow } template - requires( - not std::same_as and - std::assignable_from, TO> - ) + requires(not std::same_as and std::assignable_from, TO>) constexpr self_type& operator=(TO&& rhs) { m_value = std::forward(rhs); @@ -420,11 +406,7 @@ namespace sparrow } template - requires( - impl::both_assignable_from_cref and - not impl::initializable_from_refs> and - not impl::assignable_from_refs> - ) + requires(impl::both_assignable_from_cref and not impl::initializable_from_refs> and not impl::assignable_from_refs>) constexpr self_type& operator=(const nullable& rhs) { m_value = rhs.get(); @@ -440,11 +422,7 @@ namespace sparrow } template - requires( - impl::both_assignable_from_cond_ref and - not impl::initializable_from_refs> and - not impl::assignable_from_refs> - ) + requires(impl::both_assignable_from_cond_ref and not impl::initializable_from_refs> and not impl::assignable_from_refs>) constexpr self_type& operator=(nullable&& rhs) { m_value = std::move(rhs).get(); @@ -456,22 +434,22 @@ namespace sparrow constexpr bool has_value() const noexcept; constexpr flag_reference null_flag() & noexcept; - constexpr flag_const_reference null_flag() const & noexcept; + constexpr flag_const_reference null_flag() const& noexcept; constexpr flag_rvalue_reference null_flag() && noexcept; - constexpr flag_const_rvalue_reference null_flag() const && noexcept; + constexpr flag_const_rvalue_reference null_flag() const&& noexcept; constexpr reference get() & noexcept; - constexpr const_reference get() const & noexcept; + constexpr const_reference get() const& noexcept; constexpr rvalue_reference get() && noexcept; - constexpr const_rvalue_reference get() const && noexcept; - + constexpr const_rvalue_reference get() const&& noexcept; + constexpr reference value() &; - constexpr const_reference value() const &; + constexpr const_reference value() const&; constexpr rvalue_reference value() &&; - constexpr const_rvalue_reference value() const &&; + constexpr const_rvalue_reference value() const&&; template - constexpr value_type value_or(U&& default_value) const &; + constexpr value_type value_or(U&& default_value) const&; template constexpr value_type value_or(U&& default_value) &&; @@ -498,12 +476,12 @@ namespace sparrow template constexpr std::strong_ordering operator<=>(const nullable& lhs, nullval_t) noexcept; - + template constexpr bool operator==(const nullable& lhs, const U& rhs) noexcept; template - requires (!impl::is_nullable_v && std::three_way_comparable_with) + requires(!impl::is_nullable_v && std::three_way_comparable_with) constexpr std::compare_three_way_result_t operator<=>(const nullable& lhs, const U& rhs) noexcept; @@ -518,14 +496,14 @@ namespace sparrow // to their argument, making the deduction impossible. template constexpr nullable make_nullable(T&& value, B&& flag = true); - + /** * variant of nullable, exposing has_value for convenience * * @tparam T the list of nullable in the variant */ template - requires (is_nullable_v && ...) + requires(is_nullable_v && ...) class nullable_variant : public std::variant { public: @@ -548,16 +526,13 @@ namespace std { namespace mpl = sparrow::mpl; - // Specialization of basic_common_reference for nullable proxies so + // Specialization of basic_common_reference for nullable proxies so // we can use ranges algorithm on iterators returning nullable - template class TQual, template class UQual> + template class TQual, template class UQual> struct basic_common_reference, sparrow::nullable, TQual, UQual> { - using type = sparrow::nullable< - std::common_reference_t, UQual>, - std::common_reference_t, UQual> - >; + using type = sparrow:: + nullable, UQual>, std::common_reference_t, UQual>>; }; } @@ -584,13 +559,13 @@ namespace sparrow { return m_null_flag; } - + template - constexpr auto nullable::null_flag() const & noexcept -> flag_const_reference + constexpr auto nullable::null_flag() const& noexcept -> flag_const_reference { return m_null_flag; } - + template constexpr auto nullable::null_flag() && noexcept -> flag_rvalue_reference { @@ -603,9 +578,9 @@ namespace sparrow return flag_rvalue_reference(m_null_flag); } } - + template - constexpr auto nullable::null_flag() const && noexcept -> flag_const_rvalue_reference + constexpr auto nullable::null_flag() const&& noexcept -> flag_const_rvalue_reference { if constexpr (std::is_reference_v) { @@ -624,11 +599,11 @@ namespace sparrow } template - constexpr auto nullable::get() const & noexcept -> const_reference + constexpr auto nullable::get() const& noexcept -> const_reference { return m_value; } - + template constexpr auto nullable::get() && noexcept -> rvalue_reference { @@ -643,7 +618,7 @@ namespace sparrow } template - constexpr auto nullable::get() const && noexcept -> const_rvalue_reference + constexpr auto nullable::get() const&& noexcept -> const_rvalue_reference { if constexpr (std::is_reference_v) { @@ -663,12 +638,12 @@ namespace sparrow } template - constexpr auto nullable::value() const & -> const_reference + constexpr auto nullable::value() const& -> const_reference { throw_if_null(); return get(); } - + template constexpr auto nullable::value() && -> rvalue_reference { @@ -677,7 +652,7 @@ namespace sparrow } template - constexpr auto nullable::value() const && -> const_rvalue_reference + constexpr auto nullable::value() const&& -> const_rvalue_reference { throw_if_null(); return std::move(*this).get(); @@ -685,16 +660,16 @@ namespace sparrow template template - constexpr auto nullable::value_or(U&& default_value) const & -> value_type + constexpr auto nullable::value_or(U&& default_value) const& -> value_type { - return *this ? get() : value_type(std::forward(default_value)); + return *this ? get() : value_type(std::forward(default_value)); } template template constexpr auto nullable::value_or(U&& default_value) && -> value_type { - return *this ? get() : value_type(std::forward(default_value)); + return *this ? get() : value_type(std::forward(default_value)); } template @@ -710,7 +685,7 @@ namespace sparrow { m_null_flag = false; } - + template void nullable::throw_if_null() const { @@ -737,7 +712,7 @@ namespace sparrow { return lhs <=> false; } - + template constexpr bool operator==(const nullable& lhs, const U& rhs) noexcept { @@ -745,9 +720,8 @@ namespace sparrow } template - requires (!impl::is_nullable_v && std::three_way_comparable_with) - constexpr std::compare_three_way_result_t - operator<=>(const nullable& lhs, const U& rhs) noexcept + requires(!impl::is_nullable_v && std::three_way_comparable_with) + constexpr std::compare_three_way_result_t operator<=>(const nullable& lhs, const U& rhs) noexcept { return lhs ? lhs.get() <=> rhs : std::strong_ordering::less; } @@ -776,37 +750,40 @@ namespace sparrow ***********************************/ template - requires (is_nullable_v && ...) - constexpr nullable_variant& - nullable_variant::operator=(const nullable_variant& rhs) + requires(is_nullable_v && ...) + constexpr nullable_variant& nullable_variant::operator=(const nullable_variant& rhs) { base_type::operator=(rhs); return *this; } template - requires (is_nullable_v && ...) - constexpr nullable_variant& - nullable_variant::operator=(nullable_variant&& rhs) + requires(is_nullable_v && ...) + constexpr nullable_variant& nullable_variant::operator=(nullable_variant&& rhs) { base_type::operator=(std::move(rhs)); return *this; } - + template - requires (is_nullable_v && ...) + requires(is_nullable_v && ...) constexpr nullable_variant::operator bool() const { return has_value(); } template - requires (is_nullable_v && ...) + requires(is_nullable_v && ...) constexpr bool nullable_variant::has_value() const { - return std::visit([](const auto& v) { return v.has_value(); }, *this); + return std::visit( + [](const auto& v) + { + return v.has_value(); + }, + *this + ); } } #undef SPARROW_CONSTEXPR - diff --git a/include/sparrow/utils/offsets.hpp b/include/sparrow/utils/offsets.hpp index 41a4bfd0..64e6d133 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 4d90dcb9..9961b10b 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/src/array_factory.cpp b/src/array_factory.cpp index f6f77132..0b01acd9 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,94 +43,96 @@ 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::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::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 ff7157a8..c4575feb 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_array_schema_proxy.cpp b/src/arrow_array_schema_proxy.cpp index 37606626..5b89bc53 100644 --- a/src/arrow_array_schema_proxy.cpp +++ b/src/arrow_array_schema_proxy.cpp @@ -678,14 +678,13 @@ namespace sparrow void arrow_proxy::update_null_count() { - if(has_bitmap(data_type())) + if (has_bitmap(data_type())) { const auto& validity_buffer = buffers().front(); const dynamic_bitset_view bitmap(validity_buffer.data(), length() + offset()); const auto null_count = bitmap.null_count(); set_null_count(static_cast(null_count)); } - } bool arrow_proxy::is_arrow_array_valid() const diff --git a/src/arrow_interface/arrow_array.cpp b/src/arrow_interface/arrow_array.cpp index 74301a71..e5a10476 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,7 +109,11 @@ 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::LIST: return {make_valid_buffer(), make_buffer(1, (size + 1) * 4)}; case data_type::LARGE_LIST: @@ -123,11 +124,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: @@ -135,24 +136,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 dcf587c5..7ec5d91b 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 b7b590c6..6b3cf9f3 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 b92c6c1c..ab5e2460 100644 --- a/src/list_value.cpp +++ b/src/list_value.cpp @@ -13,10 +13,11 @@ // limitations under the License. #include "sparrow/layout/list_layout/list_value.hpp" -#include "sparrow/layout/dispatch.hpp" #include +#include "sparrow/layout/dispatch.hpp" + namespace sparrow { list_value::list_value(const array_wrapper* flat_array, size_type index_begin, size_type index_end) @@ -24,7 +25,7 @@ namespace sparrow , m_index_begin(index_begin) , m_index_end(index_end) { - SPARROW_ASSERT_TRUE(index_begin<=index_end); + SPARROW_ASSERT_TRUE(index_begin <= index_end); } auto list_value::size() const -> size_type diff --git a/src/run_encoded_array.cpp b/src/run_encoded_array.cpp index a5d56082..f9d47295 100644 --- a/src/run_encoded_array.cpp +++ b/src/run_encoded_array.cpp @@ -1,26 +1,25 @@ -#include "sparrow/layout/run_end_encoded_layout/run_end_encoded_array.hpp" +#include "sparrow/array.hpp" #include "sparrow/layout/array_helper.hpp" #include "sparrow/layout/dispatch.hpp" #include "sparrow/layout/primitive_array.hpp" -#include "sparrow/array.hpp" +#include "sparrow/layout/run_end_encoded_layout/run_end_encoded_array.hpp" + +namespace sparrow +{ + template + concept usable_array = mpl::is_type_instance_of_v + && (std::same_as + || std::same_as + || std::same_as); -namespace sparrow -{ - template - concept usable_array = - mpl::is_type_instance_of_v && ( - std::same_as || - std::same_as || - std::same_as); - auto run_end_encoded_array::get_acc_lengths_ptr(const array_wrapper& ar) -> acc_length_ptr_variant_type { return visit( [](const auto& actual_arr) -> acc_length_ptr_variant_type { using array_type = std::decay_t; - - if constexpr(usable_array) + + if constexpr (usable_array) { return actual_arr.data(); } @@ -38,11 +37,7 @@ namespace sparrow return visit( [i, this](const auto& acc_lengths_ptr) -> array_traits::const_reference { - const auto it = std::upper_bound( - acc_lengths_ptr, - acc_lengths_ptr + this->m_encoded_length, - i - ); + const auto it = std::upper_bound(acc_lengths_ptr, acc_lengths_ptr + this->m_encoded_length, i); // std::lower_bound returns an iterator, so we need to convert it to an index const auto index = static_cast(std::distance(acc_lengths_ptr, it)); return array_element(*p_encoded_values_array, static_cast(index)); @@ -51,10 +46,8 @@ namespace sparrow ); } - std::pair run_end_encoded_array::extract_length_and_null_count( - const array& acc_lengths_arr, - const array& encoded_values_arr - ) + std::pair + run_end_encoded_array::extract_length_and_null_count(const array& acc_lengths_arr, const array& encoded_values_arr) { SPARROW_ASSERT_TRUE(acc_lengths_arr.size() == encoded_values_arr.size()); @@ -64,32 +57,35 @@ namespace sparrow // visit the acc_lengths array std::int64_t length = 0; std::int64_t null_count = 0; - acc_lengths_arr.visit([&](const auto& acc_lengths_array) + acc_lengths_arr.visit( + [&](const auto& acc_lengths_array) { - if constexpr(usable_array>) - { + if constexpr (usable_array>) + { auto acc_length_data = acc_lengths_array.data(); // get the length of the array (ie last element in the acc_lengths array) length = acc_length_data[raw_size - 1]; - if(raw_null_count == 0){ + if (raw_null_count == 0) + { return; } - for(std::size_t i = 0; i < raw_size; ++i) + for (std::size_t i = 0; i < raw_size; ++i) { // check if the value is null - if(!encoded_values_arr[i].has_value()) + if (!encoded_values_arr[i].has_value()) { // how often is this value repeated? - const auto run_length = i == 0 ? acc_length_data[i] : acc_length_data[i] - acc_length_data[i - 1]; + const auto run_length = i == 0 ? acc_length_data[i] + : acc_length_data[i] - acc_length_data[i - 1]; null_count += run_length; raw_null_count -= 1; - if(raw_null_count == 0){ + if (raw_null_count == 0) + { return; } } } - } else { @@ -100,12 +96,8 @@ namespace sparrow return {null_count, length}; }; - - auto run_end_encoded_array::create_proxy( - array && acc_lengths, - array && encoded_values - ) -> arrow_proxy - { + auto run_end_encoded_array::create_proxy(array&& acc_lengths, array&& encoded_values) -> arrow_proxy + { auto [null_count, length] = extract_length_and_null_count(acc_lengths, encoded_values); auto [acc_length_array, acc_length_schema] = extract_arrow_structures(std::move(acc_lengths)); @@ -124,24 +116,24 @@ namespace sparrow ArrowSchema schema = make_arrow_schema( std::string("+r"), - std::nullopt, // name - std::nullopt, // metadata - std::nullopt, // flags, + std::nullopt, // name + std::nullopt, // metadata + std::nullopt, // flags, n_children, - child_schemas, // children - nullptr // dictionary + child_schemas, // children + nullptr // dictionary ); std::vector> arr_buffs = {}; ArrowArray arr = make_arrow_array( - static_cast(length), // length + static_cast(length), // length static_cast(null_count), - 0, // offset + 0, // offset std::move(arr_buffs), - n_children, // n_children - child_arrays, // children - nullptr // dictionary + n_children, // n_children + child_arrays, // children + nullptr // dictionary ); return arrow_proxy{std::move(arr), std::move(schema)}; diff --git a/src/struct_value.cpp b/src/struct_value.cpp index 2e41181a..b32d89cf 100644 --- a/src/struct_value.cpp +++ b/src/struct_value.cpp @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "sparrow/layout/nested_value_types.hpp" #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) + struct_value::struct_value(const std::vector& children, size_type index) : p_children(&children) , m_index(index) { diff --git a/test/better_junit_reporter.hpp b/test/better_junit_reporter.hpp index 038c8ed5..3a9ceee2 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 205c1781..64a0f4f8 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 c7f1ca4f..645e921f 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); diff --git a/test/junit_xml_writer.hpp b/test/junit_xml_writer.hpp index 8ec1439b..2796f933 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 d260caa2..8b956a4d 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_arrow_array.cpp b/test/test_arrow_array.cpp index 4a7fc0e8..7ae9d2a5 100644 --- a/test/test_arrow_array.cpp +++ b/test/test_arrow_array.cpp @@ -38,15 +38,7 @@ TEST_SUITE("C Data Interface") children[0] = new ArrowArray(); children[1] = new ArrowArray(); ArrowArray* dictionary = new ArrowArray(); - auto array = sparrow::make_arrow_array( - 1, - 0, - 0, - buffers_dummy, - 2, - children, - dictionary - ); + auto array = sparrow::make_arrow_array(1, 0, 0, buffers_dummy, 2, children, dictionary); array.release(&array); CHECK_EQ(array.buffers, nullptr); diff --git a/test/test_buffer_adaptor.cpp b/test/test_buffer_adaptor.cpp index d7763377..2472c53e 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 da255407..fc7f5aab 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 f1f6114b..4371aed7 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 d57970fe..955a7253 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 fc97976b..120e55e9 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.cpp b/test/test_decimal.cpp index e12bc685..133c0848 100644 --- a/test/test_decimal.cpp +++ b/test/test_decimal.cpp @@ -12,21 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "doctest/doctest.h" - -#include -#include #include +#include #include +#include -#include #include +#include + +#include "doctest/doctest.h" // ignore -Wdouble-promotion #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdouble-promotion" +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wdouble-promotion" #endif @@ -34,13 +34,14 @@ namespace sparrow { using testing_types = std::tuple< - int32_t - ,int64_t - #ifndef SPARROW_USE_LARGE_INT_PLACEHOLDERS - ,int128_t - ,int256_t - #endif - >; + int32_t, + int64_t +#ifndef SPARROW_USE_LARGE_INT_PLACEHOLDERS + , + int128_t, + int256_t +#endif + >; TEST_SUITE("decimals") @@ -56,18 +57,18 @@ namespace sparrow decimal_type d; auto storage = d.storage(); CHECK_EQ(static_cast(storage), 0); - + // float - auto as_float = static_cast(d); + auto as_float = static_cast(d); // cast to double: CHECK_EQ(as_float, doctest::Approx(0.0)); // double - auto as_double = static_cast(d); + auto as_double = static_cast(d); CHECK_EQ(as_double, doctest::Approx(0.0)); // string - auto as_string = std::string(d); + auto as_string = std::string(d); CHECK_EQ(as_string, "0"); } @@ -76,17 +77,17 @@ namespace sparrow decimal_type d(42, 0); auto storage = d.storage(); CHECK_EQ(static_cast(storage), 42); - + // float - auto as_float = static_cast(d); + auto as_float = static_cast(d); CHECK_EQ(as_float, doctest::Approx(42.0)); // double - auto as_double = static_cast(d); + auto as_double = static_cast(d); CHECK_EQ(as_double, doctest::Approx(42.0)); // string - auto as_string = std::string(d); + auto as_string = std::string(d); CHECK_EQ(as_string, "42"); } @@ -97,17 +98,17 @@ namespace sparrow decimal_type d(42, 1); auto storage = d.storage(); CHECK_EQ(static_cast(storage), 42); - + // float - auto as_float = static_cast(d); + auto as_float = static_cast(d); CHECK_EQ(as_float, doctest::Approx(4.2)); // double - auto as_double = static_cast(d); + auto as_double = static_cast(d); CHECK_EQ(as_double, doctest::Approx(4.20)); // string - auto as_string = std::string(d); + auto as_string = std::string(d); CHECK_EQ(as_string, "4.2"); } SUBCASE("neg") @@ -115,17 +116,17 @@ namespace sparrow decimal_type d(-42, 1); auto storage = d.storage(); CHECK_EQ(static_cast(storage), -42); - + // float - auto as_float = static_cast(d); + auto as_float = static_cast(d); CHECK_EQ(as_float, doctest::Approx(-4.2)); // double - auto as_double = static_cast(d); + auto as_double = static_cast(d); CHECK_EQ(as_double, doctest::Approx(-4.20)); // string - auto as_string = std::string(d); + auto as_string = std::string(d); CHECK_EQ(as_string, "-4.2"); } } @@ -136,17 +137,17 @@ namespace sparrow decimal_type d(42, -1); auto storage = d.storage(); CHECK_EQ(static_cast(storage), 42); - + // float - auto as_float = static_cast(d); + auto as_float = static_cast(d); CHECK_EQ(as_float, doctest::Approx(420.0)); // double - auto as_double = static_cast(d); + auto as_double = static_cast(d); CHECK_EQ(as_double, doctest::Approx(420.0)); // string - auto as_string = std::string(d); + auto as_string = std::string(d); CHECK_EQ(as_string, "420"); } SUBCASE("neg") @@ -154,42 +155,48 @@ namespace sparrow decimal_type d(-42, -1); auto storage = d.storage(); CHECK_EQ(static_cast(storage), -42); - + // float - auto as_float = static_cast(d); + auto as_float = static_cast(d); CHECK_EQ(as_float, doctest::Approx(-420.0)); // double - auto as_double = static_cast(d); + auto as_double = static_cast(d); CHECK_EQ(as_double, doctest::Approx(-420.0)); // string - auto as_string = std::string(d); + auto as_string = std::string(d); CHECK_EQ(as_string, "-420"); } } SUBCASE("generic") { - std::vector values = {-123,-122, -111, -100, -99, 10, 11, 100, 101, 110, 111, 122, 123}; - std::vector scales = {-3, -2, -1, 0, 1, 2, -4}; + std::vector values = {-123, -122, -111, -100, -99, 10, 11, 100, 101, 110, 111, 122, 123}; + std::vector scales = {-3, -2, -1, 0, 1, 2, -4}; // cross product - for(auto value : values) + for (auto value : values) { - for(auto scale : scales) + for (auto scale : scales) { decimal_type d(value, scale); auto storage = d.storage(); CHECK_EQ(static_cast(storage), value); - + // float - auto as_float = static_cast(d); - CHECK_EQ(as_float, doctest::Approx(static_cast(value) / static_cast(std::pow(10, scale)))); + auto as_float = static_cast(d); + CHECK_EQ( + as_float, + doctest::Approx(static_cast(value) / static_cast(std::pow(10, scale))) + ); // double - auto as_double = static_cast(d); - CHECK_EQ(as_double, doctest::Approx(static_cast(value) / static_cast(std::pow(10, scale)))); + auto as_double = static_cast(d); + CHECK_EQ( + as_double, + doctest::Approx(static_cast(value) / static_cast(std::pow(10, scale))) + ); } } } @@ -215,7 +222,7 @@ namespace sparrow {decimal_type(-1, 3), "-0.001"}, {decimal_type(-1, -1), "-10"}, {decimal_type(-1, -2), "-100"}, - {decimal_type(-1, -3), "-1000"}, + {decimal_type(-1, -3), "-1000"}, {decimal_type(123456789, 0), "123456789"}, {decimal_type(123456789, 1), "12345678.9"}, {decimal_type(123456789, 2), "1234567.89"}, @@ -260,18 +267,17 @@ namespace sparrow {decimal_type(-123456789, 20), "-0.00000000000123456789"}, }; - for(auto [d, expected] : data) + for (auto [d, expected] : data) { - auto as_string = std::string(d); + auto as_string = std::string(d); CHECK_EQ(as_string, expected); } } - } TEST_CASE_TEMPLATE_APPLY(decimal_test_id, testing_types); } } #ifdef __GNUC__ -#pragma GCC diagnostic pop +# pragma GCC diagnostic pop #endif \ No newline at end of file diff --git a/test/test_decimal_array.cpp b/test/test_decimal_array.cpp index 97cb9f5f..32deb68b 100644 --- a/test/test_decimal_array.cpp +++ b/test/test_decimal_array.cpp @@ -16,34 +16,30 @@ #include #include - #include "sparrow/layout/decimal_array.hpp" + #include "test_utils.hpp" namespace sparrow { using integer_types = std::tuple< - std::int32_t - ,std::int64_t - #ifndef SPARROW_USE_LARGE_INT_PLACEHOLDERS - ,int128_t - ,int256_t - #endif - >; + std::int32_t, + std::int64_t +#ifndef SPARROW_USE_LARGE_INT_PLACEHOLDERS + , + int128_t, + int256_t +#endif + >; TEST_SUITE("decimal_array") { TEST_CASE_TEMPLATE_DEFINE("generic", INTEGER_TYPE, decimal_array_test_generic_id) - { + { using integer_type = INTEGER_TYPE; - u8_buffer buffer{ - integer_type(10), - integer_type(20), - integer_type(33), - integer_type(111) - }; + u8_buffer buffer{integer_type(10), integer_type(20), integer_type(33), integer_type(111)}; std::size_t precision = 2; int scale = 4; decimal_array> array{std::move(buffer), precision, scale}; @@ -53,7 +49,7 @@ namespace sparrow CHECK_EQ(val.scale(), scale); CHECK_EQ(static_cast(val.storage()), 10); CHECK_EQ(static_cast(val), doctest::Approx(0.001)); - + val = array[1].value(); CHECK_EQ(val.scale(), scale); CHECK_EQ(static_cast(val.storage()), 20); @@ -63,8 +59,7 @@ namespace sparrow CHECK_EQ(val.scale(), scale); CHECK_EQ(static_cast(val.storage()), 33); CHECK_EQ(static_cast(val), doctest::Approx(0.0033)); - } TEST_CASE_TEMPLATE_APPLY(decimal_array_test_generic_id, integer_types); } -} // namespace sparrow \ No newline at end of file +} // namespace sparrow \ No newline at end of file diff --git a/test/test_dispatch.cpp b/test/test_dispatch.cpp index 1859fab2..ecc5efd2 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 9be78c80..63c29c7e 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 1e5f1494..37878190 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 8967160b..f05e81eb 100644 --- a/test/test_list_value.cpp +++ b/test/test_list_value.cpp @@ -12,13 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "sparrow/layout/primitive_array.hpp" #include "sparrow/layout/list_layout/list_value.hpp" +#include "sparrow/layout/primitive_array.hpp" #include "sparrow/layout/struct_layout/struct_value.hpp" -#include "doctest/doctest.h" - #include "../test/external_array_data_creation.hpp" +#include "doctest/doctest.h" namespace sparrow { @@ -48,10 +47,13 @@ namespace sparrow list_value l(&w, begin, end); for (std::size_t i = begin; i < end; ++i) { - CHECK_EQ(l[i].has_value(), ar[begin+i].has_value()); - if (ar[begin+i].has_value()) + CHECK_EQ(l[i].has_value(), ar[begin + i].has_value()); + if (ar[begin + i].has_value()) { - CHECK_EQ(std::get::const_reference>(l[i]).value(), ar[begin+i].value()); + CHECK_EQ( + std::get::const_reference>(l[i]).value(), + ar[begin + i].value() + ); } } } diff --git a/test/test_memory.cpp b/test/test_memory.cpp index 0d459a81..52bc83f3 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 9bfddea0..4049659c 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 cea3a86b..18918116 100644 --- a/test/test_null_array.cpp +++ b/test/test_null_array.cpp @@ -16,9 +16,8 @@ #include "sparrow/layout/null_array.hpp" -#include "doctest/doctest.h" - #include "../test/external_array_data_creation.hpp" +#include "doctest/doctest.h" namespace sparrow { @@ -118,4 +117,3 @@ namespace sparrow } } } - diff --git a/test/test_nullable.cpp b/test/test_nullable.cpp index db96b1c8..7fcc8d24 100644 --- a/test/test_nullable.cpp +++ b/test/test_nullable.cpp @@ -93,13 +93,17 @@ namespace sparrow return *this; } - const int& get_value() const { return m_value; } + const int& get_value() const + { + return m_value; + } private: int m_value; bool m_moved = false; }; + int Custom::counter = 0; bool operator==(const Custom& lhs, const Custom& rhs) @@ -122,10 +126,7 @@ namespace sparrow return lhs.get_value() <=> rhs; } - using testing_types = std::tuple< - double, - std::string, - Custom>; + using testing_types = std::tuple; namespace { @@ -135,37 +136,79 @@ namespace sparrow template <> struct fixture { - static double init() { return 1.2; } - static double other() { return 2.5; } - static int convert_init() { return 3; } + static double init() + { + return 1.2; + } + + static double other() + { + return 2.5; + } + + static int convert_init() + { + return 3; + } using convert_type = int; - static bool check_move_count(int) { return true; } + static bool check_move_count(int) + { + return true; + } }; template <> struct fixture { - static std::string init() { return "And now young codebase ..."; } - static std::string other() { return "Darth Codius"; } - static const char* convert_init() { return "Noooooo that's impossible!"; } + static std::string init() + { + return "And now young codebase ..."; + } + + static std::string other() + { + return "Darth Codius"; + } + + static const char* convert_init() + { + return "Noooooo that's impossible!"; + } using convert_type = const char*; - static bool check_move_count(int) { return true; } + static bool check_move_count(int) + { + return true; + } }; template <> struct fixture { - static Custom init() { return Custom(1); } - static Custom other() { return Custom(2); } - static int convert_init() { return 3; } + static Custom init() + { + return Custom(1); + } + + static Custom other() + { + return Custom(2); + } + + static int convert_init() + { + return 3; + } using convert_type = int; - static bool check_move_count(int ref) { return Custom::counter == ref; } + static bool check_move_count(int ref) + { + return Custom::counter == ref; + } }; } @@ -583,14 +626,12 @@ namespace sparrow TEST_SUITE("nullable proxy") { static_assert(std::is_convertible_v< - sparrow::nullable &&, - sparrow::nullable> - ); + sparrow::nullable&&, + sparrow::nullable>); static_assert(std::is_convertible_v< - const sparrow::nullable&, - sparrow::nullable> - ); + const sparrow::nullable&, + sparrow::nullable>); TEST_CASE_TEMPLATE_DEFINE("constructors", T, constructors_id) { @@ -935,7 +976,13 @@ namespace sparrow nullable d = vd; nullable_variant_type v = d; - bool res = std::visit([vd](const auto& val) { return val.has_value() && val.value() == vd; }, v); + bool res = std::visit( + [vd](const auto& val) + { + return val.has_value() && val.value() == vd; + }, + v + ); CHECK(res); } @@ -965,4 +1012,3 @@ namespace sparrow } } } - diff --git a/test/test_record_batch.cpp b/test/test_record_batch.cpp index 9fcd18b3..0824b11e 100644 --- a/test/test_record_batch.cpp +++ b/test/test_record_batch.cpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "sparrow/record_batch.hpp" #include "sparrow/layout/primitive_array.hpp" +#include "sparrow/record_batch.hpp" #include "doctest/doctest.h" @@ -21,14 +21,19 @@ namespace sparrow { std::vector make_array_list(const std::size_t data_size) { - primitive_array pr0(std::ranges::iota_view{std::size_t(0), std::size_t(data_size)} - | std::views::transform([](auto i){ - return static_cast(i);}) - ); + primitive_array pr0( + std::ranges::iota_view{std::size_t(0), std::size_t(data_size)} + | std::views::transform( + [](auto i) + { + return static_cast(i); + } + ) + ); primitive_array pr1(std::ranges::iota_view{std::int32_t(4), 4 + std::int32_t(data_size)}); primitive_array pr2(std::ranges::iota_view{std::int32_t(2), 2 + std::int32_t(data_size)}); - std::vector arr_list = { array(std::move(pr0)), array(std::move(pr1)), array(std::move(pr2)) }; + std::vector arr_list = {array(std::move(pr0)), array(std::move(pr1)), array(std::move(pr2))}; return arr_list; } @@ -40,7 +45,6 @@ namespace sparrow record_batch make_record_batch(const std::size_t data_size) { - return record_batch(make_name_list(), make_array_list(data_size)); } @@ -61,10 +65,7 @@ namespace sparrow { auto col_list = make_array_list(col_size); - record_batch record = { - { "first", col_list[0]}, - { "second", col_list[1]}, - { "third", col_list[2]} }; + record_batch record = {{"first", col_list[0]}, {"second", col_list[1]}, {"third", col_list[2]}}; CHECK_EQ(record.nb_columns(), 3u); CHECK_EQ(record.nb_rows(), 10u); } @@ -111,7 +112,7 @@ namespace sparrow { auto record = make_record_batch(col_size); auto name_list = make_name_list(); - for (const auto& name: name_list) + for (const auto& name : name_list) { CHECK(record.contains_column(name)); } @@ -162,4 +163,3 @@ namespace sparrow } } } - diff --git a/test/test_run_end_encoded_array.cpp b/test/test_run_end_encoded_array.cpp index ee89084c..1ee355e5 100644 --- a/test/test_run_end_encoded_array.cpp +++ b/test/test_run_end_encoded_array.cpp @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "sparrow/array.hpp" +#include "sparrow/layout/dispatch.hpp" #include "sparrow/layout/primitive_array.hpp" +#include "sparrow/layout/run_end_encoded_layout/run_end_encoded_array.hpp" #include "sparrow/utils/nullable.hpp" -#include "sparrow/layout/dispatch.hpp" + +#include "../test/external_array_data_creation.hpp" #include "doctest/doctest.h" #include "test_utils.hpp" -#include "../test/external_array_data_creation.hpp" -#include "sparrow/layout/run_end_encoded_layout/run_end_encoded_array.hpp" - -#include "sparrow/array.hpp" namespace sparrow { @@ -42,30 +42,31 @@ namespace sparrow // if alterate is true, all 42s will be replaced by 43s // this is to test EQ/NEQ after copy/move - + // encoded values primitive_array encoded_values( std::vector{ inner_value_type(1), inner_value_type(), // to check if arrays differ / are the same - alterate ? inner_value_type(43): inner_value_type(42), + alterate ? inner_value_type(43) : inner_value_type(42), inner_value_type(), - inner_value_type(9) + inner_value_type(9) }, - std::vector{1,3} // where we have no value + std::vector{1, 3} // where we have no value ); // accumulated lengths - primitive_array acc_lengths{{acc_type(1), acc_type(3), acc_type(6), acc_type(7), acc_type(8)}}; + primitive_array acc_lengths{ + {acc_type(1), acc_type(3), acc_type(6), acc_type(7), acc_type(8)} + }; array acc_lengths_array(std::move(acc_lengths)); array encoded_values_array(std::move(encoded_values)); - + return run_end_encoded_array(std::move(acc_lengths_array), std::move(encoded_values_array)); } } - TEST_SUITE("run_length_encoded") { @@ -81,15 +82,15 @@ namespace sparrow // check size REQUIRE(rle_array.size() == n); - std::vector expected_bitmap{1,0,0,1,1,1,0,1}; - std::vector expected_values{1,0,0, 42,42, 42,0,9}; - + std::vector expected_bitmap{1, 0, 0, 1, 1, 1, 0, 1}; + std::vector expected_values{1, 0, 0, 42, 42, 42, 0, 9}; + SUBCASE("copy") { run_end_encoded_array rle_array2(rle_array); CHECK_EQ(rle_array2, rle_array); - run_end_encoded_array rle_array3 = test::make_test_run_encoded_array(/*alterate=*/true); + run_end_encoded_array rle_array3 = test::make_test_run_encoded_array(/*alterate=*/true); CHECK_NE(rle_array3, rle_array); rle_array3 = rle_array; CHECK_EQ(rle_array3, rle_array); @@ -101,32 +102,41 @@ namespace sparrow run_end_encoded_array rle_array3(std::move(rle_array2)); CHECK_EQ(rle_array3, rle_array); - run_end_encoded_array rle_array4 = test::make_test_run_encoded_array(/*alterate*/true); + run_end_encoded_array rle_array4 = test::make_test_run_encoded_array(/*alterate*/ true); CHECK_NE(rle_array4, rle_array); rle_array4 = std::move(rle_array3); CHECK_EQ(rle_array4, rle_array); } - SUBCASE("operator[]"){ - //check elements - for(std::size_t i=0; i void { + std::visit( + [&](auto&& nullable) -> void + { using T = std::decay_t; using inner_type = std::decay_t; - if constexpr(std::is_same_v){ - if(nullable.has_value()){ + if constexpr (std::is_same_v) + { + if (nullable.has_value()) + { CHECK(nullable.value() == expected_values[i]); } - else{ + else + { CHECK(false); } } - else{ + else + { CHECK(false); } }, @@ -135,26 +145,35 @@ namespace sparrow } } } - SUBCASE("iterator"){ + SUBCASE("iterator") + { auto iter = rle_array.begin(); - //check elements - for(std::size_t i=0; ihas_value() == bool(expected_bitmap[i])); - if(iter->has_value()){ + if (iter->has_value()) + { auto val = *iter; - std::visit([&]( auto && nullable) -> void { + std::visit( + [&](auto&& nullable) -> void + { using T = std::decay_t; using inner_type = std::decay_t; - if constexpr(std::is_same_v){ - if(nullable.has_value()){ + if constexpr (std::is_same_v) + { + if (nullable.has_value()) + { CHECK(nullable.value() == expected_values[i]); } - else{ + else + { CHECK(false); } } - else{ + else + { CHECK(false); } }, @@ -165,10 +184,9 @@ namespace sparrow } } SUBCASE("consitency") - { + { test::generic_consistency_test(rle_array); } } } } - diff --git a/test/test_struct_array.cpp b/test/test_struct_array.cpp index eba566a5..a6a94a4f 100644 --- a/test/test_struct_array.cpp +++ b/test/test_struct_array.cpp @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "sparrow/array.hpp" #include "sparrow/layout/primitive_array.hpp" #include "sparrow/layout/struct_layout/struct_array.hpp" #include "sparrow/utils/nullable.hpp" +#include "../test/external_array_data_creation.hpp" #include "doctest/doctest.h" - #include "test_utils.hpp" -#include "../test/external_array_data_creation.hpp" -#include "sparrow/array.hpp" namespace sparrow { @@ -33,37 +32,51 @@ namespace sparrow std::vector children_arrays(2); std::vector children_schemas(2); - test::fill_schema_and_array(children_schemas[0], children_arrays[0], n, 0/*offset*/, {}); + test::fill_schema_and_array(children_schemas[0], children_arrays[0], n, 0 /*offset*/, {}); children_schemas[0].name = "item 0"; - test::fill_schema_and_array(children_schemas[1], children_arrays[1], n, 0/*offset*/, {}); + test::fill_schema_and_array(children_schemas[1], children_arrays[1], n, 0 /*offset*/, {}); children_schemas[1].name = "item 1"; ArrowArray arr{}; ArrowSchema schema{}; - test::fill_schema_and_array_for_struct_layout(schema, arr, std::move(children_schemas), std::move(children_arrays), {}); + test::fill_schema_and_array_for_struct_layout( + schema, + arr, + std::move(children_schemas), + std::move(children_arrays), + {} + ); return arrow_proxy(std::move(arr), std::move(schema)); } } TEST_SUITE("struct_array") - { + { static_assert(is_struc_array_v); TEST_CASE("constructors") { - primitive_array flat_arr({{std::int16_t(0), std::int16_t(1), std::int16_t(2), std::int16_t(3)}}); + primitive_array flat_arr( + {{std::int16_t(0), std::int16_t(1), std::int16_t(2), std::int16_t(3)}} + ); primitive_array flat_arr2({{4.0f, 5.0f, 6.0f, 7.0f}}); - primitive_array flat_arr3({{std::int32_t(8), std::int32_t(9), std::int32_t(10), std::int32_t(11)}}); + primitive_array flat_arr3( + {{std::int32_t(8), std::int32_t(9), std::int32_t(10), std::int32_t(11)}} + ); // detyped arrays - std::vector children = {array(std::move(flat_arr)), array(std::move(flat_arr2)), array(std::move(flat_arr3))}; + std::vector children = { + array(std::move(flat_arr)), + array(std::move(flat_arr2)), + array(std::move(flat_arr3)) + }; struct_array arr(std::move(children)); // check the size REQUIRE_EQ(arr.size(), 4); - + // check the children REQUIRE_EQ(arr[0].value().size(), 3); REQUIRE_EQ(arr[1].value().size(), 3); @@ -78,19 +91,17 @@ namespace sparrow CHECK_NULLABLE_VARIANT_EQ(arr[1].value()[0], std::int16_t(1)); CHECK_NULLABLE_VARIANT_EQ(arr[1].value()[1], float(5.0f)); CHECK_NULLABLE_VARIANT_EQ(arr[1].value()[2], std::int32_t(9)); - + CHECK_NULLABLE_VARIANT_EQ(arr[2].value()[0], std::int16_t(2)); CHECK_NULLABLE_VARIANT_EQ(arr[2].value()[1], float(6.0f)); CHECK_NULLABLE_VARIANT_EQ(arr[2].value()[2], std::int32_t(10)); - - }; - TEST_CASE_TEMPLATE("struct[T, uint8]",T, std::uint8_t, std::int32_t, float, double) + TEST_CASE_TEMPLATE("struct[T, uint8]", T, std::uint8_t, std::int32_t, float, double) { using inner_scalar_type = T; - //using inner_nullable_type = nullable; + // using inner_nullable_type = nullable; // number of elements in the struct array const std::size_t n = 4; @@ -140,9 +151,9 @@ namespace sparrow REQUIRE(val1_variant.has_value()); - //using const_scalar_ref = const inner_scalar_type&; - using nullable_inner_scalar_type = nullable; - using nullable_uint8_t = nullable; + // using const_scalar_ref = const inner_scalar_type&; + using nullable_inner_scalar_type = nullable; + using nullable_uint8_t = nullable; // visit the variant std::visit( @@ -174,7 +185,6 @@ namespace sparrow }, val1_variant ); - } } @@ -185,12 +195,11 @@ namespace sparrow } SUBCASE("consistency") - { + { test::generic_consistency_test(struct_arr); - } + } } } } - diff --git a/test/test_traits.cpp b/test/test_traits.cpp index 85ae5455..7bcd14cd 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_union_array.cpp b/test/test_union_array.cpp index 1f90a4b2..23b552aa 100644 --- a/test/test_union_array.cpp +++ b/test/test_union_array.cpp @@ -12,72 +12,92 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "sparrow/array.hpp" +#include "sparrow/layout/dispatch.hpp" #include "sparrow/layout/primitive_array.hpp" +#include "sparrow/layout/union_array.hpp" #include "sparrow/utils/nullable.hpp" -#include "sparrow/layout/dispatch.hpp" -#include "doctest/doctest.h" -#include "test_utils.hpp" #include "../test/external_array_data_creation.hpp" - -#include "sparrow/layout/union_array.hpp" -#include "sparrow/array.hpp" +#include "doctest/doctest.h" +#include "test_utils.hpp" namespace sparrow { namespace test { - arrow_proxy make_sparse_union_proxy(const std::string& format_string, std::size_t n, bool altered = false) + arrow_proxy + make_sparse_union_proxy(const std::string& format_string, std::size_t n, bool altered = false) { std::vector children_arrays(2); std::vector children_schemas(2); - test::fill_schema_and_array(children_schemas[0], children_arrays[0], n, 0/*offset*/, {}); + test::fill_schema_and_array(children_schemas[0], children_arrays[0], n, 0 /*offset*/, {}); children_schemas[0].name = "item 0"; - test::fill_schema_and_array(children_schemas[1], children_arrays[1], n, 0/*offset*/, {}); + test::fill_schema_and_array(children_schemas[1], children_arrays[1], n, 0 /*offset*/, {}); children_schemas[1].name = "item 1"; ArrowArray arr{}; ArrowSchema schema{}; - std::vector type_ids = {std::uint8_t(3), std::uint8_t(4), std::uint8_t(3), std::uint8_t(4)}; + std::vector type_ids = + {std::uint8_t(3), std::uint8_t(4), std::uint8_t(3), std::uint8_t(4)}; if (altered) { type_ids[0] = std::uint8_t(4); } - + test::fill_schema_and_array_for_sparse_union( - schema, arr, std::move(children_schemas), std::move(children_arrays), type_ids, format_string + schema, + arr, + std::move(children_schemas), + std::move(children_arrays), + type_ids, + format_string ); return arrow_proxy(std::move(arr), std::move(schema)); } - arrow_proxy make_dense_union_proxy(const std::string& format_string, std::size_t n_c, bool altered = false) + arrow_proxy + make_dense_union_proxy(const std::string& format_string, std::size_t n_c, bool altered = false) { std::vector children_arrays(2); std::vector children_schemas(2); - test::fill_schema_and_array(children_schemas[0], children_arrays[0], n_c, 0/*offset*/, {}); + test::fill_schema_and_array(children_schemas[0], children_arrays[0], n_c, 0 /*offset*/, {}); children_schemas[0].name = "item 0"; - test::fill_schema_and_array(children_schemas[1], children_arrays[1], n_c, 0/*offset*/, {}); + test::fill_schema_and_array( + children_schemas[1], + children_arrays[1], + n_c, + 0 /*offset*/, + {} + ); children_schemas[1].name = "item 1"; ArrowArray arr{}; ArrowSchema schema{}; - std::vector type_ids = {std::uint8_t(3), std::uint8_t(4), std::uint8_t(3), std::uint8_t(4)}; + std::vector type_ids = + {std::uint8_t(3), std::uint8_t(4), std::uint8_t(3), std::uint8_t(4)}; if (altered) { type_ids[0] = std::uint8_t(4); } - std::vector offsets = {0,0,1,1}; - + std::vector offsets = {0, 0, 1, 1}; + test::fill_schema_and_array_for_dense_union( - schema, arr, std::move(children_schemas), std::move(children_arrays), type_ids, offsets, format_string + schema, + arr, + std::move(children_schemas), + std::move(children_arrays), + type_ids, + offsets, + format_string ); return arrow_proxy(std::move(arr), std::move(schema)); @@ -85,33 +105,35 @@ namespace sparrow } TEST_SUITE("sparse_union") - { + { static_assert(is_sparse_union_array_v); static_assert(!is_dense_union_array_v); TEST_CASE("constructor") - { + { // the child arrays primitive_array arr1({{std::int16_t(2), std::int16_t(5), std::size_t(9)}}); primitive_array arr2( std::vector{std::int32_t(3), std::int32_t(4), std::size_t(5)}, - std::vector{1} // INDEX 1 IS MISSING - ); + std::vector{1} // INDEX 1 IS MISSING + ); // detyped arrays std::vector children = {array(std::move(arr1)), array(std::move(arr2))}; - + SUBCASE("with mapping") { // type ids - sparse_union_array::type_id_buffer_type type_ids{{std::uint8_t(2), std::uint8_t(3), std::uint8_t(3)}}; + sparse_union_array::type_id_buffer_type type_ids{ + {std::uint8_t(2), std::uint8_t(3), std::uint8_t(3)} + }; // mapping std::vector type_mapping{2, 3}; // the array - sparse_union_array arr( std::move(children), std::move(type_ids), std::move(type_mapping)); + sparse_union_array arr(std::move(children), std::move(type_ids), std::move(type_mapping)); // check the size REQUIRE_EQ(arr.size(), 3); @@ -127,10 +149,12 @@ namespace sparrow SUBCASE("without mapping") { // type ids - sparse_union_array::type_id_buffer_type type_ids{{std::uint8_t(0), std::uint8_t(1), std::uint8_t(1)}}; + sparse_union_array::type_id_buffer_type type_ids{ + {std::uint8_t(0), std::uint8_t(1), std::uint8_t(1)} + }; // the array - sparse_union_array arr( std::move(children), std::move(type_ids)); + sparse_union_array arr(std::move(children), std::move(type_ids)); // check the size REQUIRE_EQ(arr.size(), 3); @@ -143,11 +167,9 @@ namespace sparrow CHECK_NULLABLE_VARIANT_EQ(arr[0], std::int16_t(2)); CHECK_NULLABLE_VARIANT_EQ(arr[2], std::int32_t(5)); } - } TEST_CASE("basics") { - const std::string format_string = "+us:3,4"; const std::size_t n = 4; @@ -188,92 +210,108 @@ namespace sparrow REQUIRE(val.has_value()); } - // 0 - std::visit([](auto&& arg) { - using inner_type = std::decay_t< typename std::decay_t::value_type>; - if constexpr (std::is_same_v) + // 0 + std::visit( + [](auto&& arg) { - REQUIRE_EQ(0.0f, arg.value()); - } - else - { - CHECK(false); - } - - }, uarr[0]); + using inner_type = std::decay_t::value_type>; + if constexpr (std::is_same_v) + { + REQUIRE_EQ(0.0f, arg.value()); + } + else + { + CHECK(false); + } + }, + uarr[0] + ); // 1 - std::visit([](auto&& arg) { - using inner_type = std::decay_t< typename std::decay_t::value_type>; - if constexpr (std::is_same_v) + std::visit( + [](auto&& arg) { - REQUIRE_EQ(1, arg.value()); - } - else + using inner_type = std::decay_t::value_type>; + if constexpr (std::is_same_v) + { + REQUIRE_EQ(1, arg.value()); + } + else + { + CHECK(false); + } + }, + uarr[1] + ); + + // 2 + std::visit( + [](auto&& arg) { - CHECK(false); - } - - }, uarr[1]); - - // 2 - std::visit([](auto&& arg) { - using inner_type = std::decay_t< typename std::decay_t::value_type>; - if constexpr (std::is_same_v) - { - REQUIRE_EQ(2.0f, arg.value()); - } - else + using inner_type = std::decay_t::value_type>; + if constexpr (std::is_same_v) + { + REQUIRE_EQ(2.0f, arg.value()); + } + else + { + CHECK(false); + } + }, + uarr[2] + ); + + // 3 + std::visit( + [](auto&& arg) { - CHECK(false); - } - - }, uarr[2]); - - // 3 - std::visit([](auto&& arg) { - using inner_type = std::decay_t< typename std::decay_t::value_type>; - if constexpr (std::is_same_v) - { - REQUIRE_EQ(3, arg.value()); - } - else - { - CHECK(false); - } - - }, uarr[3]); - + using inner_type = std::decay_t::value_type>; + if constexpr (std::is_same_v) + { + REQUIRE_EQ(3, arg.value()); + } + else + { + CHECK(false); + } + }, + uarr[3] + ); } } } + TEST_SUITE("dense_union") { static_assert(is_dense_union_array_v); static_assert(!is_sparse_union_array_v); TEST_CASE("constructor") - { + { // the child arrays primitive_array arr1({{std::int16_t(0), std::int16_t(1)}}); primitive_array arr2( std::vector{std::int32_t(2), std::int32_t(3)}, - std::vector{1} // INDEX 1 IS MISSING - ); + std::vector{1} // INDEX 1 IS MISSING + ); // detyped arrays std::vector children = {array(std::move(arr1)), array(std::move(arr2))}; - + // offsets - dense_union_array::offset_buffer_type offsets{{std::size_t(1), std::size_t(1), std::size_t(0), std::size_t(0)}}; + dense_union_array::offset_buffer_type offsets{ + {std::size_t(1), std::size_t(1), std::size_t(0), std::size_t(0)} + }; SUBCASE("without mapping") { // type ids - dense_union_array::type_id_buffer_type type_ids{{std::uint8_t(0), std::uint8_t(1), std::uint8_t(0), std::uint8_t(1)}}; + dense_union_array::type_id_buffer_type type_ids{ + {std::uint8_t(0), std::uint8_t(1), std::uint8_t(0), std::uint8_t(1)} + }; // the array - dense_union_array arr( std::move(children), std::move(type_ids), std::move(offsets)); + dense_union_array arr(std::move(children), std::move(type_ids), std::move(offsets)); // check the size REQUIRE_EQ(arr.size(), 4); @@ -289,14 +327,20 @@ namespace sparrow CHECK_NULLABLE_VARIANT_EQ(arr[3], std::int32_t(2)); } SUBCASE("with mapping") - { - + { std::vector child_index_to_type_id{1, 0}; // type ids - dense_union_array::type_id_buffer_type type_ids{{std::uint8_t(1), std::uint8_t(0), std::uint8_t(1), std::uint8_t(0)}}; + dense_union_array::type_id_buffer_type type_ids{ + {std::uint8_t(1), std::uint8_t(0), std::uint8_t(1), std::uint8_t(0)} + }; // the array - dense_union_array arr( std::move(children), std::move(type_ids), std::move(offsets), std::move(child_index_to_type_id)); + dense_union_array arr( + std::move(children), + std::move(type_ids), + std::move(offsets), + std::move(child_index_to_type_id) + ); // check the size REQUIRE_EQ(arr.size(), 4); @@ -311,7 +355,6 @@ namespace sparrow CHECK_NULLABLE_VARIANT_EQ(arr[2], std::int16_t(0)); CHECK_NULLABLE_VARIANT_EQ(arr[3], std::int32_t(2)); } - } TEST_CASE("basics") { @@ -356,64 +399,75 @@ namespace sparrow } } - // 0 - std::visit([](auto&& arg) { - using inner_type = std::decay_t< typename std::decay_t::value_type>; - if constexpr (std::is_same_v) + // 0 + std::visit( + [](auto&& arg) { - REQUIRE_EQ(0.0f, arg.value()); - } - else - { - CHECK(false); - } - - }, uarr[0]); + using inner_type = std::decay_t::value_type>; + if constexpr (std::is_same_v) + { + REQUIRE_EQ(0.0f, arg.value()); + } + else + { + CHECK(false); + } + }, + uarr[0] + ); // 1 - std::visit([](auto&& arg) { - using inner_type = std::decay_t< typename std::decay_t::value_type>; - if constexpr (std::is_same_v) - { - REQUIRE_EQ(0, arg.value()); - } - else + std::visit( + [](auto&& arg) { - CHECK(false); - } - - }, uarr[1]); + using inner_type = std::decay_t::value_type>; + if constexpr (std::is_same_v) + { + REQUIRE_EQ(0, arg.value()); + } + else + { + CHECK(false); + } + }, + uarr[1] + ); - // 2 - std::visit([](auto&& arg) { - using inner_type = std::decay_t< typename std::decay_t::value_type>; - if constexpr (std::is_same_v) - { - REQUIRE_EQ(1.0f, arg.value()); - } - else + // 2 + std::visit( + [](auto&& arg) { - CHECK(false); - } - - }, uarr[2]); + using inner_type = std::decay_t::value_type>; + if constexpr (std::is_same_v) + { + REQUIRE_EQ(1.0f, arg.value()); + } + else + { + CHECK(false); + } + }, + uarr[2] + ); // 3 - std::visit([](auto&& arg) { - using inner_type = std::decay_t< typename std::decay_t::value_type>; - if constexpr (std::is_same_v) + std::visit( + [](auto&& arg) { - REQUIRE_EQ(1, arg.value()); - } - else - { - CHECK(false); - } - - }, uarr[3]); + using inner_type = std::decay_t::value_type>; + if constexpr (std::is_same_v) + { + REQUIRE_EQ(1, arg.value()); + } + else + { + CHECK(false); + } + }, + uarr[3] + ); } } } - diff --git a/test/test_utils.cpp b/test/test_utils.cpp index 63a68575..8f4a0870 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 ba433a1c..361dae90 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 0b3a98a2..a85dbcba 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 78c566fd..542ffdac 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 63a46825..67aeb754 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" }; @@ -39,9 +40,9 @@ namespace sparrow string_view_array array(words, where_nulls); - 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()); }