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 2020/08/22 16:29:00 UTC

[GitHub] [arrow] jorgecarleitao commented on a change in pull request #8024: ARROW-9809: [Rust][DataFusion] Fixed type coercion, supertypes and type checking.

jorgecarleitao commented on a change in pull request #8024:
URL: https://github.com/apache/arrow/pull/8024#discussion_r475106741



##########
File path: rust/datafusion/src/execution/physical_plan/expressions.rs
##########
@@ -991,30 +991,236 @@ impl fmt::Display for BinaryExpr {
     }
 }
 
+// Returns a formatted error about being impossible to coerce types for the binary operator.
+fn coercion_error<T>(lhs_type: &DataType, op: &String, rhs_type: &DataType) -> Result<T> {
+    Err(ExecutionError::General(
+        format!(
+            "The binary operator '{}' can't evaluate with lhs = '{:?}' and rhs = '{:?}'",
+            op, lhs_type, rhs_type
+        )
+        .to_string(),
+    ))
+}
+
+// the type that both lhs and rhs can be casted to for the purpose of a string computation
+fn string_coercion(
+    lhs_type: &DataType,
+    op: &Operator,
+    rhs_type: &DataType,
+) -> Result<DataType> {
+    use arrow::datatypes::DataType::*;
+    match (lhs_type, rhs_type) {
+        (Utf8, Utf8) => Ok(Utf8),
+        (LargeUtf8, Utf8) => Ok(LargeUtf8),
+        (Utf8, LargeUtf8) => Ok(LargeUtf8),
+        (LargeUtf8, LargeUtf8) => Ok(LargeUtf8),
+        _ => coercion_error(lhs_type, &format!("{}", op), rhs_type),
+    }
+}
+
+/// coercion rule for numerical values
+pub fn numerical_coercion(
+    lhs_type: &DataType,
+    op: &String,

Review comment:
       It is only used for error messages atm. But yes, for consistency, we should probably receive an Operator. The operator will be needed in the future for the Operator::Modulus, that only handles integers AFAIK.




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

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