Uh oh!
There was an error while loading. Please reload this page.
[SPARK-28228][SQL] Fix substitution order of nested WITH clauses - #25029
[SPARK-28228][SQL] Fix substitution order of nested WITH clauses#25029peter-toth wants to merge 7 commits into
Conversation
peter-toth
commented
Jul 2, 2019
This is WIP as it contains changes of #24831 |
maropu
commented
Jul 2, 2019
Also, you need to update the title. |
peter-toth
commented
Jul 2, 2019
Thanks, I changed it to "Fix substitution order of nested WITH clauses". I will update the migration guide too a bit later. |
SparkQA
commented
Jul 2, 2019
Test build #107104 has finished for PR 25029 at commit
|
dongjoon-hyun
commented
Jul 2, 2019
Retest this please. |
SparkQA
commented
Jul 2, 2019
Test build #107126 has finished for PR 25029 at commit
|
maropu
commented
Jul 2, 2019
retest this please |
maropu
commented
Jul 3, 2019
(If this pr gets ready for reviews, I think it'd be better to drop WIP in the title...) |
SparkQA
commented
Jul 3, 2019
Test build #107135 has finished for PR 25029 at commit
|
peter-toth
commented
Jul 3, 2019
Sure, I will remove WIP if #24831 gets accepted and I can rebase this PR on that. |
SparkQA
commented
Jul 3, 2019
Test build #107171 has finished for PR 25029 at commit
|
dongjoon-hyun
commented
Jul 4, 2019
Could you rebase this, @peter-toth ? |
peter-toth
commented
Jul 4, 2019
@maropu, @dongjoon-hyun, @mgaido91 I removed the WIP tag and this PR is ready for review now. |
SparkQA
commented
Jul 4, 2019
Test build #107239 has finished for PR 25029 at commit
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Jul 5, 2019
Test build #107292 has finished for PR 25029 at commit
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Jul 8, 2019
Test build #107359 has finished for PR 25029 at commit
|
dongjoon-hyun
commented
Jul 10, 2019
Retest this please. |
dongjoon-hyun
commented
Jul 10, 2019
Hi, @gatorsmile . |
SparkQA
commented
Jul 10, 2019
Test build #107477 has finished for PR 25029 at commit
|
SparkQA
commented
Jul 11, 2019
Test build #107512 has finished for PR 25029 at commit
|
SparkQA
commented
Jul 11, 2019
Test build #107518 has finished for PR 25029 at commit
|
dongjoon-hyun
commented
Jul 11, 2019
Let's use For the other review comments, it seems that all are addressed. @maropu . Could you review this once more? Or, do you want a more test case? |
mgaido91
left a comment
There was a problem hiding this comment.
only some minor comments, LGTM otherwise.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
peter-toth
left a comment
There was a problem hiding this comment.
Let's use
spark.sql.legacy.ctePrecedence.enabled.
Thanks. I've changed it.
SparkQA
commented
Jul 12, 2019
Test build #107590 has finished for PR 25029 at commit
|
dongjoon-hyun
left a comment
There was a problem hiding this comment.
+1, LGTM. Merged to master.
Thank you, @peter-toth , @maropu , @mgaido91 !
peter-toth
commented
Jul 12, 2019
Thanks so much for the review @dongjoon-hyun, @maropu, @mgaido91! |
## What changes were proposed in this pull request? This PR adds compatibility of handling a `WITH` clause within another `WITH` cause. Before this PR these queries retuned `1` while after this PR they return `2` as PostgreSQL does: ``` WITH t AS (SELECT 1), t2 AS ( WITH t AS (SELECT 2) SELECT * FROM t ) SELECT * FROM t2 ``` ``` WITH t AS (SELECT 1) SELECT ( WITH t AS (SELECT 2) SELECT * FROM t ) ``` As this is an incompatible change, the PR introduces the `spark.sql.legacy.cte.substitution.enabled` flag as an option to restore old behaviour. ## How was this patch tested? Added new UTs. Closesapache#25029 from peter-toth/SPARK-28228. Authored-by: Peter Toth <peter.toth@gmail.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
…ested WITH clause ### What changes were proposed in this pull request? This is a follow-up for #25029, in this PR we throw an AnalysisException when name conflict is detected in nested WITH clause. In this way, the config `spark.sql.legacy.ctePrecedence.enabled` should be set explicitly for the expected behavior. ### Why are the changes needed? The original change might risky to end-users, it changes behavior silently. ### Does this PR introduce any user-facing change? Yes, change the config `spark.sql.legacy.ctePrecedence.enabled` as optional. ### How was this patch tested? New UT. Closes#27454 from xuanyuanking/SPARK-28228-follow. Authored-by: Yuanjian Li <xyliyuanjian@gmail.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
…ested WITH clause ### What changes were proposed in this pull request? This is a follow-up for #25029, in this PR we throw an AnalysisException when name conflict is detected in nested WITH clause. In this way, the config `spark.sql.legacy.ctePrecedence.enabled` should be set explicitly for the expected behavior. ### Why are the changes needed? The original change might risky to end-users, it changes behavior silently. ### Does this PR introduce any user-facing change? Yes, change the config `spark.sql.legacy.ctePrecedence.enabled` as optional. ### How was this patch tested? New UT. Closes#27454 from xuanyuanking/SPARK-28228-follow. Authored-by: Yuanjian Li <xyliyuanjian@gmail.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com> (cherry picked from commit 3db3e39) Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
…ested WITH clause ### What changes were proposed in this pull request? This is a follow-up for apache#25029, in this PR we throw an AnalysisException when name conflict is detected in nested WITH clause. In this way, the config `spark.sql.legacy.ctePrecedence.enabled` should be set explicitly for the expected behavior. ### Why are the changes needed? The original change might risky to end-users, it changes behavior silently. ### Does this PR introduce any user-facing change? Yes, change the config `spark.sql.legacy.ctePrecedence.enabled` as optional. ### How was this patch tested? New UT. Closesapache#27454 from xuanyuanking/SPARK-28228-follow. Authored-by: Yuanjian Li <xyliyuanjian@gmail.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
| // child might contain an inner CTE that has priority so traverse and substitute inner CTEs | ||
| // in child first | ||
| val traversedChild: LogicalPlan = child transformExpressions { | ||
| case e: SubqueryExpression => e.withNewPlan(traverseAndSubstituteCTE(e.plan, true)) |
There was a problem hiding this comment.
The subquery expression seems not correctly handled.
with t1 as (select 1 i) select * from t1 where i in (with t1 as (select 2 i) select * from t1) returns 1 in Spark, but empty row in pgsql.
There was a problem hiding this comment.
Yes, it probably should be transformAllExpressions. Will look into it soon...
What changes were proposed in this pull request?
This PR adds compatibility of handling a
WITHclause within anotherWITHcause. Before this PR these queries retuned1while after this PR they return2as PostgreSQL does:As this is an incompatible change, the PR introduces the
spark.sql.legacy.cte.substitution.enabledflag as an option to restore old behaviour.How was this patch tested?
Added new UTs.