Github user cloud-fan commented on the pull request:

    https://github.com/apache/spark/pull/9844#issuecomment-158831881
  
    This is really a good catch, thanks @dilipbiswal 
    
    The problems is that, normal operator should be resolved based on its 
child, but `Sort` operator can be resolved based on its grandchild. So we have 
3 rules that can resolve `Sort`: `ResolveReferences`, 
`ResolveSortReferences`(if grandchild is `Project`) and 
`ResolveAggregateFunctions`(if grandchild is `Aggregate`).
    
    For your example, `select c1 as a , c2 as b from tab group by c1, c2 order 
by a, c2`, we need to resolve `a` and `c2` for `Sort`. Firstly `a` will be 
resolved in `ResolveReferences` based on its child, and when we reach 
`ResolveAggregateFunctions`, we will try to resolve both `a` and `c2` based on 
its grandchild, but failed because `a` is not a legal aggregate expression.
    
    I think we can just fix the problem directly, i.e. only pick up unresolved 
`SortOrder`s and try to resolve it based on grandchild in 
`ResolveAggregateFunctions`. @dilipbiswal what do you think?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to