Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-19877][SQL] Restrict the nested level of a view #17241

Closed
wants to merge 4 commits into from

Conversation

jiangxb1987
Copy link
Contributor

What changes were proposed in this pull request?

We should restrict the nested level of a view, to avoid stack overflow exception during the view resolution.

How was this patch tested?

Add new test case in SQLViewSuite.

@hvanhovell
Copy link
Contributor

@jiangxb1987 I am not entirely sure about the usefulness of this (I thought it might be good to enforce some restriction when we wrote the design doc). I don't think it matters much what we do from an end user perspective: either analysis succeeds or it fails, only the error message is slightly different. WDYT?

@jiangxb1987
Copy link
Contributor Author

jiangxb1987 commented Mar 10, 2017

@hvanhovell From an end user perspective, there may be two major differences:

  1. If the nested level exceed the value, the user will see a explict message about what caused the failure, instead of an exception that may be confusing;
  2. We don't have to wait for a long time to trigger an exception, we can fail earlier by setting a proper value for the property spark.sql.view.maxNestedViewDepth.

@SparkQA
Copy link

SparkQA commented Mar 10, 2017

Test build #74318 has finished for PR 17241 at commit 15e5366.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@hvanhovell
Copy link
Contributor

Yeah you have a point there.

cc @rxin wdyt?

@rxin
Copy link
Contributor

rxin commented Mar 10, 2017

SGTM

@@ -595,6 +594,11 @@ class Analyzer(
case view @ View(desc, _, child) if !child.resolved =>
// Resolve all the UnresolvedRelations and Views in the child.
val newChild = AnalysisContext.withAnalysisContext(desc.viewDefaultDatabase) {
if (AnalysisContext.get.nestedViewLevel > conf.maxNestedViewDepth) {
view.failAnalysis(s"The nested level of view ${view.desc.identifier} has exceeded " +
s"${conf.maxNestedViewDepth}, terminate the view resolution to avoid further " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the two sentences need to be separated by a period, not comma.

@SparkQA
Copy link

SparkQA commented Mar 11, 2017

Test build #74355 has finished for PR 17241 at commit b4f9a57.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@@ -595,6 +594,11 @@ class Analyzer(
case view @ View(desc, _, child) if !child.resolved =>
// Resolve all the UnresolvedRelations and Views in the child.
val newChild = AnalysisContext.withAnalysisContext(desc.viewDefaultDatabase) {
if (AnalysisContext.get.nestedViewLevel > conf.maxNestedViewDepth) {
view.failAnalysis(s"The nested level of view ${view.desc.identifier} has exceeded " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reword the error a little bit, how about:

s"The depth of view ${view.desc.identifier} exceeds the maximum view " + 
s"resolution depth (${conf.maxNestedViewDepth}). Analysis is aborted to " +
s"avoid errors. Increase the value of spark.sql.view.maxNestedViewDepth to " +
s"work around this."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the last two does not need s

@@ -595,6 +594,11 @@ class Analyzer(
case view @ View(desc, _, child) if !child.resolved =>
// Resolve all the UnresolvedRelations and Views in the child.
val newChild = AnalysisContext.withAnalysisContext(desc.viewDefaultDatabase) {
if (AnalysisContext.get.nestedViewLevel > conf.maxNestedViewDepth) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be consistent. How about renaming nestedViewLevel to nestedViewDepth?

val MAX_NESTED_VIEW_DEPTH =
buildConf("spark.sql.view.maxNestedViewDepth")
.internal()
.doc("The maximum level of view references allowed in a nested view. A nested view may " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wording, how about:

"The maximum depth of a view reference in a nested view. A nested view may " +
"reference other nested views, the dependencies are organized in a directed acyclic " +
"graph (DAG). However the DAG depth may become too large and cause unexpected " +
"behavior. This configuration puts a limit on this: when the depth of a view exceeds " + 
"this value during analysis, we terminate the resolution to avoid potential errors.")

"behaviors, so we put some limit on this: when the nested level of a view exceeds this " +
"value during view resolution, we terminate the resolution to avoid further errors.")
.intConf
.createWithDefault(100)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add .checkValue(...)

What is the behaviors of edge scenarios? Does that mean we can disable view support using this flag?

@gatorsmile
Copy link
Member

Please also add the related test cases. Thanks!

@SparkQA
Copy link

SparkQA commented Mar 14, 2017

Test build #74483 has finished for PR 17241 at commit 5c91ab7.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Mar 14, 2017

Test build #74543 has finished for PR 17241 at commit d28b676.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@jiangxb1987
Copy link
Contributor Author

ping @hvanhovell @gatorsmile

@gatorsmile
Copy link
Member

LGTM

@gatorsmile
Copy link
Member

Thanks! Merging to master.

@asfgit asfgit closed this in ee36bc1 Mar 15, 2017
@jiangxb1987 jiangxb1987 deleted the view-depth branch March 15, 2017 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants