alamb commented on code in PR #8735:
URL: https://github.com/apache/arrow-rs/pull/8735#discussion_r2608529164


##########
arrow-array/src/array/list_view_array.rs:
##########
@@ -498,6 +498,36 @@ impl<OffsetSize: OffsetSizeTrait> std::fmt::Debug for 
GenericListViewArray<Offse
     }
 }
 
+impl<OffsetSize: OffsetSizeTrait> From<GenericListArray<OffsetSize>>
+    for GenericListViewArray<OffsetSize>
+{
+    fn from(value: GenericListArray<OffsetSize>) -> Self {
+        let field = match value.data_type() {

Review Comment:
   you can use into_parts here to avoid clones and this unwrap
   
   I pushed this in 8494e6c1c4



##########
arrow-cast/src/cast/mod.rs:
##########
@@ -11866,4 +11887,327 @@ mod tests {
         // Verify the run-ends were cast correctly (run ends at 3, 6, 9)
         assert_eq!(run_array.run_ends().values(), &[3i64, 6i64, 9i64]);
     }
+
+    #[test]
+    fn test_cast_list_view_to_list() {
+        let list_view = ListViewArray::new(
+            Arc::new(Field::new("a", DataType::Int32, false)),
+            ScalarBuffer::from(vec![0, 3, 6]),
+            ScalarBuffer::from(vec![3, 3, 3]),
+            Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9])),
+            None,
+        );
+        let cast_result = cast(
+            &list_view,
+            &DataType::List(Arc::new(Field::new("a", DataType::Int32, false))),
+        )
+        .unwrap();
+        let got_list = 
cast_result.as_any().downcast_ref::<ListArray>().unwrap();
+
+        let mut offsets = OffsetBufferBuilder::new(0);
+        offsets.push_length(3);
+        offsets.push_length(3);
+        offsets.push_length(3);
+        let expected_list = ListArray::new(
+            Arc::new(Field::new("a", DataType::Int32, false)),
+            offsets.finish(),
+            Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9])),
+            None,
+        );
+        assert_eq!(got_list, &expected_list);

Review Comment:
   I think you could make this test significantly less verbose using 
ListArray::from_iter_primtive: 
https://docs.rs/arrow/latest/arrow/array/type.ListArray.html#method.from_iter_primitive
   
   I think now that I merged the PR from @dqkqd 
   - https://github.com/apache/arrow-rs/pull/8907
   
   there is an equivalent for ListViewArray as well
   
   



##########
arrow-cast/src/cast/mod.rs:
##########
@@ -11866,4 +11887,327 @@ mod tests {
         // Verify the run-ends were cast correctly (run ends at 3, 6, 9)
         assert_eq!(run_array.run_ends().values(), &[3i64, 6i64, 9i64]);
     }
+
+    #[test]
+    fn test_cast_list_view_to_list() {
+        let list_view = ListViewArray::new(
+            Arc::new(Field::new("a", DataType::Int32, false)),
+            ScalarBuffer::from(vec![0, 3, 6]),
+            ScalarBuffer::from(vec![3, 3, 3]),
+            Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9])),
+            None,
+        );
+        let cast_result = cast(
+            &list_view,
+            &DataType::List(Arc::new(Field::new("a", DataType::Int32, false))),
+        )
+        .unwrap();
+        let got_list = 
cast_result.as_any().downcast_ref::<ListArray>().unwrap();
+
+        let mut offsets = OffsetBufferBuilder::new(0);
+        offsets.push_length(3);
+        offsets.push_length(3);
+        offsets.push_length(3);
+        let expected_list = ListArray::new(
+            Arc::new(Field::new("a", DataType::Int32, false)),
+            offsets.finish(),
+            Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9])),
+            None,
+        );
+        assert_eq!(got_list, &expected_list);

Review Comment:
   I pushed commits that did this in  daba94d740cdfbcc1b9e35ca5b8ac9573c538cde 
and b94cdc1d0969f95bbe9cc230ddbbe5245c93a2b1 ( I found it really hard to review 
the tests without the simplification )



##########
arrow-cast/src/cast/mod.rs:
##########
@@ -153,7 +153,19 @@ pub fn can_cast_types(from_type: &DataType, to_type: 
&DataType) -> bool {
         (List(list_from) | LargeList(list_from), FixedSizeList(list_to, _)) => 
{
             can_cast_types(list_from.data_type(), list_to.data_type())
         }
+        (List(list_from) | LargeList(list_from), ListView(list_to) | 
LargeListView(list_to)) => {

Review Comment:
   I added a few clauses here -- can you please double check it @vegarsti ?



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