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
Conversation
@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? |
@hvanhovell From an end user perspective, there may be two major differences:
|
Test build #74318 has finished for PR 17241 at commit
|
Yeah you have a point there. cc @rxin wdyt? |
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 " + |
There was a problem hiding this comment.
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.
Test build #74355 has finished for PR 17241 at commit
|
@@ -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 " + |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 " + |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
Please also add the related test cases. Thanks! |
Test build #74483 has finished for PR 17241 at commit
|
Test build #74543 has finished for PR 17241 at commit
|
ping @hvanhovell @gatorsmile |
LGTM |
Thanks! Merging to master. |
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
.