Skip to content

Commit 3f5a2b9

Browse files
manuzhangdongjoon-hyun
authored andcommitted
[SPARK-54491][SQL] Fix insert into temp view on DSv2 table failure
### What changes were proposed in this pull request? Resolve `V2TableReference` for table in `InsertIntoStatement`. ### Why are the changes needed? #52876 brought in `V2TableReference` which broke relation resolution for insert into temp view on DSv2 table. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Add UT. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #53196 from manuzhang/FIX-SPARK-54491. Authored-by: manuzhang <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 8efec56 commit 3f5a2b9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,8 @@ class Analyzer(
12071207
val relation = table match {
12081208
case u: UnresolvedRelation if !u.isStreaming =>
12091209
resolveRelation(u).getOrElse(u)
1210+
case r: V2TableReference =>
1211+
relationResolution.resolveReference(r)
12101212
case other => other
12111213
}
12121214

sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2SQLSuite.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3986,6 +3986,19 @@ class DataSourceV2SQLSuiteV1Filter
39863986
}
39873987
}
39883988

3989+
test("SPARK-54491: insert into temp view on DSv2 table") {
3990+
val t = s"testcat.default.t"
3991+
val v = "v"
3992+
withTable(t) {
3993+
withTempView(v) {
3994+
sql(s"CREATE TABLE $t (id INT) USING foo")
3995+
spark.table(t).createOrReplaceTempView(v)
3996+
sql(s"INSERT INTO v VALUES (1)")
3997+
checkAnswer(sql(s"SELECT * FROM $t"), Seq(Row(1)))
3998+
}
3999+
}
4000+
}
4001+
39894002
private def testNotSupportedV2Command(
39904003
sqlCommand: String,
39914004
sqlParams: String,

0 commit comments

Comments
 (0)