junjunjd commented on code in PR #7901:
URL: https://github.com/apache/arrow-datafusion/pull/7901#discussion_r1378446881


##########
datafusion/common/src/scalar.rs:
##########
@@ -1309,27 +1338,33 @@ impl ScalarValue {
 
         macro_rules! build_array_list_primitive {
             ($ARRAY_TY:ident, $SCALAR_TY:ident, $NATIVE_TYPE:ident) => {{
-                Arc::new(ListArray::from_iter_primitive::<$ARRAY_TY, _, _>(
-                    scalars.into_iter().map(|x| match x {
-                        ScalarValue::List(arr) => {
-                            if 
arr.as_any().downcast_ref::<NullArray>().is_some() {
-                                None
-                            } else {
-                                let list_arr = as_list_array(&arr);
-                                let primitive_arr =
-                                    
list_arr.values().as_primitive::<$ARRAY_TY>();
-                                Some(
-                                    
primitive_arr.into_iter().collect::<Vec<Option<_>>>(),
-                                )
+                Ok::<ArrayRef, 
DataFusionError>(Arc::new(ListArray::from_iter_primitive::<$ARRAY_TY, _, _>(
+                    scalars
+                        .into_iter()
+                        .map(|x| match x {
+                            ScalarValue::List(arr) => {
+                                if 
arr.as_any().downcast_ref::<NullArray>().is_some() {
+                                    Ok(None)
+                                } else {
+                                    let list_arr = as_list_array(&arr);
+                                    let primitive_arr =
+                                        
list_arr.values().as_primitive::<$ARRAY_TY>();
+                                    Ok(Some(
+                                        primitive_arr
+                                            .into_iter()
+                                            .collect::<Vec<Option<_>>>(),
+                                    ))
+                                }
                             }
-                        }
-                        sv => panic!(
-                            "Inconsistent types in ScalarValue::iter_to_array. 
\
+                            sv => _internal_err!(
+                                "Inconsistent types in 
ScalarValue::iter_to_array. \

Review Comment:
   It appears that unreachable errors are handled inconsistently in 
`iter_to_array`. This error should be 
[unreachable](https://github.com/apache/arrow-datafusion/blob/main/datafusion/common/src/scalar.rs#L1277).
 However, all the other `build_*` macros defined in `iter_to_array` return an 
internal error (for example 
[`build_array_list_string`](https://github.com/apache/arrow-datafusion/blob/main/datafusion/common/src/scalar.rs#L1253),
 
[`build_array_primitive`](https://github.com/apache/arrow-datafusion/blob/main/datafusion/common/src/scalar.rs#L1145).
 I removed `panic` here to align with other `build_*` macros.
   This does not require any code change in client side, since `iter_to_array` 
already returns a Result.



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