diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/ShowTablesSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/ShowTablesSuiteBase.scala similarity index 76% rename from sql/core/src/test/scala/org/apache/spark/sql/execution/command/ShowTablesSuite.scala rename to sql/core/src/test/scala/org/apache/spark/sql/execution/command/ShowTablesSuiteBase.scala index 01720b572324..49428fab7902 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/ShowTablesSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/ShowTablesSuiteBase.scala @@ -20,13 +20,13 @@ package org.apache.spark.sql.execution.command import org.scalactic.source.Position import org.scalatest.Tag -import org.apache.spark.sql.Row +import org.apache.spark.sql.{QueryTest, Row} import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._ import org.apache.spark.sql.internal.SQLConf -import org.apache.spark.sql.test.SharedSparkSession +import org.apache.spark.sql.test.SQLTestUtils import org.apache.spark.sql.types.StructType -trait ShowTablesSuite extends SharedSparkSession { +trait ShowTablesSuiteBase extends QueryTest with SQLTestUtils { protected def version: String protected def catalog: String protected def defaultNamespace: Seq[String] @@ -39,7 +39,7 @@ trait ShowTablesSuite extends SharedSparkSession { protected def runShowTablesSql(sqlText: String, expected: Seq[ShowRow]): Unit = { val df = spark.sql(sqlText) assert(df.schema === showSchema) - assert(df.collect() === getRows(expected)) + checkAnswer(df, getRows(expected)) } override def test(testName: String, testTags: Tag*)(testFun: => Any) @@ -63,30 +63,36 @@ trait ShowTablesSuite extends SharedSparkSession { sql(s"CREATE NAMESPACE $catalog.ns2") withTable( s"$catalog.ns1.table", - s"$catalog.ns1.table_name_1", - s"$catalog.ns1.table_name_2", - s"$catalog.ns2.table_name_2") { + s"$catalog.ns1.table_name_1a", + s"$catalog.ns1.table_name_2b", + s"$catalog.ns2.table_name_2b") { sql(s"CREATE TABLE $catalog.ns1.table (id bigint, data string) $defaultUsing") - sql(s"CREATE TABLE $catalog.ns1.table_name_1 (id bigint, data string) $defaultUsing") - sql(s"CREATE TABLE $catalog.ns1.table_name_2 (id bigint, data string) $defaultUsing") - sql(s"CREATE TABLE $catalog.ns2.table_name_2 (id bigint, data string) $defaultUsing") + sql(s"CREATE TABLE $catalog.ns1.table_name_1a (id bigint, data string) $defaultUsing") + sql(s"CREATE TABLE $catalog.ns1.table_name_2b (id bigint, data string) $defaultUsing") + sql(s"CREATE TABLE $catalog.ns2.table_name_2b (id bigint, data string) $defaultUsing") runShowTablesSql( s"SHOW TABLES FROM $catalog.ns1", Seq( ShowRow("ns1", "table", false), - ShowRow("ns1", "table_name_1", false), - ShowRow("ns1", "table_name_2", false))) + ShowRow("ns1", "table_name_1a", false), + ShowRow("ns1", "table_name_2b", false))) runShowTablesSql( s"SHOW TABLES FROM $catalog.ns1 LIKE '*name*'", Seq( - ShowRow("ns1", "table_name_1", false), - ShowRow("ns1", "table_name_2", false))) + ShowRow("ns1", "table_name_1a", false), + ShowRow("ns1", "table_name_2b", false))) runShowTablesSql( - s"SHOW TABLES FROM $catalog.ns1 LIKE '*2'", - Seq(ShowRow("ns1", "table_name_2", false))) + s"SHOW TABLES FROM $catalog.ns1 LIKE 'table_name_1*|table_name_2*'", + Seq( + ShowRow("ns1", "table_name_1a", false), + ShowRow("ns1", "table_name_2b", false))) + + runShowTablesSql( + s"SHOW TABLES FROM $catalog.ns1 LIKE '*2b'", + Seq(ShowRow("ns1", "table_name_2b", false))) } } } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/ShowTablesSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/ShowTablesSuite.scala index feb3bc623f3f..d2332818d954 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/ShowTablesSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/ShowTablesSuite.scala @@ -20,10 +20,11 @@ package org.apache.spark.sql.execution.command.v1 import org.apache.spark.sql.{AnalysisException, Row} import org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException import org.apache.spark.sql.connector.catalog.CatalogManager -import org.apache.spark.sql.execution.command.{ShowTablesSuite => CommonShowTablesSuite} +import org.apache.spark.sql.execution.command +import org.apache.spark.sql.test.SharedSparkSession import org.apache.spark.sql.types.{BooleanType, StringType, StructType} -class ShowTablesSuite extends CommonShowTablesSuite { +trait ShowTablesSuiteBase extends command.ShowTablesSuiteBase { override def version: String = "V1" override def catalog: String = CatalogManager.SESSION_CATALOG_NAME override def defaultNamespace: Seq[String] = Seq("default") @@ -93,3 +94,5 @@ class ShowTablesSuite extends CommonShowTablesSuite { } } } + +class ShowTablesSuite extends ShowTablesSuiteBase with SharedSparkSession diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala index 668120ae1cad..c7f68863a179 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala @@ -21,10 +21,11 @@ import org.apache.spark.SparkConf import org.apache.spark.sql.{AnalysisException, Row} import org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException import org.apache.spark.sql.connector.InMemoryTableCatalog -import org.apache.spark.sql.execution.command.{ShowTablesSuite => CommonShowTablesSuite} +import org.apache.spark.sql.execution.command +import org.apache.spark.sql.test.SharedSparkSession import org.apache.spark.sql.types.{StringType, StructType} -class ShowTablesSuite extends CommonShowTablesSuite { +class ShowTablesSuite extends command.ShowTablesSuiteBase with SharedSparkSession { override def version: String = "V2" override def catalog: String = "test_catalog" override def defaultNamespace: Seq[String] = Nil diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala index dcec8bf5c0cc..a78fd506b752 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala @@ -95,28 +95,6 @@ class HiveCommandSuite extends QueryTest with SQLTestUtils with TestHiveSingleto } } - test("show tables") { - withTable("show1a", "show2b") { - sql("CREATE TABLE show1a(c1 int)") - sql("CREATE TABLE show2b(c2 int)") - checkAnswer( - sql("SHOW TABLES IN default 'show1*'"), - Row("default", "show1a", false) :: Nil) - checkAnswer( - sql("SHOW TABLES IN default 'show1*|show2*'"), - Row("default", "show1a", false) :: - Row("default", "show2b", false) :: Nil) - checkAnswer( - sql("SHOW TABLES 'show1*|show2*'"), - Row("default", "show1a", false) :: - Row("default", "show2b", false) :: Nil) - assert( - sql("SHOW TABLES").count() >= 2) - assert( - sql("SHOW TABLES IN default").count() >= 2) - } - } - test("show views") { withView("show1a", "show2b", "global_temp.temp1", "temp2") { sql("CREATE VIEW show1a AS SELECT 1 AS id") diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/ShowTablesSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/ShowTablesSuite.scala new file mode 100644 index 000000000000..836f080d28e7 --- /dev/null +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/ShowTablesSuite.scala @@ -0,0 +1,26 @@ +/* + * 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.hive.execution.command + +import org.apache.spark.sql.execution.command.v1 +import org.apache.spark.sql.hive.test.TestHiveSingleton + +class ShowTablesSuite extends v1.ShowTablesSuiteBase with TestHiveSingleton { + override def version: String = "Hive V1" + override def defaultUsing: String = "USING HIVE" +}