Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions datafusion/physical-expr-common/src/expressions/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions datafusion/sqllogictest/test_files/cast.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
----

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest a test that also shows the filter passing (I wasn't sure if the whole thing was turned into NULL). But I double checked and this query works on this branch:

Suggested change
query I
select * from t0 where v0<1e100;
----
1
2
3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add that

query I
select * from t0 where v0<1e100;
----
1
2
3

statement ok
drop table t0;