Skip to content

Commit

Permalink
[SPARK-50174][SQL] Factor out UnresolvedCatalogRelation resolution
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

Factor out `UnresolvedCatalogRelation` resolution into a separate `FindDataSourceTable` method to reuse it in the single-pass Analyzer.

### Why are the changes needed?

Context: https://issues.apache.org/jira/browse/SPARK-49834

### 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?

copilot.vim.

Closes apache#48707 from vladimirg-db/vladimirg-db/master.

Authored-by: Vladimir Golubev <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
  • Loading branch information
vladimirg-db authored and MaxGekk committed Oct 30, 2024
1 parent 2316fed commit b7ac624
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,8 @@ class FindDataSourceTable(sparkSession: SparkSession) extends Rule[LogicalPlan]
table.partitionColumnNames.map(name => name -> None).toMap,
Seq.empty, append.query, false, append.isByName)

case UnresolvedCatalogRelation(tableMeta, options, false)
if DDLUtils.isDatasourceTable(tableMeta) =>
readDataSourceTable(tableMeta, options)

case UnresolvedCatalogRelation(tableMeta, _, false) =>
DDLUtils.readHiveTable(tableMeta)

case UnresolvedCatalogRelation(tableMeta, extraOptions, true) =>
getStreamingRelation(tableMeta, extraOptions)
case unresolvedCatalogRelation: UnresolvedCatalogRelation =>
resolveUnresolvedCatalogRelation(unresolvedCatalogRelation)

case s @ StreamingRelationV2(
_, _, table, extraOptions, _, _, _, Some(UnresolvedCatalogRelation(tableMeta, _, true))) =>
Expand All @@ -320,6 +313,21 @@ class FindDataSourceTable(sparkSession: SparkSession) extends Rule[LogicalPlan]
v1Relation
}
}

def resolveUnresolvedCatalogRelation(
unresolvedCatalogRelation: UnresolvedCatalogRelation): LogicalPlan = {
unresolvedCatalogRelation match {
case UnresolvedCatalogRelation(tableMeta, options, false)
if DDLUtils.isDatasourceTable(tableMeta) =>
readDataSourceTable(tableMeta, options)

case UnresolvedCatalogRelation(tableMeta, _, false) =>
DDLUtils.readHiveTable(tableMeta)

case UnresolvedCatalogRelation(tableMeta, extraOptions, true) =>
getStreamingRelation(tableMeta, extraOptions)
}
}
}


Expand Down

0 comments on commit b7ac624

Please sign in to comment.