Skip to content

Commit

Permalink
Preserve the TryCast expression in columnize_expr (#4574)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahgao authored Dec 13, 2022
1 parent b822b0e commit b3d1cb1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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 @@ -3394,6 +3394,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

0 comments on commit b3d1cb1

Please sign in to comment.