andygrove commented on code in PR #3245:
URL: https://github.com/apache/arrow-datafusion/pull/3245#discussion_r956156901


##########
datafusion/optimizer/src/pre_cast_lit_in_comparison.rs:
##########
@@ -214,47 +165,109 @@ fn is_comparison_op(op: &Operator) -> bool {
 }
 
 fn is_support_data_type(data_type: &DataType) -> bool {
-    // TODO support decimal with other data type
     matches!(
         data_type,
-        DataType::Int8 | DataType::Int16 | DataType::Int32 | DataType::Int64
+        DataType::Int8
+            | DataType::Int16
+            | DataType::Int32
+            | DataType::Int64
+            | DataType::Decimal128(_, _)
     )
 }
 
-fn can_integer_literal_cast_to_type(
-    integer_lit_value: &ScalarValue,
+fn try_cast_literal_to_type(
+    lit_value: &ScalarValue,
     target_type: &DataType,
-) -> Result<bool> {
-    if integer_lit_value.is_null() {
+) -> Result<Option<ScalarValue>> {
+    if lit_value.is_null() {
         // null value can be cast to any type of null value
-        return Ok(true);
+        return Ok(Some(ScalarValue::try_from(target_type)?));
     }
+    let mul = match target_type {
+        DataType::Int8 | DataType::Int16 | DataType::Int32 | DataType::Int64 
=> 1_i128,
+        DataType::Decimal128(_, scale) => 10_i128.pow(*scale as u32),
+        other_type => {
+            return Err(DataFusionError::Internal(format!(
+                "Error target data type {:?}",
+                other_type
+            )));
+        }
+    };
     let (target_min, target_max) = match target_type {
         DataType::Int8 => (i8::MIN as i128, i8::MAX as i128),
         DataType::Int16 => (i16::MIN as i128, i16::MAX as i128),
         DataType::Int32 => (i32::MIN as i128, i32::MAX as i128),
         DataType::Int64 => (i64::MIN as i128, i64::MAX as i128),
+        DataType::Decimal128(precision, _) => (
+            MIN_DECIMAL_FOR_EACH_PRECISION[*precision - 1],

Review Comment:
   Could you add a comment here to explain what is going on? 



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