Jay846 commented on code in PR #50976:
URL: https://github.com/apache/arrow/pull/50976#discussion_r4033226500


##########
cpp/src/arrow/compute/kernels/scalar_cast_test.cc:
##########
@@ -3646,6 +3646,83 @@ TEST(Cast, ListToListOptionsPassthru) {
   }
 }
 
+TEST(Cast, ListViewToList) {
+  // 1. Contiguous ListView
+  auto contiguous_src = ArrayFromJSON(list_view(int16()), "[[10, 20], [30], 
[40, 50]]");
+  auto contiguous_expected = ArrayFromJSON(list(int16()), "[[10, 20], [30], 
[40, 50]]");
+  CheckCast(contiguous_src, contiguous_expected);
+
+  // Assert zero-copy for contiguous values
+  ASSERT_OK_AND_ASSIGN(auto cast_result, Cast(contiguous_src, list(int16())));
+  auto src_lv = std::dynamic_pointer_cast<ListViewArray>(contiguous_src);
+  auto res_list = 
std::dynamic_pointer_cast<ListArray>(cast_result.make_array());
+  ASSERT_EQ(res_list->values()->data()->buffers[1]->address(),
+            src_lv->values()->data()->buffers[1]->address());
+
+  // 2. Gapped/Non-contiguous ListView
+  auto values = ArrayFromJSON(int16(), "[10, 20, 999, 30, 40, 50]");
+  auto offsets = ArrayFromJSON(int32(), "[0, 3]");
+  auto sizes = ArrayFromJSON(int32(), "[2, 3]");
+  ASSERT_OK_AND_ASSIGN(auto gapped_src,
+                       ListViewArray::FromArrays(*offsets, *sizes, *values));
+  auto gapped_expected = ArrayFromJSON(list(int16()), "[[10, 20], [30, 40, 
50]]");
+  CheckCast(gapped_src, gapped_expected);
+
+  // 3. Overlapping ListView
+  auto overlapping_offsets = ArrayFromJSON(int32(), "[0, 1]");
+  auto overlapping_sizes = ArrayFromJSON(int32(), "[2, 2]");
+  ASSERT_OK_AND_ASSIGN(
+      auto overlapping_src,
+      ListViewArray::FromArrays(*overlapping_offsets, *overlapping_sizes, 
*values));
+  auto overlapping_expected = ArrayFromJSON(list(int16()), "[[10, 20], [20, 
999]]");
+  CheckCast(overlapping_src, overlapping_expected);
+
+  // 4. Large ListView to List and vice versa
+  auto large_contiguous_src =
+      ArrayFromJSON(large_list_view(int16()), "[[10, 20], [30], [40, 50]]");
+  auto large_contiguous_expected =
+      ArrayFromJSON(large_list(int16()), "[[10, 20], [30], [40, 50]]");
+  CheckCast(large_contiguous_src, large_contiguous_expected);
+  CheckCast(contiguous_src, large_contiguous_expected);
+  CheckCast(large_contiguous_src, contiguous_expected);
+
+  // 5. Null Propagation

Review Comment:
   Added null entries to the contiguous test examples



-- 
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]

Reply via email to