This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/master by this push:
new b3d1cb149 Preserve the TryCast expression in columnize_expr (#4574)
b3d1cb149 is described below
commit b3d1cb149d016482b46dadecf551c4fc0935b291
Author: byteink <[email protected]>
AuthorDate: Tue Dec 13 19:55:06 2022 +0800
Preserve the TryCast expression in columnize_expr (#4574)
---
datafusion/expr/src/utils.rs | 4 ++++
datafusion/sql/src/planner.rs | 10 ++++++++++
2 files changed, 14 insertions(+)
diff --git a/datafusion/expr/src/utils.rs b/datafusion/expr/src/utils.rs
index 88631cc6f..8a04df43d 100644
--- a/datafusion/expr/src/utils.rs
+++ b/datafusion/expr/src/utils.rs
@@ -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) {
diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index c78032a02..a04a71d4e 100644
--- a/datafusion/sql/src/planner.rs
+++ b/datafusion/sql/src/planner.rs
@@ -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