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/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 45599ce310 use safe cast in propagate_constraints (#11297)
45599ce310 is described below

commit 45599ce310aa6270813091a5c3288abcd7541f59
Author: Lordworms <[email protected]>
AuthorDate: Sun Jul 7 10:39:37 2024 -0700

    use safe cast in propagate_constraints (#11297)
    
    * use safe cast in propagate_constraints
    
    * add test
---
 .../physical-expr-common/src/expressions/cast.rs     | 11 ++++++++---
 datafusion/sqllogictest/test_files/cast.slt          | 20 ++++++++++++++++++++
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/datafusion/physical-expr-common/src/expressions/cast.rs 
b/datafusion/physical-expr-common/src/expressions/cast.rs
index 8aba33932c..dd6131ad65 100644
--- a/datafusion/physical-expr-common/src/expressions/cast.rs
+++ b/datafusion/physical-expr-common/src/expressions/cast.rs
@@ -36,6 +36,11 @@ const DEFAULT_CAST_OPTIONS: CastOptions<'static> = 
CastOptions {
     format_options: DEFAULT_FORMAT_OPTIONS,
 };
 
+const DEFAULT_SAFE_CAST_OPTIONS: CastOptions<'static> = CastOptions {
+    safe: true,
+    format_options: DEFAULT_FORMAT_OPTIONS,
+};
+
 /// CAST expression casts an expression to a specific data type and returns a 
runtime error on invalid cast
 #[derive(Debug, Clone)]
 pub struct CastExpr {
@@ -150,9 +155,9 @@ impl PhysicalExpr for CastExpr {
         let child_interval = children[0];
         // Get child's datatype:
         let cast_type = child_interval.data_type();
-        Ok(Some(
-            vec![interval.cast_to(&cast_type, &self.cast_options)?],
-        ))
+        Ok(Some(vec![
+            interval.cast_to(&cast_type, &DEFAULT_SAFE_CAST_OPTIONS)?
+        ]))
     }
 
     fn dyn_hash(&self, state: &mut dyn Hasher) {
diff --git a/datafusion/sqllogictest/test_files/cast.slt 
b/datafusion/sqllogictest/test_files/cast.slt
index 4554c9292b..3466354e54 100644
--- a/datafusion/sqllogictest/test_files/cast.slt
+++ b/datafusion/sqllogictest/test_files/cast.slt
@@ -69,3 +69,23 @@ query ?
 SELECT CAST(MAKE_ARRAY() AS VARCHAR[])
 ----
 []
+
+statement ok
+create table t0(v0 BIGINT);
+
+statement ok
+insert into t0 values (1),(2),(3);
+
+query I
+select * from t0 where v0>1e100;
+----
+
+query I
+select * from t0 where v0<1e100;
+----
+1
+2
+3
+
+statement ok
+drop table t0;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to