Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -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]
Expand All @@ -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)
Expand All @@ -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)))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -93,3 +94,5 @@ class ShowTablesSuite extends CommonShowTablesSuite {
}
}
}

class ShowTablesSuite extends ShowTablesSuiteBase with SharedSparkSession
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}