ZhangHuiGui commented on code in PR #41092:
URL: https://github.com/apache/arrow/pull/41092#discussion_r1561236690
##########
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:
Nice suggestion!
--
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]