Wan Kun created SPARK-44870: ------------------------------- Summary: Convert HashAggregate to SortAggregate if all grouping expressions are in child output orderings Key: SPARK-44870 URL: https://issues.apache.org/jira/browse/SPARK-44870 Project: Spark Issue Type: Improvement Components: SQL Affects Versions: 3.5.0 Reporter: Wan Kun
If all the grouping expressions of Aggregate could be found in the child output orderings, it still can be convert to SortAggregate. For example: {code:java} SELECT a, b, count(1) FROM values(1, 1, 1), (2, 2, 2) t1(a, b, c) JOIN values(1, 1, 1), (2, 2, 2) t2(d, e, f) ON a = d AND b = e GROUP by b, a{code} The grouping expressions are b, a, and the child output orderings are a.asc, b.asc, it still can be convert to SortAggregate. If all the grouping expressions of Aggregate are semanticEquals with the child output orderings, it can be replaced to SortAggregate. For example: {code:java} SELECT a, b, count(1) FROM values(1, 1, 1), (2, 2, 2) t1(a, b, c) JOIN values(1, 1, 1), (2, 2, 2) t2(d, e, f) ON a = d AND b = e GROUP by a, b, d{code} The grouping expressions are a, b, d, and the child output orderings are a.asc, b.asc, but we still can find d in a.asc.children, so it can be convert to SortAggregate. -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org