mihailoale-db commented on code in PR #60722:
URL: https://github.com/apache/spark/pull/60722#discussion_r4632115982
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/RelationResolutionSuite.scala:
##########
Review Comment:
This is refactor only change. I would remove these tests (unnecessary
overhead).
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/RelationResolution.scala:
##########
@@ -112,6 +114,89 @@ class RelationResolution(
Seq(nameParts.last)
}
+ /**
+ * Resolves relations to `ResolvedTable` or `Resolved[Temp/Persistent]View`.
This is
+ * for resolving DDL and misc commands. UnresolvedView callers reject
non-view results
+ * downstream via `expectViewNotTableError`.
+ *
+ * When `viewOnly=true`, non-session catalogs that do not implement
[[ViewCatalog]] are
+ * rejected up front with MISSING_CATALOG_ABILITY.VIEWS -- they cannot host
views at all,
+ * so surfacing a downstream "view not found" would hide the real reason.
+ *
+ * Lookup order against a non-session catalog:
+ * 1. If the catalog is a [[RelationCatalog]],
[[RelationCatalog.loadRelation]] is called
+ * once. A returned [[org.apache.spark.sql.connector.catalog.View]] is
interpreted as a
+ * view; a [[Table]] is a table.
+ * 2. Otherwise, [[TableCatalog.loadTable]] is tried (when implemented),
then
+ * [[ViewCatalog.loadView]] as the fallback view-resolution path (when
implemented).
+ */
+ def lookupTableOrView(
+ identifier: Seq[String],
+ viewOnly: Boolean = false): Option[LogicalPlan] = {
+ lookupTempView(identifier).map { tempView =>
+ ResolvedTempView(identifier.asIdentifier, tempView.tableMeta)
+ }.orElse {
+ expandIdentifier(identifier) match {
+ case CatalogAndIdentifier(catalog, ident) =>
+ if (viewOnly && !CatalogV2Util.isSessionCatalog(catalog) &&
+ !catalog.isInstanceOf[ViewCatalog]) {
+ throw
QueryCompilationErrors.missingCatalogViewsAbilityError(catalog)
+ }
+ catalog match {
+ case mc: RelationCatalog =>
+ // Single-RPC perf path: loadRelation returns a Table for a
table or a View
Review Comment:
Let's move inline comments to Scala doc to improve readability.
--
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]