diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/unresolved.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/unresolved.scala index 1c72ec0d69980..b1dcb465b4778 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/unresolved.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/unresolved.scala @@ -104,12 +104,11 @@ object UnresolvedRelation { tableIdentifier: TableIdentifier, extraOptions: CaseInsensitiveStringMap, isStreaming: Boolean): UnresolvedRelation = { - UnresolvedRelation( - tableIdentifier.database.toSeq :+ tableIdentifier.table, extraOptions, isStreaming) + UnresolvedRelation(tableIdentifier.nameParts, extraOptions, isStreaming) } def apply(tableIdentifier: TableIdentifier): UnresolvedRelation = - UnresolvedRelation(tableIdentifier.database.toSeq :+ tableIdentifier.table) + UnresolvedRelation(tableIdentifier.nameParts) } /** diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala index 0c66e6ae89c66..df396bf054849 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala @@ -26,6 +26,7 @@ import org.apache.spark.sql.catalyst.plans._ import org.apache.spark.sql.catalyst.plans.logical._ import org.apache.spark.sql.internal.SQLConf import org.apache.spark.sql.types.{Decimal, DecimalType, IntegerType, LongType, StringType} +import org.apache.spark.sql.util.CaseInsensitiveStringMap /** * Parser test cases for rules defined in [[CatalystSqlParser]] / [[AstBuilder]]. @@ -1893,4 +1894,15 @@ class PlanParserSuite extends AnalysisTest { parsePlan("SELECT * FROM a LIMIT ?"), table("a").select(star()).limit(PosParameter(22))) } + + test("SPARK-45189: Creating UnresolvedRelation from TableIdentifier should include the" + + " catalog field") { + val tableId = TableIdentifier("t", Some("db"), Some("cat")) + val unresolvedRelation = UnresolvedRelation(tableId) + assert(unresolvedRelation.multipartIdentifier == Seq("cat", "db", "t")) + val unresolvedRelation2 = UnresolvedRelation(tableId, CaseInsensitiveStringMap.empty, true) + assert(unresolvedRelation2.multipartIdentifier == Seq("cat", "db", "t")) + assert(unresolvedRelation2.options == CaseInsensitiveStringMap.empty) + assert(unresolvedRelation2.isStreaming) + } }