GitHub user hvanhovell opened a pull request: https://github.com/apache/spark/pull/17278
[SPARK-19933][SQL] Do not change output of a subquery ## What changes were proposed in this pull request? The `RemoveRedundantAlias` rule can change the output attributes (the expression id's to be precise) of a query by eliminating the redundant alias producing them. This is no problem for a regular query, but can cause problems for correlated subqueries: The attributes produced by the subquery are used in the parent plan; changing them will break the parent plan. This PR fixes this by wrapping a subquery in a `ReturnAnswer` top level node when it gets optimized. The `RemoveRedundantAlias` rule now recognizes `ReturnAnswer` and makes aure that the output attributes of the `ReturnAnswer` node are retained. ## How was this patch tested? Added a test case to `RemoveRedundantAliasAndProjectSuite` and added a regression test to `SubquerySuite`. You can merge this pull request into a Git repository by running: $ git pull https://github.com/hvanhovell/spark SPARK-19933 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/17278.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #17278 ---- commit 54cbad15ed17bf9c16b372fb3e5fdf6a8fee69ae Author: Herman van Hovell <hvanhov...@databricks.com> Date: 2017-03-13T16:14:47Z Do not change output of a subquery ---- --- 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