Skip to content

Commit 5588cd5

Browse files
wForgetpan3793
authored andcommitted
[KYUUBI #2672] Check if the table exists
### _Why are the changes needed?_ close #2672 ### _How was this patch tested?_ - [X] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #2673 from wForget/KYUUBI-2672. Closes #2672 a6c30d5 [wforget] [KYUUBI-2672] Check if the table exists Authored-by: wforget <643348094@qq.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent b40bcbd commit 5588cd5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

extensions/spark/kyuubi-spark-connector-tpcds/src/main/scala/org/apache/kyuubi/spark/connector/tpcds/TPCDSCatalog.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TPCDSCatalog extends TableCatalog with SupportsNamespaces {
5252
}
5353

5454
override def loadTable(ident: Identifier): SparkTable = (ident.namespace, ident.name) match {
55-
case (Array(db), table) if databases contains db =>
55+
case (Array(db), table) if (databases contains db) && tables.contains(table.toLowerCase) =>
5656
new TPCDSTable(table.toLowerCase, scales(databases indexOf db), options)
5757
case (_, _) => throw new NoSuchTableException(ident)
5858
}

extensions/spark/kyuubi-spark-connector-tpcds/src/test/scala/org/apache/kyuubi/spark/connector/tpcds/TPCDSCatalogSuite.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.kyuubi.spark.connector.tpcds
1919

20-
import org.apache.spark.sql.SparkSession
20+
import org.apache.spark.sql.{AnalysisException, SparkSession}
2121

2222
import org.apache.kyuubi.KyuubiFunSuite
2323

@@ -99,6 +99,13 @@ class TPCDSCatalogSuite extends KyuubiFunSuite {
9999
assertStats("tpcds.sf1.web_site", 8760)
100100
}
101101

102+
test("nonexistent table") {
103+
val exception = intercept[AnalysisException] {
104+
spark.table("tpcds.sf1.nonexistent_table")
105+
}
106+
assert(exception.message === "Table or view not found: tpcds.sf1.nonexistent_table")
107+
}
108+
102109
override def afterAll(): Unit = {
103110
super.afterAll()
104111
spark.stop()

0 commit comments

Comments
 (0)