forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-50638][SQL] Refactor the view resolution into the separate fil…
…e to reuse it in the single-pass Analyzer ### What changes were proposed in this pull request? Refactor the view resolution into the separate file to reuse it in the single-pass Analyzer. ### Why are the changes needed? To reuse this code from the single-pass Analyzer. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Existing tests. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#49255 from vladimirg-db/vladimirg-db/refactor-view-resolution-to-a-separate-file. Authored-by: Vladimir Golubev <vladimir.golubev@databricks.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
- Loading branch information
1 parent
482a27c
commit 827d2a0
Showing
2 changed files
with
58 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ViewResolution.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.catalyst.analysis | ||
|
||
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, View} | ||
import org.apache.spark.sql.errors.QueryCompilationErrors | ||
import org.apache.spark.sql.internal.SQLConf | ||
|
||
object ViewResolution { | ||
def resolve( | ||
view: View, | ||
resolveChild: LogicalPlan => LogicalPlan, | ||
checkAnalysis: LogicalPlan => Unit): View = { | ||
// The view's child should be a logical plan parsed from the `desc.viewText`, the variable | ||
// `viewText` should be defined, or else we throw an error on the generation of the View | ||
// operator. | ||
|
||
// Resolve all the UnresolvedRelations and Views in the child. | ||
val newChild = AnalysisContext.withAnalysisContext(view.desc) { | ||
val nestedViewDepth = AnalysisContext.get.nestedViewDepth | ||
val maxNestedViewDepth = AnalysisContext.get.maxNestedViewDepth | ||
if (nestedViewDepth > maxNestedViewDepth) { | ||
throw QueryCompilationErrors.viewDepthExceedsMaxResolutionDepthError( | ||
view.desc.identifier, | ||
maxNestedViewDepth, | ||
view | ||
) | ||
} | ||
SQLConf.withExistingConf(View.effectiveSQLConf(view.desc.viewSQLConfigs, view.isTempView)) { | ||
resolveChild(view.child) | ||
} | ||
} | ||
|
||
// Fail the analysis eagerly because outside AnalysisContext, the unresolved operators | ||
// inside a view maybe resolved incorrectly. | ||
checkAnalysis(newChild) | ||
|
||
view.copy(child = newChild) | ||
} | ||
} |