Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
58f4134
Draft of ShowTablesSuite
MaxGekk Nov 5, 2020
7b8746f
ShowTablesSuite for v2
MaxGekk Nov 5, 2020
4c0d2b8
test "show table in a not existing namespace"
MaxGekk Nov 5, 2020
f1aa46c
test "show an existing table in V1 catalog"
MaxGekk Nov 5, 2020
3a85ac3
Move "ShowTables: using v2 catalog" to v2/ShowTablesSuite
MaxGekk Nov 6, 2020
0534480
Move v2 pattern tests
MaxGekk Nov 6, 2020
7c12702
Move more v1 tests
MaxGekk Nov 6, 2020
327179e
Move more v2 tests
MaxGekk Nov 7, 2020
c07e08b
Move "namespace not specified and default v2 catalog not set - fallba…
MaxGekk Nov 7, 2020
7738473
Move "SHOW TABLE EXTENDED valid v1"
MaxGekk Nov 7, 2020
91521ce
Move "SHOW TABLE EXTENDED not valid v1 database"
MaxGekk Nov 7, 2020
79b0fd0
Introduce ShowRow
MaxGekk Nov 7, 2020
e282bb5
Move "show tables with a pattern" to common trait
MaxGekk Nov 7, 2020
70a578d
Remove duplicate tests
MaxGekk Nov 7, 2020
d21dd5e
Move "SHOW TABLE EXTENDED for default" to the common trait
MaxGekk Nov 7, 2020
48509fb
Change default USING in v2
MaxGekk Nov 7, 2020
b5a6187
Add a comment for "show tables in nested namespaces"
MaxGekk Nov 7, 2020
bdc249a
Add comment for "show table in a not existing namespace"
MaxGekk Nov 7, 2020
ef2b536
Remove duplicate test from v1
MaxGekk Nov 7, 2020
122faa5
Move SHOW VIEWS test back to DataSourceV2SQLSuite
MaxGekk Nov 7, 2020
3016f69
Add comment for the test "using v2 catalog with empty namespace"
MaxGekk Nov 7, 2020
53d0c77
Add comment for the test "namespace is not specified and default v2 c…
MaxGekk Nov 7, 2020
ebfa670
Add comment for the test "SHOW TABLE EXTENDED not valid v1 database"
MaxGekk Nov 7, 2020
dbf8e76
Minor: fix test titles
MaxGekk Nov 7, 2020
1829685
Move a show view test back to DataSourceV2SQLSuite
MaxGekk Nov 7, 2020
7d3b4b2
Fix test title
MaxGekk Nov 7, 2020
80eb4a8
Refactoring
MaxGekk Nov 7, 2020
f0152e6
Minor changes
MaxGekk Nov 7, 2020
8e55686
Using foo -> Using _
MaxGekk Nov 7, 2020
4364a02
Remove beforeAll()
MaxGekk Nov 7, 2020
529a858
Move parsing tests to the common trait
MaxGekk Nov 7, 2020
947c8bc
Move the current catalog test
MaxGekk Nov 7, 2020
dd1f335
Add "TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2"
MaxGekk Nov 9, 2020
70922c7
Add "TODO(SPARK-33394): Throw `NoSuchDatabaseException` for not exist…
MaxGekk Nov 9, 2020
a62486f
Use CatalogManager.SESSION_CATALOG_NAME
MaxGekk Nov 9, 2020
b608f8b
Move parsing tests to ShowTablesParserSuite
MaxGekk Nov 9, 2020
3a3bc57
Move the SHOW TABLE EXTENDED test out from the common trait
MaxGekk Nov 9, 2020
1c7f63c
Split the test "namespace is not specified and the default catalog is…
MaxGekk Nov 9, 2020
3d82b4e
Add TODO(SPARK-33403)
MaxGekk Nov 9, 2020
d264962
Adjust test title
MaxGekk Nov 9, 2020
286e11a
Move withSourceViews() out from the common trait
MaxGekk Nov 9, 2020
aafa7f8
refine tests
cloud-fan Nov 10, 2020
6286152
Merge pull request #28 from cloud-fan/help
MaxGekk Nov 10, 2020
94b337d
Override test()
MaxGekk Nov 10, 2020
5f37a4c
Remove some parent classes
MaxGekk Nov 10, 2020
ca2f96a
Refactoring
MaxGekk Nov 10, 2020
8108cb1
Remove an unused import
MaxGekk Nov 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1233,55 +1233,6 @@ class DDLParserSuite extends AnalysisTest {
assert(exc.getMessage.contains("There must be at least one WHEN clause in a MERGE statement"))
}

test("show tables") {
comparePlans(
parsePlan("SHOW TABLES"),
ShowTables(UnresolvedNamespace(Seq.empty[String]), None))
comparePlans(
parsePlan("SHOW TABLES '*test*'"),
ShowTables(UnresolvedNamespace(Seq.empty[String]), Some("*test*")))
comparePlans(
parsePlan("SHOW TABLES LIKE '*test*'"),
ShowTables(UnresolvedNamespace(Seq.empty[String]), Some("*test*")))
comparePlans(
parsePlan("SHOW TABLES FROM testcat.ns1.ns2.tbl"),
ShowTables(UnresolvedNamespace(Seq("testcat", "ns1", "ns2", "tbl")), None))
comparePlans(
parsePlan("SHOW TABLES IN testcat.ns1.ns2.tbl"),
ShowTables(UnresolvedNamespace(Seq("testcat", "ns1", "ns2", "tbl")), None))
comparePlans(
parsePlan("SHOW TABLES IN ns1 '*test*'"),
ShowTables(UnresolvedNamespace(Seq("ns1")), Some("*test*")))
comparePlans(
parsePlan("SHOW TABLES IN ns1 LIKE '*test*'"),
ShowTables(UnresolvedNamespace(Seq("ns1")), Some("*test*")))
}

test("show table extended") {
comparePlans(
parsePlan("SHOW TABLE EXTENDED LIKE '*test*'"),
ShowTableStatement(None, "*test*", None))
comparePlans(
parsePlan("SHOW TABLE EXTENDED FROM testcat.ns1.ns2 LIKE '*test*'"),
ShowTableStatement(Some(Seq("testcat", "ns1", "ns2")), "*test*", None))
comparePlans(
parsePlan("SHOW TABLE EXTENDED IN testcat.ns1.ns2 LIKE '*test*'"),
ShowTableStatement(Some(Seq("testcat", "ns1", "ns2")), "*test*", None))
comparePlans(
parsePlan("SHOW TABLE EXTENDED LIKE '*test*' PARTITION(ds='2008-04-09', hr=11)"),
ShowTableStatement(None, "*test*", Some(Map("ds" -> "2008-04-09", "hr" -> "11"))))
comparePlans(
parsePlan("SHOW TABLE EXTENDED FROM testcat.ns1.ns2 LIKE '*test*' " +
"PARTITION(ds='2008-04-09')"),
ShowTableStatement(Some(Seq("testcat", "ns1", "ns2")), "*test*",
Some(Map("ds" -> "2008-04-09"))))
comparePlans(
parsePlan("SHOW TABLE EXTENDED IN testcat.ns1.ns2 LIKE '*test*' " +
"PARTITION(ds='2008-04-09')"),
ShowTableStatement(Some(Seq("testcat", "ns1", "ns2")), "*test*",
Some(Map("ds" -> "2008-04-09"))))
}

test("show views") {
comparePlans(
parsePlan("SHOW VIEWS"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,71 +898,9 @@ class DataSourceV2SQLSuite
}
}

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())
}

test("ShowTables: using v1 catalog") {
runShowTablesSql(
"SHOW TABLES FROM default",
Seq(Row("", "source", true), Row("", "source2", true)),
expectV2Catalog = false)
}

test("ShowTables: using v1 catalog, db doesn't exist ") {
// 'db' below resolves to a database name for v1 catalog because there is no catalog named
// 'db' and there is no default catalog set.
val exception = intercept[NoSuchDatabaseException] {
runShowTablesSql("SHOW TABLES FROM db", Seq(), expectV2Catalog = false)
}

assert(exception.getMessage.contains("Database 'db' not found"))
}

test("ShowTables: using v1 catalog, db name with multipartIdentifier ('a.b') is not allowed.") {
val exception = intercept[AnalysisException] {
runShowTablesSql("SHOW TABLES FROM a.b", Seq(), expectV2Catalog = false)
}

assert(exception.getMessage.contains("The database name is not valid: a.b"))
}

test("ShowViews: using v1 catalog, db name with multipartIdentifier ('a.b') is not allowed.") {
val exception = intercept[AnalysisException] {
sql("SHOW TABLES FROM a.b")
sql("SHOW VIEWS FROM a.b")
}

assert(exception.getMessage.contains("The database name is not valid: a.b"))
Expand All @@ -977,48 +915,6 @@ class DataSourceV2SQLSuite
" only SessionCatalog supports this command."))
}

test("ShowTables: using v2 catalog with empty namespace") {
spark.sql("CREATE TABLE testcat.table (id bigint, data string) USING foo")
runShowTablesSql("SHOW TABLES FROM testcat", Seq(Row("", "table")))
}

test("ShowTables: namespace is not specified and default v2 catalog is set") {
spark.conf.set(SQLConf.DEFAULT_CATALOG.key, "testcat")
spark.sql("CREATE TABLE testcat.table (id bigint, data string) USING foo")

// v2 catalog is used where default namespace is empty for TestInMemoryTableCatalog.
runShowTablesSql("SHOW TABLES", Seq(Row("", "table")))
}

test("ShowTables: namespace not specified and default v2 catalog not set - fallback to v1") {
runShowTablesSql(
"SHOW TABLES",
Seq(Row("", "source", true), Row("", "source2", true)),
expectV2Catalog = false)

runShowTablesSql(
"SHOW TABLES LIKE '*2'",
Seq(Row("", "source2", true)),
expectV2Catalog = false)
}

test("ShowTables: change current catalog and namespace with USE statements") {
sql("CREATE TABLE testcat.ns1.ns2.table (id bigint) USING foo")

// Initially, the v2 session catalog (current catalog) is used.
runShowTablesSql(
"SHOW TABLES", Seq(Row("", "source", true), Row("", "source2", true)),
expectV2Catalog = false)

// Update the current catalog, and no table is matched since the current namespace is Array().
sql("USE testcat")
runShowTablesSql("SHOW TABLES", Seq())

// Update the current namespace to match ns1.ns2.table.
sql("USE testcat.ns1.ns2")
runShowTablesSql("SHOW TABLES", Seq(Row("ns1.ns2", "table")))
}

private def runShowTablesSql(
sqlText: String,
expected: Seq[Row],
Expand All @@ -1039,50 +935,6 @@ class DataSourceV2SQLSuite
assert(expected === df.collect())
}

test("SHOW TABLE EXTENDED not valid v1 database") {
def testV1CommandNamespace(sqlCommand: String, namespace: String): Unit = {
val e = intercept[AnalysisException] {
sql(sqlCommand)
}
assert(e.message.contains(s"The database name is not valid: ${namespace}"))
}

val namespace = "testcat.ns1.ns2"
val table = "tbl"
withTable(s"$namespace.$table") {
sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
s"USING foo PARTITIONED BY (id)")

testV1CommandNamespace(s"SHOW TABLE EXTENDED FROM $namespace LIKE 'tb*'",
namespace)
testV1CommandNamespace(s"SHOW TABLE EXTENDED IN $namespace LIKE 'tb*'",
namespace)
testV1CommandNamespace("SHOW TABLE EXTENDED " +
s"FROM $namespace LIKE 'tb*' PARTITION(id=1)",
namespace)
testV1CommandNamespace("SHOW TABLE EXTENDED " +
s"IN $namespace LIKE 'tb*' PARTITION(id=1)",
namespace)
}
}

test("SHOW TABLE EXTENDED valid v1") {
val expected = Seq(Row("", "source", true), Row("", "source2", true))
val schema = new StructType()
.add("database", StringType, nullable = false)
.add("tableName", StringType, nullable = false)
.add("isTemporary", BooleanType, nullable = false)
.add("information", StringType, nullable = false)

val df = sql("SHOW TABLE EXTENDED FROM default LIKE '*source*'")
val result = df.collect()
val resultWithoutInfo = result.map{ case Row(db, table, temp, _) => Row(db, table, temp)}

assert(df.schema === schema)
assert(resultWithoutInfo === expected)
result.foreach{ case Row(_, _, _, info: String) => assert(info.nonEmpty)}
}

test("CreateNameSpace: basic tests") {
// Session catalog is used.
withNamespace("ns") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark.sql.execution.command

import org.apache.spark.sql.catalyst.analysis.{AnalysisTest, UnresolvedNamespace}
import org.apache.spark.sql.catalyst.parser.CatalystSqlParser.parsePlan
import org.apache.spark.sql.catalyst.plans.logical.{ShowTables, ShowTableStatement}
import org.apache.spark.sql.test.SharedSparkSession

class ShowTablesParserSuite extends AnalysisTest with SharedSparkSession {
private val catalog = "test_catalog"

test("show tables") {
comparePlans(
parsePlan("SHOW TABLES"),
ShowTables(UnresolvedNamespace(Seq.empty[String]), None))
comparePlans(
parsePlan("SHOW TABLES '*test*'"),
ShowTables(UnresolvedNamespace(Seq.empty[String]), Some("*test*")))
comparePlans(
parsePlan("SHOW TABLES LIKE '*test*'"),
ShowTables(UnresolvedNamespace(Seq.empty[String]), Some("*test*")))
comparePlans(
parsePlan(s"SHOW TABLES FROM $catalog.ns1.ns2.tbl"),
ShowTables(UnresolvedNamespace(Seq(catalog, "ns1", "ns2", "tbl")), None))
comparePlans(
parsePlan(s"SHOW TABLES IN $catalog.ns1.ns2.tbl"),
ShowTables(UnresolvedNamespace(Seq(catalog, "ns1", "ns2", "tbl")), None))
comparePlans(
parsePlan("SHOW TABLES IN ns1 '*test*'"),
ShowTables(UnresolvedNamespace(Seq("ns1")), Some("*test*")))
comparePlans(
parsePlan("SHOW TABLES IN ns1 LIKE '*test*'"),
ShowTables(UnresolvedNamespace(Seq("ns1")), Some("*test*")))
}

test("show table extended") {
comparePlans(
parsePlan("SHOW TABLE EXTENDED LIKE '*test*'"),
ShowTableStatement(None, "*test*", None))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imback82 do you know why we still have ShowTableStatement here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We parse SHOW TABLE EXTENDED:

| SHOW TABLE EXTENDED ((FROM | IN) ns=multipartIdentifier)?
LIKE pattern=STRING partitionSpec? #showTable

and convert it to ShowTableStatement :
override def visitShowTable(ctx: ShowTableContext): LogicalPlan = withOrigin(ctx) {
ShowTableStatement(
Option(ctx.ns).map(visitMultipartIdentifier),
string(ctx.pattern),
Option(ctx.partitionSpec).map(visitNonOptionalPartitionSpec))
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cloud-fan ShowTable is not migrated yet; only ShowTables with "s" is migrated. I will work on this migration soon.

comparePlans(
parsePlan(s"SHOW TABLE EXTENDED FROM $catalog.ns1.ns2 LIKE '*test*'"),
ShowTableStatement(Some(Seq(catalog, "ns1", "ns2")), "*test*", None))
comparePlans(
parsePlan(s"SHOW TABLE EXTENDED IN $catalog.ns1.ns2 LIKE '*test*'"),
ShowTableStatement(Some(Seq(catalog, "ns1", "ns2")), "*test*", None))
comparePlans(
parsePlan("SHOW TABLE EXTENDED LIKE '*test*' PARTITION(ds='2008-04-09', hr=11)"),
ShowTableStatement(None, "*test*", Some(Map("ds" -> "2008-04-09", "hr" -> "11"))))
comparePlans(
parsePlan(s"SHOW TABLE EXTENDED FROM $catalog.ns1.ns2 LIKE '*test*' " +
"PARTITION(ds='2008-04-09')"),
ShowTableStatement(Some(Seq(catalog, "ns1", "ns2")), "*test*",
Some(Map("ds" -> "2008-04-09"))))
comparePlans(
parsePlan(s"SHOW TABLE EXTENDED IN $catalog.ns1.ns2 LIKE '*test*' " +
"PARTITION(ds='2008-04-09')"),
ShowTableStatement(Some(Seq(catalog, "ns1", "ns2")), "*test*",
Some(Map("ds" -> "2008-04-09"))))
}
}
Loading