You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/01/17 14:07:25 UTC

[GitHub] [arrow-datafusion] alamb commented on a change in pull request #1554: support mathematics operation for decimal data type

alamb commented on a change in pull request #1554:
URL: https://github.com/apache/arrow-datafusion/pull/1554#discussion_r786034055



##########
File path: datafusion/src/physical_plan/coercion_rule/binary_rule.rs
##########
@@ -162,12 +162,141 @@ fn get_comparison_common_decimal_type(
     }
 }
 
+// Convert the numeric data type to the decimal data type.
+// Now, we just support the signed integer type and floating-point type.
+fn convert_numeric_type_to_decimal(numeric_type: &DataType) -> Option<DataType> {
+    match numeric_type {
+        DataType::Int8 => Some(DataType::Decimal(3, 0)),
+        DataType::Int16 => Some(DataType::Decimal(5, 0)),
+        DataType::Int32 => Some(DataType::Decimal(10, 0)),
+        DataType::Int64 => Some(DataType::Decimal(20, 0)),
+        // TODO if we convert the floating-point data to the decimal type, it maybe overflow.
+        DataType::Float32 => Some(DataType::Decimal(14, 7)),
+        DataType::Float64 => Some(DataType::Decimal(30, 15)),
+        _ => None,
+    }
+}
+
+fn mathematics_numerical_coercion(

Review comment:
       This function looks almost the same as `numerical_coercion`  -- which is used for equality
   
   What is the reason for making a new function rather than extending `numerical_coercion` with Decimal support?

##########
File path: datafusion/src/physical_plan/expressions/binary.rs
##########
@@ -235,12 +236,10 @@ fn is_distinct_from_decimal(
 ) -> Result<BooleanArray> {
     let mut bool_builder = BooleanBuilder::new(left.len());
     for i in 0..left.len() {
-        if left.is_null(i) && right.is_null(i) {
-            bool_builder.append_value(false)?;
-        } else if left.is_null(i) || right.is_null(i) {
-            bool_builder.append_value(true)?;
-        } else {
-            bool_builder.append_value(left.value(i) != right.value(i))?;
+        match (left.is_null(i), right.is_null(i)) {

Review comment:
       👍 

##########
File path: datafusion/src/physical_plan/coercion_rule/binary_rule.rs
##########
@@ -162,12 +162,141 @@ fn get_comparison_common_decimal_type(
     }
 }
 
+// Convert the numeric data type to the decimal data type.
+// Now, we just support the signed integer type and floating-point type.
+fn convert_numeric_type_to_decimal(numeric_type: &DataType) -> Option<DataType> {

Review comment:
       maybe this would be better called `coerce_numeric_type_to_decimal`?




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org