junjunjd commented on code in PR #7901:
URL: https://github.com/apache/arrow-datafusion/pull/7901#discussion_r1378379142
##########
datafusion/common/src/scalar.rs:
##########
@@ -512,19 +516,19 @@ impl std::hash::Hash for ScalarValue {
pub fn get_dict_value<K: ArrowDictionaryKeyType>(
array: &dyn Array,
index: usize,
-) -> (&ArrayRef, Option<usize>) {
- let dict_array = as_dictionary_array::<K>(array).unwrap();
- (dict_array.values(), dict_array.key(index))
+) -> Result<(&ArrayRef, Option<usize>)> {
+ let dict_array = as_dictionary_array::<K>(array)?;
Review Comment:
This is a public function and `as_dictionary_array` can fail depending on
what `array` value the user passes to the function. The
[`downcast_value`](https://github.com/apache/arrow-datafusion/blob/main/datafusion/common/src/lib.rs#L73)
macro called by `as_dictionary_array` returns an internal error if the cast is
impossible.
Returning a `Result` here makes sense because this error is reachable and
recoverable (user can handle the error and only passes in arrays that can be
downcast to `DictionaryArray`).
This does not require any code change in client side.
--
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]