Skip to content

Commit b088f39

Browse files
jiaoqingbopan3793
authored andcommitted
[KYUUBI #2540] Kyuubi Spark TPC-DS Connector - SupportsNamespaces
### _Why are the changes needed?_ fix #2540 ### _How was this patch tested?_ - [ ] 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 #2649 from jiaoqingbo/kyuubi2540. Closes #2540 f64150d [jiaoqingbo] code review 9faff90 [jiaoqingbo] [KYUUBI #2540] Kyuubi Spark TPC-DS Connector - SupportsNamespaces Authored-by: jiaoqingbo <1178404354@qq.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent 3187885 commit b088f39

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ package org.apache.kyuubi.spark.connector.tpcds
2020
import java.util
2121

2222
import scala.collection.JavaConverters._
23+
import scala.collection.immutable
2324

2425
import io.trino.tpcds.Table
2526
import org.apache.spark.sql.catalyst.analysis.{NoSuchNamespaceException, NoSuchTableException}
26-
import org.apache.spark.sql.connector.catalog.{Identifier, Table => SparkTable, TableCatalog, TableChange}
27+
import org.apache.spark.sql.connector.catalog.{Identifier, NamespaceChange, SupportsNamespaces, Table => SparkTable, TableCatalog, TableChange}
2728
import org.apache.spark.sql.connector.expressions.Transform
2829
import org.apache.spark.sql.types.StructType
2930
import org.apache.spark.sql.util.CaseInsensitiveStringMap
3031

31-
// TODO: implement SupportsNamespaces
32-
class TPCDSCatalog extends TableCatalog {
32+
class TPCDSCatalog extends TableCatalog with SupportsNamespaces {
3333

3434
val tables: Array[String] = Table.getBaseTables.asScala
3535
.map(_.getName).filterNot(_ == "dbgen_version").toArray
@@ -72,4 +72,37 @@ class TPCDSCatalog extends TableCatalog {
7272

7373
override def renameTable(oldIdent: Identifier, newIdent: Identifier): Unit =
7474
throw new UnsupportedOperationException
75+
76+
override def listNamespaces(): Array[Array[String]] = {
77+
databases.map(Array(_))
78+
}
79+
80+
override def listNamespaces(namespace: Array[String]): Array[Array[String]] = {
81+
namespace match {
82+
case Array() =>
83+
listNamespaces()
84+
case Array(db) if databases contains db =>
85+
Array()
86+
case _ =>
87+
throw new NoSuchNamespaceException(namespace)
88+
}
89+
}
90+
91+
override def loadNamespaceMetadata(namespace: Array[String]): util.Map[String, String] = {
92+
namespace match {
93+
case Array(_) =>
94+
immutable.HashMap[String, String]().asJava
95+
case _ =>
96+
throw new NoSuchNamespaceException(namespace)
97+
}
98+
}
99+
100+
override def createNamespace(namespace: Array[String], metadata: util.Map[String, String]): Unit =
101+
throw new UnsupportedOperationException
102+
103+
override def alterNamespace(namespace: Array[String], changes: NamespaceChange*): Unit =
104+
throw new UnsupportedOperationException
105+
106+
override def dropNamespace(namespace: Array[String]): Boolean =
107+
throw new UnsupportedOperationException
75108
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ class TPCDSCatalogSuite extends KyuubiFunSuite {
3232
.getOrCreate()
3333
}
3434

35+
test("supports namespaces") {
36+
spark.sql("use tpcds")
37+
assert(spark.sql(s"SHOW DATABASES").collect().length == 10)
38+
assert(spark.sql(s"SHOW NAMESPACES IN tpcds.sf1").collect().length == 0)
39+
}
40+
3541
test("tpcds.sf1 count") {
3642
assert(spark.table("tpcds.sf1.call_center").count === 6)
3743
assert(spark.table("tpcds.sf1.catalog_page").count === 11718)

0 commit comments

Comments
 (0)