This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new b6fa286a50 fix: plan error when adding utf8 and timestamp (#5696)
b6fa286a50 is described below

commit b6fa286a507702ea4a2a5d8e80efdaf6f07d5779
Author: Alex Huang <[email protected]>
AuthorDate: Thu Mar 23 21:22:56 2023 +0100

    fix: plan error when adding utf8 and timestamp (#5696)
---
 datafusion/core/tests/sqllogictests/test_files/dates.slt | 5 +++++
 datafusion/physical-expr/src/expressions/binary.rs       | 8 ++++++++
 2 files changed, 13 insertions(+)

diff --git a/datafusion/core/tests/sqllogictests/test_files/dates.slt 
b/datafusion/core/tests/sqllogictests/test_files/dates.slt
index 65234b29d2..fa8644c7db 100644
--- a/datafusion/core/tests/sqllogictests/test_files/dates.slt
+++ b/datafusion/core/tests/sqllogictests/test_files/dates.slt
@@ -83,3 +83,8 @@ where d3_date > d2_date + INTERVAL '5 days'
 d
 g
 h
+
+## Plan error when compare Utf8 and timestamp in where clause
+statement error DataFusion error: Error during planning: The type of 
Timestamp\(Nanosecond, Some\("\+00:00"\)\) Plus Utf8 of binary physical should 
be same
+select i_item_desc from test
+where d3_date > now() + '5 days';
\ No newline at end of file
diff --git a/datafusion/physical-expr/src/expressions/binary.rs 
b/datafusion/physical-expr/src/expressions/binary.rs
index a67c3748ca..4e65a9fdd5 100644
--- a/datafusion/physical-expr/src/expressions/binary.rs
+++ b/datafusion/physical-expr/src/expressions/binary.rs
@@ -52,6 +52,7 @@ use arrow::datatypes::*;
 
 use adapter::{eq_dyn, gt_dyn, gt_eq_dyn, lt_dyn, lt_eq_dyn, neq_dyn};
 use arrow::compute::kernels::concat_elements::concat_elements_utf8;
+use datafusion_expr::type_coercion::{is_timestamp, is_utf8_or_large_utf8};
 use kernels::{
     bitwise_and, bitwise_and_scalar, bitwise_or, bitwise_or_scalar, 
bitwise_shift_left,
     bitwise_shift_left_scalar, bitwise_shift_right, bitwise_shift_right_scalar,
@@ -1213,6 +1214,13 @@ pub fn binary(
 ) -> Result<Arc<dyn PhysicalExpr>> {
     let lhs_type = &lhs.data_type(input_schema)?;
     let rhs_type = &rhs.data_type(input_schema)?;
+    if (is_utf8_or_large_utf8(lhs_type) && is_timestamp(rhs_type))
+        || (is_timestamp(lhs_type) && is_utf8_or_large_utf8(rhs_type))
+    {
+        return Err(DataFusionError::Plan(format!(
+            "The type of {lhs_type} {op:?} {rhs_type} of binary physical 
should be same"
+        )));
+    }
     if !lhs_type.eq(rhs_type) {
         return Err(DataFusionError::Internal(format!(
             "The type of {lhs_type} {op:?} {rhs_type} of binary physical 
should be same"

Reply via email to