Skip to content

Commit b3d1cb1

Browse files
authored
Preserve the TryCast expression in columnize_expr (#4574)
1 parent b822b0e commit b3d1cb1

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

datafusion/expr/src/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,10 @@ pub fn columnize_expr(e: Expr, input_schema: &DFSchema) -> Expr {
688688
expr: Box::new(columnize_expr(*expr, input_schema)),
689689
data_type,
690690
}),
691+
Expr::TryCast { expr, data_type } => Expr::TryCast {
692+
expr: Box::new(columnize_expr(*expr, input_schema)),
693+
data_type,
694+
},
691695
Expr::ScalarSubquery(_) => e.clone(),
692696
_ => match e.display_name() {
693697
Ok(name) => match input_schema.field_with_unqualified_name(&name) {

datafusion/sql/src/planner.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,6 +3394,16 @@ mod tests {
33943394
);
33953395
}
33963396

3397+
#[test]
3398+
fn try_cast_from_aggregation() {
3399+
quick_test(
3400+
"SELECT TRY_CAST(SUM(age) AS FLOAT) FROM person",
3401+
"Projection: TRY_CAST(SUM(person.age) AS Float32)\
3402+
\n Aggregate: groupBy=[[]], aggr=[[SUM(person.age)]]\
3403+
\n TableScan: person",
3404+
);
3405+
}
3406+
33973407
#[test]
33983408
fn cast_to_invalid_decimal_type() {
33993409
// precision == 0

0 commit comments

Comments
 (0)