You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "llama90 (via GitHub)" <gi...@apache.org> on 2024/05/26 13:11:01 UTC

Re: [PR] GH-41668: [C++] Support cast kernel from list-like to (large) string [arrow]

llama90 commented on code in PR #41831:
URL: https://github.com/apache/arrow/pull/41831#discussion_r1615198228


##########
cpp/src/arrow/compute/kernels/scalar_cast_test.cc:
##########
@@ -2476,54 +2508,137 @@ TEST(Cast, ListToFSL) {
                               CastOptions::Safe(fixed_size_list(int32(), 3))));
 }
 
-TEST(Cast, CastMap) {
-  const std::string map_json =
-      "[[[\"x\", 1], [\"y\", 8], [\"z\", 9]], [[\"x\", 6]], [[\"y\", 36]]]";
-  const std::string map_json_nullable =
-      "[[[\"x\", 1], [\"y\", null], [\"z\", 9]], null, [[\"y\", 36]]]";
+TEST_F(TestCastToString, ListToString) {
+  // Example with int32 list, large list, list view and large list view
+  const std::vector<std::pair<std::shared_ptr<DataType>, std::string>> list_types = {
+      {list(int32()), R"([
+  "list<item: int32>[1, 2]",
+  "list<item: int32>[3]",
+  "list<item: int32>[]"
+])"},
+      {large_list(int32()), R"([
+  "large_list<item: int32>[1, 2]",
+  "large_list<item: int32>[3]",
+  "large_list<item: int32>[]"
+])"},
+      {list_view(int32()), R"([
+  "list_view<item: int32>[1, 2]",
+  "list_view<item: int32>[3]",
+  "list_view<item: int32>[]"
+])"},
+      {large_list_view(int32()), R"([
+  "large_list_view<item: int32>[1, 2]",
+  "large_list_view<item: int32>[3]",
+  "large_list_view<item: int32>[]"
+])"}};
+
+  const std::string list_json = R"([[1, 2], [3], []])";
+
+  for (const auto& [list_type, expected_str] : list_types) {
+    CheckCastToString(list_type, list_json, expected_str);
+  }
+
+  // Example with nested list of int32.  To avoid further code duplication, the code for
+  // large_list, list_view, and large_list_view is omitted.
+  const std::vector<std::pair<std::shared_ptr<DataType>, std::string>> nested_list_types =
+      {{list(list(int32())), R"([
+  "list<item: list<item: int32>>[list<item: int32>[1, 2], list<item: int32>[3]]",
+  "list<item: list<item: int32>>[list<item: int32>[4]]",
+  "list<item: list<item: int32>>[list<item: int32>[]]",
+  "list<item: list<item: int32>>[]"
+])"}};
+
+  const std::string nested_list_json = R"([[[1, 2], [3]], [[4]], [[]], []])";
+
+  for (const auto& [nested_list_type, expected_nested_str] : nested_list_types) {
+    CheckCastToString(nested_list_type, nested_list_json, expected_nested_str);
+  }
+}
+
+class TestMapScalar : public TestCastToString {

Review Comment:
   Just as `TestMapScalar` was written for `MapType`, I wanted to write similar classes for `List` and `FixedSizeList`.
   
   However, I found it too extensive to address within this PR, so I only covered `MapType`. 
   
   It would be better to create a separate issue to handle this.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org