You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by li...@apache.org on 2025/02/19 03:28:56 UTC

(iceberg-rust) branch main updated: fix: Do not extract expression from cast to date (#977)

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

liurenjie1024 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 44666565 fix: Do not extract expression from cast to date (#977)
44666565 is described below

commit 446665652eedc9cd23b9a3ef1ed168e6e5bc36e6
Author: Omer Hadari <om...@ryft.io>
AuthorDate: Wed Feb 19 05:28:51 2025 +0200

    fix: Do not extract expression from cast to date (#977)
    
    solves #976 by not transforming `Cast`s to `DATE`.
---
 .../datafusion/src/physical_plan/expr_to_predicate.rs   | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/crates/integrations/datafusion/src/physical_plan/expr_to_predicate.rs b/crates/integrations/datafusion/src/physical_plan/expr_to_predicate.rs
index 03fb132f..a45e21a5 100644
--- a/crates/integrations/datafusion/src/physical_plan/expr_to_predicate.rs
+++ b/crates/integrations/datafusion/src/physical_plan/expr_to_predicate.rs
@@ -17,6 +17,7 @@
 
 use std::vec;
 
+use datafusion::arrow::datatypes::DataType;
 use datafusion::logical_expr::{Expr, Operator};
 use datafusion::scalar::ScalarValue;
 use iceberg::expr::{BinaryExpression, Predicate, PredicateOperator, Reference, UnaryExpression};
@@ -119,7 +120,14 @@ fn to_iceberg_predicate(expr: &Expr) -> TransformedResult {
                 _ => TransformedResult::NotTransformed,
             }
         }
-        Expr::Cast(c) => to_iceberg_predicate(&c.expr),
+        Expr::Cast(c) => {
+            if c.data_type == DataType::Date32 || c.data_type == DataType::Date64 {
+                // Casts to date truncate the expression, we cannot simply extract it as it
+                // can create erroneous predicates.
+                return TransformedResult::NotTransformed;
+            }
+            to_iceberg_predicate(&c.expr)
+        }
         _ => TransformedResult::NotTransformed,
     }
 }
@@ -403,4 +411,11 @@ mod tests {
             Reference::new("ts").greater_than_or_equal_to(Datum::string("2023-01-05T00:00:00"));
         assert_eq!(predicate, expected_predicate);
     }
+
+    #[test]
+    fn test_predicate_conversion_with_date_cast() {
+        let sql = "ts >= date '2023-01-05T11:00:00'";
+        let predicate = convert_to_iceberg_predicate(sql);
+        assert_eq!(predicate, None);
+    }
 }