Uh oh!
There was an error while loading. Please reload this page.
[SPARK-18389][SQL] Disallow cyclic view reference - #17152
Conversation
jiangxb1987
commented
Mar 3, 2017
SparkQA
commented
Mar 3, 2017
Test build #73854 has finished for PR 17152 at commit
|
gatorsmile
commented
Mar 3, 2017
Based on our current impl of view, |
jiangxb1987
commented
Mar 4, 2017
@gatorsmile Currently we don't perform recursive resolution over a temporary view, so perhaps that won't trigger a cyclic view reference. For example: |
gatorsmile
commented
Mar 6, 2017
Yeah. The temporary view does not have such an issue, because we did not change it. My typo. What I mean is |
cloud-fan
commented
Mar 6, 2017
When do other databases report this error? During view creating/alter or during view resolution? |
jiangxb1987
commented
Mar 6, 2017
Hive report the error during alter view: |
| sql("ALTER VIEW view1 AS SELECT * FROM view3 JOIN view2") | ||
| }.getMessage | ||
| assert(e2.contains("Recursive view `default`.`view1` detected (cycle: `default`.`view1` " + | ||
| "-> `default`.`view3` -> `default`.`view2` -> `default`.`view1`)")) |
There was a problem hiding this comment.
How about this test case?
sql("alter view v1 as select * from jt where exists (select 1 from v2)")
Should we get the same exception as well?
There was a problem hiding this comment.
What is missing in your code is whenever you hit a SubqueryExpression, you need to traverse the plan of that expression to detect cyclic references? See an example of the code in #16493.
nsyca
commented
Mar 6, 2017
Going back to @gatorsmile 's question, does this fix cover the scenario below?
If this is an existing problem and your PR does not cover it, would you intend to address it in this PR? |
jiangxb1987
commented
Mar 7, 2017
@gatorsmile@nsyca Thank you for your comments! I've added the coverage for both |
SparkQA
commented
Mar 7, 2017
Test build #74088 has finished for PR 17152 at commit
|
| // Detect cyclic references from subqueries. | ||
| plan.expressions.foreach { expr => | ||
| if (expr.isInstanceOf[SubqueryExpression]) { | ||
| checkCyclicViewReference(expr.asInstanceOf[SubqueryExpression].plan, path, viewIdent) |
There was a problem hiding this comment.
Shall we use the pattern matching instead of isInstanceOf-asInstanceOf? The logic in the code looks good to me.
SparkQA
commented
Mar 8, 2017
Test build #74169 has finished for PR 17152 at commit
|
cloud-fan
commented
Mar 8, 2017
thanks, merging to master! |
What changes were proposed in this pull request?
Disallow cyclic view references, a cyclic view reference may be created by the following queries:
In the above example, a reference cycle (testView -> testView2 -> testView) exsits.
We disallow cyclic view references by checking that in ALTER VIEW command, when the
analyzedPlancontains the sameViewnode with the altered view, we should prevent the behavior and throw an AnalysisException.How was this patch tested?
Test by
SQLViewSuite.test("correctly handle a cyclic view reference").