ozankabak commented on code in PR #4168:
URL: https://github.com/apache/arrow-datafusion/pull/4168#discussion_r1019409860


##########
datafusion/common/src/scalar.rs:
##########
@@ -1881,13 +1881,22 @@ impl ScalarValue {
         index: usize,
         precision: u8,
         scale: u8,
-    ) -> ScalarValue {
-        let array = array.as_any().downcast_ref::<Decimal128Array>().unwrap();
-        if array.is_null(index) {
-            ScalarValue::Decimal128(None, precision, scale)
-        } else {
-            ScalarValue::Decimal128(Some(array.value(index)), precision, scale)
-        }
+    ) -> Result<ScalarValue> {
+        let array = match as_decimal128_array(array) {

Review Comment:
   Can you not do this with:
   ```rust
   let array = as_decimal128_array(array)?;
   if array.is_null(index) {
       Ok(ScalarValue::Decimal128(None, precision, scale))
   } else {
       let value = array.value(index);
       Ok(ScalarValue::Decimal128(Some(value), precision, scale))
   }
   ```



##########
datafusion/common/src/scalar.rs:
##########
@@ -2073,14 +2082,14 @@ impl ScalarValue {
         value: &Option<i128>,
         precision: u8,
         scale: u8,
-    ) -> bool {
-        let array = array.as_any().downcast_ref::<Decimal128Array>().unwrap();
+    ) -> Result<bool> {
+        let array = as_decimal128_array(array)?;
         if array.precision() != precision || array.scale() != scale {
-            return false;
+            return Ok(false);
         }
         match value {

Review Comment:
   Using `match` expressions with binary types like `Result` or `Option` is 
typically less idiomatic than using the `if let` expression. With this in mind, 
I suggest:
   ```rust
   let is_null = array.is_null(index);
   if let Some(v) = value {
     Ok(!is_null && array.value(index) == *v)
   } else {
     Ok(is_null)
   }
   ```



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