gengliangwang commented on code in PR #52876:
URL: https://github.com/apache/spark/pull/52876#discussion_r2529313684
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/RelationResolution.scala:
##########
@@ -225,6 +225,44 @@ class RelationResolution(override val catalogManager:
CatalogManager)
}
}
+ def resolveReference(ref: TableReference): LogicalPlan = {
+ val relation = getOrLoadRelation(ref)
+ val planId = ref.getTagValue(LogicalPlan.PLAN_ID_TAG)
+ cloneWithPlanId(relation, planId)
+ }
+
+ private def getOrLoadRelation(ref: TableReference): LogicalPlan = {
+ val key = toCacheKey(ref.catalog, ref.identifier)
+ relationCache.get(key) match {
+ case Some(cached) =>
+ adaptCachedRelation(cached, ref)
+ case None =>
+ val relation = loadRelation(ref)
+ relationCache.update(key, relation)
+ relation
+ }
+ }
+
+ private def loadRelation(ref: TableReference): LogicalPlan = {
+ val table = ref.catalog.loadTable(ref.identifier)
+ TableReferenceUtils.validateLoadedTable(table, ref)
+ val tableName = ref.identifier.toQualifiedNameParts(ref.catalog)
+ SubqueryAlias(tableName, ref.toRelation(table))
+ }
+
+ private def adaptCachedRelation(cached: LogicalPlan, ref: TableReference):
LogicalPlan = {
+ cached transform {
+ case r: DataSourceV2Relation if matchesReference(r, ref) =>
+ r.copy(output = ref.output, options = ref.options)
Review Comment:
QQ: do we need to call `TableReferenceUtils.validateLoadedTable` if it is
cached?
--
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]