Apache DataFusion SQL Query Engine
use safe cast in propagate_constraints (#11297)
Lordworms45599ce310aa
diff --git a/datafusion/physical-expr-common/src/expressions/cast.rs b/datafusion/physical-expr-common/src/expressions/cast.rsindex 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.sltindex 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;