imback82 commented on a change in pull request #25247: [SPARK-28319][SQL]
Implement SHOW TABLES for Data Source V2 Tables
URL: https://github.com/apache/spark/pull/25247#discussion_r312777236
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/sources/v2/DataSourceV2SQLSuite.scala
##########
@@ -1700,6 +1704,126 @@ class DataSourceV2SQLSuite extends QueryTest with
SharedSQLContext with BeforeAn
}
}
+ test("ShowTables: using v2 catalog") {
+ spark.sql("CREATE TABLE testcat.db.table_name (id bigint, data string)
USING foo")
+ spark.sql("CREATE TABLE testcat.n1.n2.db.table_name (id bigint, data
string) USING foo")
+
+ runShowTablesSql("SHOW TABLES FROM testcat.db", Seq(Row("db",
"table_name")))
+
+ runShowTablesSql(
+ "SHOW TABLES FROM testcat.n1.n2.db",
+ Seq(Row("n1.n2.db", "table_name")))
+ }
+
+ test("ShowTables: using v2 catalog with a pattern") {
+ spark.sql("CREATE TABLE testcat.db.table (id bigint, data string) USING
foo")
+ spark.sql("CREATE TABLE testcat.db.table_name_1 (id bigint, data string)
USING foo")
+ spark.sql("CREATE TABLE testcat.db.table_name_2 (id bigint, data string)
USING foo")
+ spark.sql("CREATE TABLE testcat.db2.table_name_2 (id bigint, data string)
USING foo")
+
+ runShowTablesSql(
+ "SHOW TABLES FROM testcat.db",
+ Seq(
+ Row("db", "table"),
+ Row("db", "table_name_1"),
+ Row("db", "table_name_2")))
+
+ runShowTablesSql(
+ "SHOW TABLES FROM testcat.db LIKE '*name*'",
+ Seq(Row("db", "table_name_1"), Row("db", "table_name_2")))
+
+ runShowTablesSql(
+ "SHOW TABLES FROM testcat.db LIKE '*2'",
+ Seq(Row("db", "table_name_2")))
+ }
+
+ test("ShowTables: using v2 catalog, namespace doesn't exist") {
+ runShowTablesSql("SHOW TABLES FROM testcat.unknown", Seq())
Review comment:
@cloud-fan as far as I understand, throwing `NoSuchNamespaceException` is
optional in v2:
```
/**
* List the tables in a namespace from the catalog.
* <p>
* If the catalog supports views, this must return identifiers for only
tables and not views.
*
* @param namespace a multi-part namespace
* @return an array of Identifiers for tables
* @throws NoSuchNamespaceException If the namespace does not exist
(optional).
*/
Identifier[] listTables(String[] namespace) throws
NoSuchNamespaceException;
```
I can update `TestInMemoryTableCatalog` to throw NoSuchNamespaceException if
there is no namespace existing for the tables created. However, I am not sure
if this is the right approach since you could have created namespace without
tables - in v1, you could have done `CREATE DATABASE db` without creating
tables belonging to `db`, although I don't think this scenario is supported in
v2 yet.
Please advise how this needs to be handled. Thanks!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]