goldmedal commented on code in PR #12453:
URL: https://github.com/apache/datafusion/pull/12453#discussion_r1758815845
##########
datafusion/core/tests/expr_api/simplification.rs:
##########
@@ -693,3 +694,24 @@ fn test_simplify_cycles() {
let expected = lit(true);
test_simplify_with_cycle_count(expr, expected, 3);
}
+
+#[test]
+fn test_alias_pushdown() -> Result<()> {
+ let schema = Schema::new(vec![
+ Field::new("id", DataType::Int64, false),
+ Field::new("age", DataType::Int64, false),
+ ]);
Review Comment:
I'm not sure if adding the unparsing test here is appropriate. 🤔 Typically,
we add unparse-related tests in `datafusion/sql/tests/cases/plan_to_sql.rs`
I left a disabled test for this issue in the previous PR
https://github.com/apache/datafusion/pull/12158. I guess we can just enable it
and remove this test.
https://github.com/apache/datafusion/blob/389f7f738997acb8c127e17afb7f8688b3477f73/datafusion/sql/tests/cases/plan_to_sql.rs#L702
##########
datafusion/sql/src/unparser/rewrite.rs:
##########
@@ -300,3 +301,27 @@ fn find_projection(logical_plan: &LogicalPlan) ->
Option<&Projection> {
_ => None,
}
}
+
+pub struct TableAliasRewriter {
Review Comment:
How about adding some doc for this public struct?
##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -587,12 +587,24 @@ impl Unparser<'_> {
builder = builder.project(project_columns)?;
}
- let filter_expr = table_scan
+ let filter_expr: Result<Option<Expr>> = table_scan
.filters
.iter()
.cloned()
- .reduce(|acc, expr| acc.and(expr));
- if let Some(filter) = filter_expr {
+ .map(|expr| {
+ if let Some(ref mut rewriter) = filter_alias_rewriter {
+ expr.rewrite(rewriter).data()
+ } else {
+ Ok(expr)
+ }
+ })
+ .reduce(|acc, expr_result| match (acc, expr_result) {
+ (Ok(acc_expr), Ok(expr)) => Ok(acc_expr.and(expr)),
+ (Err(e), _) | (_, Err(e)) => Err(e),
+ })
Review Comment:
We can simplify here like this
```suggestion
.reduce(|acc, expr_result| {
acc.and_then(|acc_expr| {
expr_result.map(|expr| acc_expr.and(expr))
})
})
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]