felipecrv commented on code in PR #41092:
URL: https://github.com/apache/arrow/pull/41092#discussion_r1561148455
##########
cpp/src/arrow/array/array_list_test.cc:
##########
@@ -763,6 +763,50 @@ class TestListArray : public ::testing::Test {
<< flattened->ToString();
}
+ void TestFlattenRecursively() {
+ auto inner_type = std::make_shared<T>(int32());
+ auto type = std::make_shared<T>(inner_type);
+
+ // List type with two nested level: list(list(int32))
Review Comment:
there is a missing `s`, but it's better to cite `list` as just one example
because this test is templated on all the list types [1]:
```suggestion
// List type with two nested level: list(list(int32))
// A nested (2 levels) list array (e.g.: `list<list<int32>>`)
```
[1]:
```cpp
using ListAndListViewTypes =
::testing::Types<ListType, LargeListType, ListViewType,
LargeListViewType>;
```
##########
cpp/src/arrow/array/array_list_test.cc:
##########
@@ -763,6 +763,50 @@ class TestListArray : public ::testing::Test {
<< flattened->ToString();
}
+ void TestFlattenRecursively() {
+ auto inner_type = std::make_shared<T>(int32());
+ auto type = std::make_shared<T>(inner_type);
+
+ // List type with two nested level: list(list(int32))
+ auto nested_list_array =
std::dynamic_pointer_cast<ArrayType>(ArrayFromJSON(type, R"([
+ [[0, 1, 2], null, [3]],
+ [null],
+ [[2, 9], [4], [], [6, 5]]
+ ])"));
+ ASSERT_OK_AND_ASSIGN(auto flattened,
nested_list_array->FlattenRecursively());
+ ASSERT_OK(flattened->ValidateFull());
+ ASSERT_EQ(9, flattened->length());
+ ASSERT_TRUE(flattened->Equals(ArrayFromJSON(int32(), "[0, 1, 2, 3, 2, 9,
4, 6, 5]")));
+
+ // Empty nested list should flatten until reach it's non-list type
+ nested_list_array =
+ std::dynamic_pointer_cast<ArrayType>(ArrayFromJSON(type, R"([null])"));
+ ASSERT_OK_AND_ASSIGN(flattened, nested_list_array->FlattenRecursively());
+ ASSERT_TRUE(flattened->type()->Equals(int32()));
+
+ // List type with three nested level: list(list(list(int32)))
Review Comment:
Same suggestion as in the comment above.
But it would be good to make one of these a `fixed_size_list` because this
test is not exercising that flatten function (e.g.:
`list<list<fixed_size_list<int32, 3>>>`).
##########
cpp/src/arrow/array/array_list_test.cc:
##########
@@ -763,6 +763,50 @@ class TestListArray : public ::testing::Test {
<< flattened->ToString();
}
+ void TestFlattenRecursively() {
+ auto inner_type = std::make_shared<T>(int32());
+ auto type = std::make_shared<T>(inner_type);
+
+ // List type with two nested level: list(list(int32))
+ auto nested_list_array =
std::dynamic_pointer_cast<ArrayType>(ArrayFromJSON(type, R"([
+ [[0, 1, 2], null, [3]],
+ [null],
+ [[2, 9], [4], [], [6, 5]]
+ ])"));
Review Comment:
Throw in one `null` in the `int32` values as well.
##########
cpp/src/arrow/array/array_list_test.cc:
##########
@@ -763,6 +763,50 @@ class TestListArray : public ::testing::Test {
<< flattened->ToString();
}
+ void TestFlattenRecursively() {
+ auto inner_type = std::make_shared<T>(int32());
+ auto type = std::make_shared<T>(inner_type);
+
+ // List type with two nested level: list(list(int32))
+ auto nested_list_array =
std::dynamic_pointer_cast<ArrayType>(ArrayFromJSON(type, R"([
+ [[0, 1, 2], null, [3]],
+ [null],
+ [[2, 9], [4], [], [6, 5]]
+ ])"));
Review Comment:
indentation
```suggestion
[[0, 1, 2], null, [3]],
[null],
[[2, 9], [4], [], [6, 5]]
])"));
```
##########
cpp/src/arrow/array/array_list_test.cc:
##########
@@ -763,6 +763,50 @@ class TestListArray : public ::testing::Test {
<< flattened->ToString();
}
+ void TestFlattenRecursively() {
+ auto inner_type = std::make_shared<T>(int32());
+ auto type = std::make_shared<T>(inner_type);
+
+ // List type with two nested level: list(list(int32))
+ auto nested_list_array =
std::dynamic_pointer_cast<ArrayType>(ArrayFromJSON(type, R"([
+ [[0, 1, 2], null, [3]],
+ [null],
+ [[2, 9], [4], [], [6, 5]]
+ ])"));
+ ASSERT_OK_AND_ASSIGN(auto flattened,
nested_list_array->FlattenRecursively());
+ ASSERT_OK(flattened->ValidateFull());
+ ASSERT_EQ(9, flattened->length());
+ ASSERT_TRUE(flattened->Equals(ArrayFromJSON(int32(), "[0, 1, 2, 3, 2, 9,
4, 6, 5]")));
+
+ // Empty nested list should flatten until reach it's non-list type
Review Comment:
```suggestion
// Empty nested list should flatten until non-list type is reached
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]