HyukjinKwon commented on code in PR #59416:
URL: https://github.com/apache/spark/pull/59416#discussion_r4270849724
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ViewResolution.scala:
##########
@@ -33,31 +35,54 @@ object ViewResolution {
// operator.
// Resolve all the UnresolvedRelations and Views in the child.
- val newChild = AnalysisContext.withAnalysisContext(view.desc) {
+ val newChild = resolveInViewContext(view.desc, view.isTempView, view,
view.child, resolveChild)
+
+ // Fail the analysis eagerly because outside AnalysisContext, the
unresolved operators
+ // inside a view maybe resolved incorrectly.
+ checkAnalysis(newChild)
+
+ view.copy(child = newChild, options = options)
+ }
+
+ /**
+ * Resolves the source of a metric view read from the catalog. Like a view's
child, it resolves
+ * in the catalog and namespace the metric view was created in, with its
captured SQL configs.
+ */
+ def resolveMetricView(
+ metricView: MetricViewPlaceholder,
+ resolveChild: LogicalPlan => LogicalPlan,
+ checkAnalysis: LogicalPlan => Unit): MetricViewPlaceholder = {
+ val newChild = resolveInViewContext(
Review Comment:
**Nit (P3):** Besides the namespace, this now analyzes the metric view's
source and WHERE under the configs captured at creation
(`View.effectiveSQLConf`, including the
`spark.sql.legacy.useCurrentConfigsForView` rollback), and counts the metric
view toward `spark.sql.view.maxNestedViewDepth`. The PR description and this
ScalaDoc both call that out. The new tests only change the current
namespace/catalog and add a same-named temp view, with the same SQL configs at
CREATE and SELECT and no WHERE. Dropping the `withExistingConf` wrapper for
metric views, passing `isTempView = true`, or skipping the depth check would
leave every metric view test green, even though the captured-config part
changes results for existing metric views.
**Verification:**
- **Behavior:** A metric view read under a session config that differs from
its creation config returns the result implied by the captured config for its
source/WHERE.
- **Compatibility:** The legacy useCurrentConfigsForView rollback makes the
same metric view read follow the session config, as it does for regular views.
- **Regression:** The nested-view-depth limit counts the metric view level,
so a metric view over a view raises VIEW_EXCEED_MAX_NESTED_DEPTH at a depth
limit that a direct read of the view would pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]