tustvold commented on code in PR #5340:
URL: https://github.com/apache/arrow-rs/pull/5340#discussion_r1470887252


##########
arrow-cast/src/cast.rs:
##########
@@ -802,6 +804,9 @@ pub fn cast_with_options(
         }
         (_, List(ref to)) => cast_values_to_list::<i32>(array, to, 
cast_options),
         (_, LargeList(ref to)) => cast_values_to_list::<i64>(array, to, 
cast_options),
+        (_, FixedSizeList(ref to, size)) if size.eq(&1_i32) => {
+            cast_values_to_fixed_size_list(array, to, size, cast_options)

Review Comment:
   ```suggestion
               cast_values_to_fixed_size_list(array, to, *size, cast_options)
   ```
   



##########
arrow-cast/src/cast.rs:
##########
@@ -141,6 +141,8 @@ pub fn can_cast_types(from_type: &DataType, to_type: 
&DataType) -> bool {
         }
         (_, List(list_to)) => can_cast_types(from_type, list_to.data_type()),
         (_, LargeList(list_to)) => can_cast_types(from_type, 
list_to.data_type()),
+        (_, FixedSizeList(list_to,size)) if size.eq(&1_i32) => {

Review Comment:
   ```suggestion
           (_, FixedSizeList(list_to,size)) if *size == 1 => {
   ```
   



##########
arrow-cast/src/cast.rs:
##########
@@ -7609,6 +7626,36 @@ mod tests {
         assert_eq!(expected.values(), actual.values());
     }
 
+    #[test]
+    fn test_cast_utf8_to_list() {
+        // DataType::List
+        let array = Arc::new(StringArray::from(vec!["5"])) as ArrayRef;
+        let field = Arc::new(Field::new("", DataType::Int32, false));
+        let list_array = cast(&array, &DataType::List(field.clone())).unwrap();
+        let actual = list_array.as_any().downcast_ref::<ListArray>().unwrap();
+        let expect = ListArray::from_iter_primitive::<Int32Type, _, 
_>([Some([Some(5)])]);
+        assert_eq!(&expect.value(0), &actual.value(0));
+
+        // DataType::LargeList
+        let list_array = cast(&array, 
&DataType::LargeList(field.clone())).unwrap();
+        let actual = list_array
+            .as_any()
+            .downcast_ref::<LargeListArray>()

Review Comment:
   Can we use AsArray please



##########
arrow-cast/src/cast.rs:
##########
@@ -3040,6 +3045,18 @@ fn cast_values_to_list<O: OffsetSizeTrait>(
     Ok(Arc::new(list))
 }
 
+/// Helper function that takes a primitive array and casts to a fixed size 
list array.
+fn cast_values_to_fixed_size_list(
+    array: &dyn Array,
+    to: &FieldRef,
+    size: &i32,

Review Comment:
   ```suggestion
       size: i32,
   ```
   



##########
arrow-cast/src/cast.rs:
##########
@@ -7609,6 +7626,36 @@ mod tests {
         assert_eq!(expected.values(), actual.values());
     }
 
+    #[test]
+    fn test_cast_utf8_to_list() {
+        // DataType::List
+        let array = Arc::new(StringArray::from(vec!["5"])) as ArrayRef;
+        let field = Arc::new(Field::new("", DataType::Int32, false));
+        let list_array = cast(&array, &DataType::List(field.clone())).unwrap();
+        let actual = list_array.as_any().downcast_ref::<ListArray>().unwrap();
+        let expect = ListArray::from_iter_primitive::<Int32Type, _, 
_>([Some([Some(5)])]);
+        assert_eq!(&expect.value(0), &actual.value(0));
+
+        // DataType::LargeList
+        let list_array = cast(&array, 
&DataType::LargeList(field.clone())).unwrap();
+        let actual = list_array
+            .as_any()
+            .downcast_ref::<LargeListArray>()
+            .unwrap();
+        let expect = LargeListArray::from_iter_primitive::<Int32Type, _, 
_>([Some([Some(5)])]);
+        assert_eq!(&expect.value(0), &actual.value(0));
+
+        // DataType::FixedSizeList
+        let list_array = cast(&array, &DataType::FixedSizeList(field.clone(), 
1)).unwrap();
+        let actual = list_array
+            .as_any()
+            .downcast_ref::<FixedSizeListArray>()
+            .unwrap();
+        let expect =
+            FixedSizeListArray::from_iter_primitive::<Int32Type, _, 
_>([Some([Some(5)])], 1);
+        assert_eq!(&expect.value(0), &actual.value(0));

Review Comment:
   ```suggestion
           assert_eq!(expect.value(0), actual.value(0));
   ```
   



##########
arrow-cast/src/cast.rs:
##########
@@ -7609,6 +7626,36 @@ mod tests {
         assert_eq!(expected.values(), actual.values());
     }
 
+    #[test]
+    fn test_cast_utf8_to_list() {
+        // DataType::List
+        let array = Arc::new(StringArray::from(vec!["5"])) as ArrayRef;
+        let field = Arc::new(Field::new("", DataType::Int32, false));
+        let list_array = cast(&array, &DataType::List(field.clone())).unwrap();
+        let actual = list_array.as_any().downcast_ref::<ListArray>().unwrap();
+        let expect = ListArray::from_iter_primitive::<Int32Type, _, 
_>([Some([Some(5)])]);
+        assert_eq!(&expect.value(0), &actual.value(0));
+
+        // DataType::LargeList
+        let list_array = cast(&array, 
&DataType::LargeList(field.clone())).unwrap();
+        let actual = list_array
+            .as_any()
+            .downcast_ref::<LargeListArray>()
+            .unwrap();
+        let expect = LargeListArray::from_iter_primitive::<Int32Type, _, 
_>([Some([Some(5)])]);
+        assert_eq!(&expect.value(0), &actual.value(0));

Review Comment:
   ```suggestion
           assert_eq!(expect.value(0), actual.value(0));
   ```
   



##########
arrow-cast/src/cast.rs:
##########
@@ -802,6 +804,9 @@ pub fn cast_with_options(
         }
         (_, List(ref to)) => cast_values_to_list::<i32>(array, to, 
cast_options),
         (_, LargeList(ref to)) => cast_values_to_list::<i64>(array, to, 
cast_options),
+        (_, FixedSizeList(ref to, size)) if size.eq(&1_i32) => {

Review Comment:
   ```suggestion
           (_, FixedSizeList(ref to, size)) if *size == 1 => {
   ```
   



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