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


##########
datafusion/common/src/scalar.rs:
##########
@@ -579,24 +581,44 @@ fn dict_from_values<K: ArrowDictionaryKeyType>(
 
 macro_rules! typed_cast_tz {
     ($array:expr, $index:expr, $ARRAYTYPE:ident, $SCALAR:ident, $TZ:expr) => {{
-        let array = $array.as_any().downcast_ref::<$ARRAYTYPE>().unwrap();
-        ScalarValue::$SCALAR(
+        use std::any::type_name;
+        let array = $array
+            .as_any()
+            .downcast_ref::<$ARRAYTYPE>()
+            .ok_or_else(|| {
+                DataFusionError::Internal(format!(
+                    "could not cast value to {}",
+                    type_name::<$ARRAYTYPE>()
+                ))
+            })?;

Review Comment:
   `typed_cast_tz` macro is called by 
[`try_from_array`](https://github.com/apache/arrow-datafusion/blob/main/datafusion/common/src/scalar.rs#L2021-L2022).
 `try_from_array` is a public function.  Depending on what `array` value the 
user passes to the function, downcasting the array to a timestamp array can 
fail. 
   
   This error is reachable and recoverable. It makes sense to  return an 
internal error here. This aligns with how downcast error is handled in the 
[downcast_value](https://github.com/apache/arrow-datafusion/blob/main/datafusion/common/src/lib.rs#L73)
 macro.



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