Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-28227][SQL] Support projection, aggregate/window functions, an…
…d lateral view in the TRANSFORM clause ### What changes were proposed in this pull request? For Spark SQL, it can't support script transform SQL with aggregationClause/windowClause/LateralView. This case we can't directly migration Hive SQL to Spark SQL. In this PR, we treat all script transform statement's query part (exclude transform about part) as a separate query block and solve it as ScriptTransformation's child and pass a UnresolvedStart as ScriptTransform's input. Then in analyzer level, we pass child's output as ScriptTransform's input. Then we can support all kind of normal SELECT query combine with script transformation. Such as transform with aggregation: ``` SELECT TRANSFORM ( d2, max(d1) as max_d1, sum(d3)) USING 'cat' AS (a,b,c) FROM script_trans WHERE d1 <= 100 GROUP BY d2 HAVING max_d1 > 0 ``` When we build AST, we treat it as ``` SELECT TRANSFORM (*) USING 'cat' AS (a,b,c) FROM ( SELECT d2, max(d1) as max_d1, sum(d3) FROM script_trans WHERE d1 <= 100 GROUP BY d2 HAVING max_d1 > 0 ) tmp ``` then in Analyzer's `ResolveReferences`, resolve `* (UnresolvedStar)`, then sql behavior like ``` SELECT TRANSFORM ( d2, max(d1) as max_d1, sum(d3)) USING 'cat' AS (a,b,c) FROM script_trans WHERE d1 <= 100 GROUP BY d2 HAVING max_d1 > 0 ``` About UT, in this pr we add a lot of different SQL to check we can support all kind of such SQL and each kind of expressions can work well, such as alias, case when, binary compute etc... ### Why are the changes needed? Support transform with aggregateClause/windowClause/LateralView etc , make sql migration more smoothly ### Does this PR introduce _any_ user-facing change? User can write transform with aggregateClause/windowClause/LateralView. ### How was this patch tested? Added UT Closes #29087 from AngersZhuuuu/SPARK-28227-NEW. Lead-authored-by: angerszhu <angers.zhu@gmail.com> Co-authored-by: Angerszhuuuu <angers.zhu@gmail.com> Co-authored-by: AngersZhuuuu <angers.zhu@gmail.com> Signed-off-by: Takeshi Yamamuro <yamamuro@apache.org>
- Loading branch information
1 parent
9c1f807
commit 278203d
Showing
8 changed files
with
662 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.