Skip to content

[SPARK-29947][SQL][followup] ResolveRelations should return relations with fresh attribute IDs #28717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ class Analyzer(
private def lookupRelation(identifier: Seq[String]): Option[LogicalPlan] = {
expandRelationName(identifier) match {
case SessionCatalogAndIdentifier(catalog, ident) =>
def loaded = CatalogV2Util.loadTable(catalog, ident).map {
lazy val loaded = CatalogV2Util.loadTable(catalog, ident).map {
case v1Table: V1Table =>
v1SessionCatalog.getRelation(v1Table.v1Table)
case table =>
Expand All @@ -1024,7 +1024,12 @@ class Analyzer(
DataSourceV2Relation.create(table, Some(catalog), Some(ident)))
}
val key = catalog.name +: ident.namespace :+ ident.name
Option(AnalysisContext.get.relationCache.getOrElseUpdate(key, loaded.orNull))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just:

Option(AnalysisContext.get.relationCache.getOrElseUpdate(key, loaded.orNull)).map { rel =>
  rel.transform { case multi: MultiInstanceRelation => multi.newInstance() }
} 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry just saw your comment after running the merge script.

We only need to refresh the attributes if we get the relation from the cache. Otherwise, it's already a fresh relation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is correct, but IMO it's a little cleaner. Creating new attributes should be super cheap, and not worth having a orElses and foreachs.

AnalysisContext.get.relationCache.get(key).map(_.transform {
case multi: MultiInstanceRelation => multi.newInstance()
}).orElse {
loaded.foreach(AnalysisContext.get.relationCache.update(key, _))
loaded
}
case _ => None
}
}
Expand Down