xiedeyantu commented on code in PR #21362:
URL: https://github.com/apache/datafusion/pull/21362#discussion_r3058064144
##########
datafusion/optimizer/src/eliminate_duplicated_expr.rs:
##########
@@ -175,4 +214,40 @@ mod tests {
TableScan: test
")
}
+
+ #[test]
+ fn eliminate_fd_redundant_sort_expr() -> Result<()> {
+ let table_scan = test_table_scan().unwrap();
+ let plan = LogicalPlanBuilder::from(table_scan)
+ .aggregate(vec![col("a")], vec![sum(col("b")).alias("total_sal")])?
+ .sort(vec![
+ col("a").sort(true, true),
+ col("total_sal").sort(true, true),
+ ])?
+ .build()?;
+
+ assert_optimized_plan_equal!(plan, @r"
+ Sort: test.a ASC NULLS FIRST
+ Aggregate: groupBy=[[test.a]], aggr=[[sum(test.b) AS total_sal]]
+ TableScan: test
+ ")
+ }
+
+ #[test]
+ fn keep_order_by_when_dependency_comes_later() -> Result<()> {
+ let table_scan = test_table_scan().unwrap();
+ let plan = LogicalPlanBuilder::from(table_scan)
+ .aggregate(vec![col("a")], vec![sum(col("b")).alias("total_sal")])?
+ .sort(vec![
+ col("total_sal").sort(true, true),
+ col("a").sort(true, true),
+ ])?
+ .build()?;
+
+ assert_optimized_plan_equal!(plan, @r"
+ Sort: total_sal ASC NULLS FIRST, test.a ASC NULLS FIRST
+ Aggregate: groupBy=[[test.a]], aggr=[[sum(test.b) AS total_sal]]
+ TableScan: test
+ ")
+ }
Review Comment:
These cases has been moved to .slt test.
--
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]