alamb commented on code in PR #20300:
URL: https://github.com/apache/datafusion/pull/20300#discussion_r2800775402
##########
datafusion/optimizer/src/extract_leaf_expressions.rs:
##########
@@ -1501,4 +1501,134 @@ mod tests {
(same as after pushdown)
"#)
}
+
+ /// Projection containing a MoveTowardsLeafNodes sub-expression above an
+ /// Aggregate. Aggregate blocks pushdown, so the (None, true) recovery
+ /// fallback path fires: in-place extraction + recovery projection.
+ #[test]
+ fn test_projection_with_leaf_expr_above_aggregate() -> Result<()> {
+ use datafusion_expr::test::function_stub::count;
+
+ let table_scan = test_table_scan_with_struct()?;
+ let plan = LogicalPlanBuilder::from(table_scan)
+ .aggregate(vec![col("user")], vec![count(lit(1))])?
+ .project(vec![
+ leaf_udf(col("user"), "name")
+ .is_not_null()
+ .alias("has_name"),
+ col("COUNT(Int32(1))"),
+ ])?
+ .build()?;
+
+ assert_stages!(plan, @r#"
+ ## Original Plan
+ Projection: leaf_udf(test.user, Utf8("name")) IS NOT NULL AS has_name,
COUNT(Int32(1))
+ Aggregate: groupBy=[[test.user]], aggr=[[COUNT(Int32(1))]]
+ TableScan: test projection=[user]
+
+ ## After Extraction
+ (same as original)
+
+ ## After Pushdown
+ Projection: __datafusion_extracted_1 IS NOT NULL AS has_name,
COUNT(Int32(1))
+ Projection: leaf_udf(test.user, Utf8("name")) AS
__datafusion_extracted_1, test.user, COUNT(Int32(1))
+ Aggregate: groupBy=[[test.user]], aggr=[[COUNT(Int32(1))]]
+ TableScan: test projection=[user]
+
+ ## Optimized
+ Projection: leaf_udf(test.user, Utf8("name")) IS NOT NULL AS has_name,
COUNT(Int32(1))
Review Comment:
the optimized version is the same as the original, it seems
##########
datafusion/sqllogictest/test_files/projection_pushdown.slt:
##########
@@ -1792,3 +1792,118 @@ SELECT s['value'], s['label'] FROM (
200 beta
250 epsilon
300 delta
+
+#####################
+# Section 16: Aggregate / Join edge-case tests
+# Translated from unit tests in extract_leaf_expressions.rs
Review Comment:
this comment seems somewhat irrelevant for future readers of this file
--
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]