Skip to content

Commit

Permalink
[SPARK-45189][SQL] Creating UnresolvedRelation from TableIdentifier s…
Browse files Browse the repository at this point in the history
…hould include the catalog field

### What changes were proposed in this pull request?

Creating UnresolvedRelation from TableIdentifier should include the catalog field

### Why are the changes needed?

Fix a issue in a utility method for UnresolvedRelation

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

New unit test

### Was this patch authored or co-authored using generative AI tooling?

No

Closes #42964 from gengliangwang/fixUnresolvedRelation.

Authored-by: Gengliang Wang <[email protected]>
Signed-off-by: Gengliang Wang <[email protected]>
  • Loading branch information
gengliangwang committed Sep 18, 2023
1 parent fd15518 commit 46e0724
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]].
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 46e0724

Please sign in to comment.