Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve the TryCast expression in columnize_expr #4574

Merged
merged 1 commit into from
Dec 13, 2022
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
4 changes: 4 additions & 0 deletions datafusion/expr/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ pub fn columnize_expr(e: Expr, input_schema: &DFSchema) -> Expr {
expr: Box::new(columnize_expr(*expr, input_schema)),
data_type,
}),
Expr::TryCast { expr, data_type } => Expr::TryCast {
expr: Box::new(columnize_expr(*expr, input_schema)),
data_type,
},
Expr::ScalarSubquery(_) => e.clone(),
_ => match e.display_name() {
Ok(name) => match input_schema.field_with_unqualified_name(&name) {
Expand Down
10 changes: 10 additions & 0 deletions datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3366,6 +3366,16 @@ mod tests {
);
}

#[test]
fn try_cast_from_aggregation() {
quick_test(
"SELECT TRY_CAST(SUM(age) AS FLOAT) FROM person",
"Projection: TRY_CAST(SUM(person.age) AS Float32)\
\n Aggregate: groupBy=[[]], aggr=[[SUM(person.age)]]\
\n TableScan: person",
);
}

#[test]
fn cast_to_invalid_decimal_type() {
// precision == 0
Expand Down