Github user gatorsmile commented on the pull request:
https://github.com/apache/spark/pull/11298#issuecomment-187001189
##### Issue 1:
```SQL
SELECT MAX(value) FROM src GROUP BY key + 1 ORDER BY key + 1
```
`key + 1` is not an aggregated function, but we still need to push it down
into `Aggregate`, if we do not have `Project` and `Window` between `Sort` and
`Aggregate`.
```
== Parsed Logical Plan ==
'Sort [('key + 1) ASC], true
+- 'Aggregate [('key + 1)], [unresolvedalias('MAX('value),None)]
+- 'UnresolvedRelation `src`, None
```
When that happens, we need to treat it as an aggregated function. The plan
will be like:
```
Project [_c0#50]
+- Sort [aggOrder#51 ASC], true
+- Aggregate [(key#45 + 1)],
[(max(value#46),mode=Complete,isDistinct=false) AS _c0#50,(key#45 + 1) AS
aggOrder#51]
+- Subquery src
+- Project [_1#43 AS key#45,_2#44 AS value#46]
+- LocalRelation [_1#43,_2#44], [[1,1],[-1,1]]
```
Let me show another case that does not need to treat `key+1` as an
aggregate function.
```SQL
SELECT value FROM src ORDER BY key + 1
```
```
== Parsed Logical Plan ==
'Sort [('key + 1) ASC], true
+- 'Project [unresolvedalias('value,None)]
+- 'UnresolvedRelation `src`, None
```
In this case, we just need to push `key` into `Project`.
```
Project [value#46]
+- Sort [(key#45 + 1) ASC], true
+- Project [value#46,key#45]
+- Subquery src
+- Project [_1#43 AS key#45,_2#44 AS value#46]
+- LocalRelation [_1#43,_2#44], [[1,1],[-1,1]]
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]