Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precommit-fixes #311

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.5
hooks:
- id: clang-format
- id: clang-format
exclude_types: [javascript, json]
120 changes: 51 additions & 69 deletions examples/builder_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
*/


#include <vector>
#include <array>
#include <tuple>
#include <cassert>
#include <list>
#include <string>
#include <cassert>
#include <tuple>
#include <vector>

#include <sparrow/builder/builder.hpp>

void primitve_array()
{
{
//! [builder_primitive_array]
// using initializer_list
auto arr = sparrow::build({1, 2, 3, 4, 5});
Expand All @@ -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<int>(i);
});
auto iota = std::views::iota(1, 6)
| std::views::transform(
[](int i)
{
return static_cast<int>(i);
}
);
auto arr4 = sparrow::build(iota);
/////////////////////
// all of the arrays above are equivalent to the manually built array
Expand All @@ -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<sparrow::nullable<int>>({1, 2, sparrow::nullval, 4, 5});
Expand All @@ -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<int> {
return i == 3 ? sparrow::nullable<int>{} : sparrow::nullable<int>{i};
});
auto iota = std::views::iota(1, 6)
| std::views::transform(
[](int i) -> sparrow::nullable<int>
{
return i == 3 ? sparrow::nullable<int>{} : sparrow::nullable<int>{i};
}
);
auto arr4 = sparrow::build(iota);
// all of the arrays above are equivalent to the manually built array
std::vector<std::size_t> where_nulls{2};
Expand All @@ -68,49 +76,45 @@ 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<std::vector<std::string>> v{
{"hello", "world", "!"},
{"Another", "sentence"}
};
std::vector<std::vector<std::string>> 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<std::string>;
using nullable_string_vector = sparrow::nullable<string_vector>;
std::vector<nullable_string_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"}}
};
auto arr = sparrow::build(v);
//! [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)
],
[
Expand All @@ -119,85 +123,64 @@ void list_of_struct()
]
*/
std::vector<std::vector<std::tuple<int, float>>> v{
{
std::tuple<int, float>{1, 2.5},
std::tuple<int, float>{2, 3.5}
},
{
std::tuple<int, float>{3, 5.5},
std::tuple<int, float>{5, 6.5},
std::tuple<int, float>{6, 7.5}
},
{
std::tuple<int, float>{7, 8.5}
}
{std::tuple<int, float>{1, 2.5}, std::tuple<int, float>{2, 3.5}},
{std::tuple<int, float>{3, 5.5}, std::tuple<int, float>{5, 6.5}, std::tuple<int, float>{6, 7.5}},
{std::tuple<int, float>{7, 8.5}}
};
auto arr = sparrow::build(v);
//! [builder_list_of_struct]
}

void fixed_sized_list_strings()
{
{
//! [builder_fixed_sized_list_strings]
std::vector<std::array<std::string, 2>> v{
{"hello", "world"},
{"Another", "sentence"},
{"This", "is"}
};
std::vector<std::array<std::string, 2>> 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<int, float>;
using array_type = std::array<variant_type, 2>;
std::vector<array_type> v{
{1, 2.5f},
{2, 3.5f},
{3, 4.5f}
};
std::vector<array_type> v{{1, 2.5f}, {2, 3.5f}, {3, 4.5f}};
auto arr = sparrow::build(v);
//! [builder_fixed_sized_list_of_union]
}

void dict_encoded_variable_sized_binary()
{
//! [builder_dict_encoded_variable_sized_binary]
sparrow::dict_encode<std::vector<std::string>> v{
std::vector<std::string>{
"hello",
"world",
"hello",
"world",
"hello",
}
};
sparrow::dict_encode<std::vector<std::string>> v{std::vector<std::string>{
"hello",
"world",
"hello",
"world",
"hello",
}};
auto arr = sparrow::build(v);
//! [builder_dict_encoded_variable_sized_binary]
}

void run_end_encoded_variable_sized_binary()
{
//! [builder_run_end_encoded_variable_sized_binary]
sparrow::run_end_encode<std::vector<std::string>> v{
std::vector<std::string>{
"hello",
"hello",
"hello",
"world",
"world",
}
};
sparrow::run_end_encode<std::vector<std::string>> v{std::vector<std::string>{
"hello",
"hello",
"hello",
"world",
"world",
}};
auto arr = sparrow::build(v);
//! [builder_run_end_encoded_variable_sized_binary]
}

void struct_array()
{
//! [builder_struct_array]
using tuple_type = std::tuple<int, std::array<std::string, 2>, sparrow::nullable<float>>;
using tuple_type = std::tuple<int, std::array<std::string, 2>, sparrow::nullable<float>>;
std::vector<tuple_type> v{
{1, {"hello", "world"}, 2.5f},
{2, {"Another", "sentence"}, sparrow::nullval},
Expand All @@ -210,7 +193,7 @@ void struct_array()
void sparse_union_array()
{
//! [builder_union_array]
using variant_type = std::variant<int, std::array<std::string, 2>, sparrow::nullable<float>>;
using variant_type = std::variant<int, std::array<std::string, 2>, sparrow::nullable<float>>;
std::vector<variant_type> v{
int{1},
std::array<std::string, 2>{{"A", "sentence"}},
Expand All @@ -221,7 +204,6 @@ void sparse_union_array()
//! [builder_union_array]
}


int main()
{
primitve_array();
Expand Down
17 changes: 9 additions & 8 deletions examples/typed_array_high_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* The range can be a range of values or a range of nullable values.
*/

//#include <sparrow/array/array_data.hpp>
// #include <sparrow/array/array_data.hpp>


/*void example_typed_array_of_floats(){
using value_type = float;
std::vector<value_type> data = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};

// construct the array
auto array = sparrow::typed_array<value_type>(data);

Expand All @@ -34,7 +34,7 @@ void example_typed_array_of_strings(){
"four",
"five"
};

// construct the array
auto array = sparrow::typed_array<value_type>(data);

Expand All @@ -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<value_type>(data);

Expand All @@ -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;
}
5 changes: 3 additions & 2 deletions examples/typed_array_low_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* The typed_array is created from the array_data and the data is accessed.
*/

//#include <sparrow/array/array_data.hpp>
// #include <sparrow/array/array_data.hpp>

int main() {
int main()
{
/////////////////////////////////////////////////
// create array_data with 5 float32 elements
// where the value at index 2 is missing
Expand Down
2 changes: 1 addition & 1 deletion include/sparrow/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace sparrow
{
template <layout A>
requires (not std::is_lvalue_reference_v<A>)
requires(not std::is_lvalue_reference_v<A>)
array::array(A&& a)
: p_array(new array_wrapper_impl<A>(std::move(a)))
{
Expand Down
2 changes: 1 addition & 1 deletion include/sparrow/array_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
namespace sparrow
{
SPARROW_API cloning_ptr<array_wrapper> array_factory(arrow_proxy proxy);

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace sparrow

BufferType m_buffers;
std::vector<std::uint8_t*> m_buffers_pointers;

};

constexpr arrow_array_private_data::arrow_array_private_data(BufferType buffers, std::size_t children_size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions include/sparrow/arrow_interface/arrow_array_schema_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T>
requires std::same_as<T, ArrowArray> || std::same_as<T, ArrowSchema>
requires std::same_as<T, ArrowArray> || std::same_as<T, ArrowSchema>
void release_common_arrow(T& t);

/**
Expand Down Expand Up @@ -174,14 +174,14 @@ namespace sparrow
}

template <class T>
requires std::same_as<T, ArrowArray> || std::same_as<T, ArrowSchema>
requires std::same_as<T, ArrowArray> || std::same_as<T, ArrowSchema>
void release_common_arrow(T& t)
{
if (t.release == nullptr)
{
return;
}

if (t.dictionary)
{
if (t.dictionary->release)
Expand Down
Loading
Loading