Uh oh!
There was an error while loading. Please reload this page.
[SPARK-16771][SQL] WITH clause should not fall into infinite loop. - #14397
[SPARK-16771][SQL] WITH clause should not fall into infinite loop.#14397dongjoon-hyun wants to merge 6 commits into
Conversation
SparkQA
commented
Jul 29, 2016
Test build #62995 has finished for PR 14397 at commit
|
dongjoon-hyun
commented
Jul 29, 2016
Hi, @rxin . |
hvanhovell
commented
Jul 31, 2016
@dongjoon-hyun I think this has merit. I do have one question, what do other databases do? Like postgresql, mysql, sqlserver and others? |
There was a problem hiding this comment.
This integrates some of the functionality of the ResolveRelations rule, but not all (for instance file based datasources). Shouldn't we be consistent and (perhaps) integrate these rules?
dongjoon-hyun
commented
Aug 1, 2016
Thank you for review, @hvanhovell . For the recursive CTE queries, traditional DBMS supports optional For the overlap of
For Hive, the recursive queries and |
hvanhovell
commented
Aug 1, 2016
New behavior versus existing systemsI was not talking about recursive CTE's (which can be very useful in some cases). We are changing the behavior of the Analyzer, and this might surprise users. I would like to know if there is a common approach to this among other systems; so we can justify the change in behavior. Resolve RelationsThe change you propose is almost subsuming the |
dongjoon-hyun
commented
Aug 1, 2016
Oh, sorry for misunderstanding, @hvanhovell . I think we can integrate |
Hi, @hvanhovell . It seems not clearly documented, so I did some comparisons. First of all, in the main SQL body, CTE query names are used first. However, the table resolution in the main SQL body is also dependent on the CTE subqueries. The general Analyzer approach seems to
The root cause of previous Spark problems is using |
dongjoon-hyun
commented
Aug 2, 2016
The above approach also can remove the duplicated scope issue between |
dongjoon-hyun
commented
Aug 8, 2016
Hi, @hvanhovell . |
SparkQA
commented
Aug 8, 2016
Test build #63371 has finished for PR 14397 at commit
|
dongjoon-hyun
commented
Aug 9, 2016
Could you review this PR again, @hvanhovell ? |
There was a problem hiding this comment.
Here, the CTEs of WITH clause are resolved sequentially before applying to main SQL body.
hvanhovell
commented
Aug 9, 2016
@dongjoon-hyun I'll take a look in the morning (CET) |
dongjoon-hyun
commented
Aug 9, 2016
Thank you so much! Then, see you later. :) |
There was a problem hiding this comment.
relations is a map. The iteration sequence of a map does not need the be the ordered in which elements were added (Use a map larger than 4 to see this in action, e.g.: Seq.tabulate(5)(i => ('a' + i).toChar.toString -> i).toMap).
So I think we need to change the data type in With to accommodate this.
There was a problem hiding this comment.
So, I changed it to Seq. Now, relations of With is a sequence.
There was a problem hiding this comment.
Never mind you have already done that :)
There was a problem hiding this comment.
This does not replace With in all cases. Could you remove the relations.nonEmpty guard?
There was a problem hiding this comment.
If WITH without relations, I thought we can skip all since there is nothing to be replaced.
There was a problem hiding this comment.
Yeah you are right about that. But the current code does not remove the With node if there are no relations.
hvanhovell
commented
Aug 10, 2016
@dongjoon-hyun this is looking very promising. I left two small comments. |
dongjoon-hyun
commented
Aug 10, 2016
Thank you, @hvanhovell ! |
There was a problem hiding this comment.
resolved :+ r._1 -> ResolveRelations(substituteCTE(r._2, resolved))?
You could also deconstruct the r tuple for easier reading.
hvanhovell
commented
Aug 10, 2016
LGTM pending Jenkins. |
SparkQA
commented
Aug 10, 2016
Test build #63526 has finished for PR 14397 at commit
|
SparkQA
commented
Aug 10, 2016
Test build #63529 has finished for PR 14397 at commit
|
dongjoon-hyun
commented
Aug 11, 2016
Rebased just to resolve conflicts. |
SparkQA
commented
Aug 11, 2016
Test build #63577 has finished for PR 14397 at commit
|
SparkQA
commented
Aug 11, 2016
Test build #63578 has finished for PR 14397 at commit
|
There was a problem hiding this comment.
can you create a test in SQLQueryTestSuite instead?
There was a problem hiding this comment.
Ur, @rxin .SQLQueryTestSuite seems not to support exceptions cases yet.
There was a problem hiding this comment.
In this PR, exceptions are important and should be checked.
dongjoon-hyun
commented
Aug 11, 2016
dongjoon-hyun
commented
Aug 11, 2016
Hi, @rxin . |
SparkQA
commented
Aug 11, 2016
Test build #63595 has finished for PR 14397 at commit
|
dongjoon-hyun
commented
Aug 11, 2016
Hi, @rxin . I moved the testcase into new suite. |
| @@ -0,0 +1,14 @@ | |||
| create temporary view t as select * from values 0, 1, 2 as t(id); | |||
There was a problem hiding this comment.
Here, t and t2 is base tables.
The followings are used CTEs and to check if base table or previous CTE is used correctly.
There was a problem hiding this comment.
Ah, I see. You mean with.sql into CTE.sql.
I see. No problem.
There was a problem hiding this comment.
I will use cte.sql instead of with.sql.
dongjoon-hyun
commented
Aug 11, 2016
Thank you, @rxin . It's updated. |
SparkQA
commented
Aug 11, 2016
Test build #63637 has finished for PR 14397 at commit
|
dongjoon-hyun
commented
Aug 12, 2016
Hi, @hvanhovell . |
hvanhovell
commented
Aug 12, 2016
LGTM (again) - merging to master. Thanks! |
dongjoon-hyun
commented
Aug 12, 2016
Thank you, @hvanhovell ! |
What changes were proposed in this pull request?
This PR changes the CTE resolving rule to use only forward-declared tables in order to prevent infinite loops. More specifically, new logic is like the following.
WITHclauses first before replacing the main SQL body.Reported Error Scenarios
Note that
t,t1, andt2are not declared in database. Spark falls into infinite loops before resolving table names.How was this patch tested?
Pass the Jenkins tests with new two testcases.