[SPARK-44714] Ease restriction of LCA resolution regarding queries with having#42276
Closed
anchovYu wants to merge 6 commits intoapache:masterfrom
Closed
[SPARK-44714] Ease restriction of LCA resolution regarding queries with having#42276anchovYu wants to merge 6 commits intoapache:masterfrom
anchovYu wants to merge 6 commits intoapache:masterfrom
Conversation
Hisoka-X
reviewed
Aug 2, 2023
| "LATERAL_COLUMN_ALIAS_IN_AGGREGATE_WITH_WINDOW_AND_HAVING" : { | ||
| "message" : [ | ||
| "Referencing lateral column alias <lca> in the aggregate query both with window expressions and with having clause. Please rewrite the aggregate query by removing the having clause or removing lateral alias reference in the SELECT list." | ||
| "Referencing lateral column alias <lca> in the query both with window expressions and with having clause. Please rewrite the aggregate query by removing the having clause or removing lateral alias reference in the SELECT list that has the window expression and retry." |
Member
There was a problem hiding this comment.
anchovYu
commented
Aug 8, 2023
| && aggregateExpressions.exists(_.containsPattern(LATERAL_COLUMN_ALIAS_REFERENCE)) => | ||
| case pOriginal: Project if ruleApplicableOnOperator(pOriginal, pOriginal.projectList) | ||
| && pOriginal.projectList.exists(_.containsPattern(LATERAL_COLUMN_ALIAS_REFERENCE)) => | ||
| val p @ Project(projectList, child) = pOriginal.mapChildren(apply0) |
Contributor
Author
There was a problem hiding this comment.
Bottom-up resolution. The rest of code is fully copied and has no change.
anchovYu
commented
Aug 8, 2023
| if ruleApplicableOnOperator(aggOriginal, aggOriginal.aggregateExpressions) | ||
| && aggOriginal.aggregateExpressions.exists( | ||
| _.containsPattern(LATERAL_COLUMN_ALIAS_REFERENCE)) => | ||
| val agg @ Aggregate(groupingExpressions, aggregateExpressions, _) = |
Contributor
Author
There was a problem hiding this comment.
Bottom up resolution. The rest of code is fully copied and has no change (except the one I commented out).
anchovYu
commented
Aug 8, 2023
| } | ||
| } | ||
| if (!aggregateExpressions.forall(eligibleToLiftUp)) { | ||
| agg |
Contributor
Author
There was a problem hiding this comment.
Previously this line was return agg. That could be risky to return in a closure.. But for apply0 with or without return should be the same.
cloud-fan
approved these changes
Aug 8, 2023
Contributor
|
thanks, merging to master/3.5! |
cloud-fan
pushed a commit
that referenced
this pull request
Aug 8, 2023
…th having ### What changes were proposed in this pull request? This PR eases some restriction of LCA resolution regarding queries with having. Previously LCA won't rewrite (to the new plan shape) when the whole queries contains `UnresolvedHaving`, in case it breaks the plan shape of `UnresolvedHaving - Aggregate` that can be recognized by other rules. But this limitation is too strict and it causes some deadlock in having - lca - window queries. See https://issues.apache.org/jira/browse/SPARK-42936 for more details and examples. With this PR, it will only skip LCA resolution on the `Aggregate` whose direct parent is `UnresolvedHaving`. This is enabled by a new bottom-up resolution without using the transform or resolve utility function. This PR also recognizes a vulnerability related to `TEMP_RESOVLED_COLUMN` and comments in the code. It should be considered as future work. ### Why are the changes needed? More complete functionality and better user experience. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? New tests. Closes #42276 from anchovYu/lca-limitation-better-error. Authored-by: Xinyi Yu <xinyi.yu@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com> (cherry picked from commit 29e8331) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
valentinp17
pushed a commit
to valentinp17/spark
that referenced
this pull request
Aug 24, 2023
…th having ### What changes were proposed in this pull request? This PR eases some restriction of LCA resolution regarding queries with having. Previously LCA won't rewrite (to the new plan shape) when the whole queries contains `UnresolvedHaving`, in case it breaks the plan shape of `UnresolvedHaving - Aggregate` that can be recognized by other rules. But this limitation is too strict and it causes some deadlock in having - lca - window queries. See https://issues.apache.org/jira/browse/SPARK-42936 for more details and examples. With this PR, it will only skip LCA resolution on the `Aggregate` whose direct parent is `UnresolvedHaving`. This is enabled by a new bottom-up resolution without using the transform or resolve utility function. This PR also recognizes a vulnerability related to `TEMP_RESOVLED_COLUMN` and comments in the code. It should be considered as future work. ### Why are the changes needed? More complete functionality and better user experience. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? New tests. Closes apache#42276 from anchovYu/lca-limitation-better-error. Authored-by: Xinyi Yu <xinyi.yu@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR eases some restriction of LCA resolution regarding queries with having.
Previously LCA won't rewrite (to the new plan shape) when the whole queries contains
UnresolvedHaving, in case it breaks the plan shape ofUnresolvedHaving - Aggregatethat can be recognized by other rules. But this limitation is too strict and it causes some deadlock in having - lca - window queries. See https://issues.apache.org/jira/browse/SPARK-42936 for more details and examples.With this PR, it will only skip LCA resolution on the
Aggregatewhose direct parent isUnresolvedHaving. This is enabled by a new bottom-up resolution without using the transform or resolve utility function.This PR also recognizes a vulnerability related to
TEMP_RESOVLED_COLUMNand comments in the code. It should be considered as future work.Why are the changes needed?
More complete functionality and better user experience.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
New tests.