singhpk234 commented on code in PR #19001:
URL: https://github.com/apache/iceberg/pull/19001#discussion_r4705169646
##########
spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveViews.scala:
##########
@@ -104,34 +121,136 @@ case class ResolveViews(spark: SparkSession) extends
Rule[LogicalPlan] with Look
}
}
- private def createViewRelation(nameParts: Seq[String], view: View):
LogicalPlan = {
- val parsed = parseViewText(nameParts.quoted, view.query)
+ private def resolveRelationFromView(
+ relation: UnResolvedRelationFromView,
+ catalog: CatalogPlugin,
+ ident: Identifier): LogicalPlan = {
+ val parts = relation.tableMultipartIdentifier
+ val referencedBy = ViewUtil.buildReferencedByChain(relation.viewChain,
catalog.name())
+ catalog match {
+ case contextual: TableCatalog with SparkSupportsLoadContext if
!relation.isStreaming =>
+ val context = LoadContext.builder().referencedBy(referencedBy).build()
+ val timeTravelSpec = TimeTravelSpec.create(
+ relation.timeTravelTimestamp,
+ relation.timeTravelVersion,
+ conf.sessionLocalTimeZone)
+ try {
+ ViewUtil.loadTable(contextual, ident, context, timeTravelSpec) match
{
+ case _: V1Table =>
+ toUnresolvedRelation(relation)
+ case table =>
+ val relationCatalog = if (timeTravelSpec.isEmpty) {
+ LoadContextTableCatalog(contextual, context)
+ } else {
+ contextual
+ }
+ SubqueryAlias(
+ catalog.name +: ident.asMultipartIdentifier,
+ DataSourceV2Relation.create(
+ table,
+ Some(relationCatalog),
+ Some(ident),
+ relation.options,
+ timeTravelSpec))
+ }
+ } catch {
+ case _: NoSuchTableException =>
+ ViewUtil
+ .loadView(catalog, ident, context)
+ .map(createViewRelation(parts, catalog, ident, _,
relation.viewChain))
+ .getOrElse(toUnresolvedRelation(relation))
+ }
+
+ case _ =>
+ toUnresolvedRelation(relation)
+ }
+ }
+
+ private def toUnresolvedRelation(relation: UnResolvedRelationFromView):
LogicalPlan = {
+ val unresolved =
+ UnresolvedRelation(relation.tableMultipartIdentifier, relation.options,
relation.isStreaming)
+ if (relation.timeTravelVersion.isEmpty &&
relation.timeTravelTimestamp.isEmpty) {
+ unresolved
+ } else {
+ RelationTimeTravel(unresolved, relation.timeTravelTimestamp,
relation.timeTravelVersion)
+ }
+ }
+
+ private def createViewRelation(
+ nameParts: Seq[String],
+ catalog: CatalogPlugin,
+ ident: Identifier,
+ view: View,
+ existingChain: Seq[Seq[String]] = Seq.empty): LogicalPlan = {
+ // Session settings are read before switching to the view's captured SQL
configs, which
+ // don't include them
+ val sessionConf = spark.sessionState.conf
+ val viewIdent = catalog.name +: ident.asMultipartIdentifier
+ val viewChain = if (ViewUtil.referencedByEnabled(sessionConf)) {
+ existingChain :+ viewIdent
+ } else {
+ Seq.empty
+ }
+ val compensate = viewSchemaMode(sessionConf) ==
SparkSQLProperties.VIEW_SCHEMA_MODE_COMPENSATION
- // Apply any necessary rewrites to preserve correct resolution
- val viewCatalogAndNamespace: Seq[String] = view.currentCatalog +:
view.currentNamespace.toSeq
- val rewritten = rewriteIdentifiers(parsed, viewCatalogAndNamespace);
+ // Like Spark's own views, the view body is parsed and analyzed with the
SQL configs captured
+ // at creation, and nested views are expanded within the outer view's
analysis
+ ViewUtil.withNestedView(viewIdent, sessionConf.maxNestedViewDepth) {
+ val viewConf = ViewNode.effectiveSQLConf(ViewUtil.sqlConfigs(view),
isTempView = false)
Review Comment:
Good catch on the ANSI default, thanks. Removed in d9b2889346: CREATE VIEW
no longer captures SQL configs, and views resolve with the session conf as
before. I also dropped the eager analysis of the view body and the nested-depth
check that came with it, so view expansion is back to what it was.
--
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]