MaxGekk commented on code in PR #37588:
URL: https://github.com/apache/spark/pull/37588#discussion_r1364047573
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala:
##########
@@ -404,6 +404,13 @@ class DataSourceV2Strategy(session: SparkSession) extends
Strategy with Predicat
case ShowTables(ResolvedNamespace(catalog, ns), pattern, output) =>
ShowTablesExec(output, catalog.asTableCatalog, ns, pattern) :: Nil
+ case ShowTableExtended(
+ ResolvedNamespace(catalog, ns), pattern,
Review Comment:
nit:
```suggestion
ResolvedNamespace(catalog, ns),
pattern,
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result2 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'$table'")
+ assert(result2.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result2.collect()(0).length == 4)
+ assert(result2.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result3 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'tb*'")
+ assert(result3.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result3.collect()(0).length == 4)
+ assert(result3.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result4 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result4.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result4.collect()(0).length == 4)
+ assert(result4.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result5 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id = 1)")
+ assert(result5.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result5.collect()(0).length == 4)
+ assert(result5.collect()(0)(3) ===
+ """Partition Values: [id=1]
+ |
+ |""".stripMargin)
+
+ val result6 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id = 1)")
+ assert(result6.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result6.collect()(0).length == 4)
+ assert(result6.collect()(0)(3) ===
+ """Partition Values: [id=1]
+ |
+ |""".stripMargin)
+
+ sql(s"ALTER TABLE $tbl SET LOCATION 's3://bucket/path'")
+ val result7 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result7.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result7.collect()(0).length == 4)
+ assert(result7.collect()(0)(1) === "tbl")
+ assert(result7.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Location: s3://bucket/path
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+ }
+ }
+
+ test("show table extended for v2 multi tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ val table1 = "tbl1"
+ val table2 = "tbl2"
+ withTable(table1, table2) {
+ sql(s"CREATE TABLE $catalog.$namespace.$table1 (id1 bigint, data1
string) " +
+ s"$defaultUsing PARTITIONED BY (id1)")
+ sql(s"CREATE TABLE $catalog.$namespace.$table2 (id2 bigint, data2
string) " +
+ s"$defaultUsing PARTITIONED BY (id2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table*'")
+ .sort("tableName")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().length == 3)
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(1) === "tbl")
+ assert(result.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+ assert(result.collect()(1).length == 4)
+ assert(result.collect()(1)(1) === "tbl1")
Review Comment:
```suggestion
assert(result.collect()(1)(1) === table1)
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result2 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'$table'")
+ assert(result2.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result2.collect()(0).length == 4)
+ assert(result2.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
Review Comment:
```suggestion
s"""Namespace: $namespace
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
Review Comment:
```suggestion
s"""Namespace: $namespace
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result2 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'$table'")
+ assert(result2.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result2.collect()(0).length == 4)
+ assert(result2.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result3 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'tb*'")
+ assert(result3.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result3.collect()(0).length == 4)
+ assert(result3.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result4 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result4.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result4.collect()(0).length == 4)
+ assert(result4.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result5 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id = 1)")
+ assert(result5.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result5.collect()(0).length == 4)
+ assert(result5.collect()(0)(3) ===
+ """Partition Values: [id=1]
+ |
+ |""".stripMargin)
+
+ val result6 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id = 1)")
+ assert(result6.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result6.collect()(0).length == 4)
+ assert(result6.collect()(0)(3) ===
+ """Partition Values: [id=1]
+ |
+ |""".stripMargin)
+
+ sql(s"ALTER TABLE $tbl SET LOCATION 's3://bucket/path'")
+ val result7 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result7.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result7.collect()(0).length == 4)
+ assert(result7.collect()(0)(1) === "tbl")
+ assert(result7.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Location: s3://bucket/path
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+ }
+ }
+
+ test("show table extended for v2 multi tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ val table1 = "tbl1"
+ val table2 = "tbl2"
+ withTable(table1, table2) {
+ sql(s"CREATE TABLE $catalog.$namespace.$table1 (id1 bigint, data1
string) " +
+ s"$defaultUsing PARTITIONED BY (id1)")
+ sql(s"CREATE TABLE $catalog.$namespace.$table2 (id2 bigint, data2
string) " +
+ s"$defaultUsing PARTITIONED BY (id2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table*'")
+ .sort("tableName")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().length == 3)
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(1) === "tbl")
+ assert(result.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+ assert(result.collect()(1).length == 4)
+ assert(result.collect()(1)(1) === "tbl1")
+ assert(result.collect()(1)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl1
Review Comment:
```suggestion
|Table: $table1
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result2 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'$table'")
+ assert(result2.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result2.collect()(0).length == 4)
+ assert(result2.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result3 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'tb*'")
+ assert(result3.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result3.collect()(0).length == 4)
+ assert(result3.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result4 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result4.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result4.collect()(0).length == 4)
+ assert(result4.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result5 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id = 1)")
+ assert(result5.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result5.collect()(0).length == 4)
+ assert(result5.collect()(0)(3) ===
+ """Partition Values: [id=1]
+ |
+ |""".stripMargin)
+
+ val result6 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id = 1)")
+ assert(result6.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result6.collect()(0).length == 4)
+ assert(result6.collect()(0)(3) ===
+ """Partition Values: [id=1]
+ |
+ |""".stripMargin)
+
+ sql(s"ALTER TABLE $tbl SET LOCATION 's3://bucket/path'")
+ val result7 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result7.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result7.collect()(0).length == 4)
+ assert(result7.collect()(0)(1) === "tbl")
+ assert(result7.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Location: s3://bucket/path
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+ }
+ }
+
+ test("show table extended for v2 multi tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ val table1 = "tbl1"
+ val table2 = "tbl2"
+ withTable(table1, table2) {
+ sql(s"CREATE TABLE $catalog.$namespace.$table1 (id1 bigint, data1
string) " +
+ s"$defaultUsing PARTITIONED BY (id1)")
+ sql(s"CREATE TABLE $catalog.$namespace.$table2 (id2 bigint, data2
string) " +
+ s"$defaultUsing PARTITIONED BY (id2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table*'")
+ .sort("tableName")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().length == 3)
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(1) === "tbl")
+ assert(result.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+ assert(result.collect()(1).length == 4)
+ assert(result.collect()(1)(1) === "tbl1")
+ assert(result.collect()(1)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl1
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id1`
+ |Schema: root
+ | |-- id1: long (nullable = true)
+ | |-- data1: string (nullable = true)
+ |
+ |""".stripMargin)
+ assert(result.collect()(2).length == 4)
+ assert(result.collect()(2)(1) === "tbl2")
+ assert(result.collect()(2)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl2
Review Comment:
```suggestion
|Table: $table2
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result2 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'$table'")
+ assert(result2.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result2.collect()(0).length == 4)
+ assert(result2.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result3 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'tb*'")
+ assert(result3.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result3.collect()(0).length == 4)
+ assert(result3.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result4 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result4.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result4.collect()(0).length == 4)
+ assert(result4.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
Review Comment:
```suggestion
s"""Namespace: $namespace
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result2 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'$table'")
+ assert(result2.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result2.collect()(0).length == 4)
+ assert(result2.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result3 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'tb*'")
+ assert(result3.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result3.collect()(0).length == 4)
+ assert(result3.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result4 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result4.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result4.collect()(0).length == 4)
+ assert(result4.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result5 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id = 1)")
+ assert(result5.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result5.collect()(0).length == 4)
+ assert(result5.collect()(0)(3) ===
+ """Partition Values: [id=1]
+ |
+ |""".stripMargin)
+
+ val result6 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id = 1)")
+ assert(result6.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result6.collect()(0).length == 4)
+ assert(result6.collect()(0)(3) ===
+ """Partition Values: [id=1]
+ |
+ |""".stripMargin)
+
+ sql(s"ALTER TABLE $tbl SET LOCATION 's3://bucket/path'")
+ val result7 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result7.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result7.collect()(0).length == 4)
+ assert(result7.collect()(0)(1) === "tbl")
+ assert(result7.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
Review Comment:
```suggestion
s"""Namespace: $namespace
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result2 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'$table'")
+ assert(result2.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result2.collect()(0).length == 4)
+ assert(result2.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result3 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'tb*'")
+ assert(result3.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result3.collect()(0).length == 4)
+ assert(result3.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result4 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result4.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result4.collect()(0).length == 4)
+ assert(result4.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
Review Comment:
```suggestion
|Table: $table
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result2 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'$table'")
+ assert(result2.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result2.collect()(0).length == 4)
+ assert(result2.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result3 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'tb*'")
+ assert(result3.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result3.collect()(0).length == 4)
+ assert(result3.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
Review Comment:
```suggestion
|Table: $table
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result2 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'$table'")
+ assert(result2.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result2.collect()(0).length == 4)
+ assert(result2.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result3 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'tb*'")
+ assert(result3.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result3.collect()(0).length == 4)
+ assert(result3.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result4 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result4.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result4.collect()(0).length == 4)
+ assert(result4.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result5 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id = 1)")
+ assert(result5.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result5.collect()(0).length == 4)
+ assert(result5.collect()(0)(3) ===
+ """Partition Values: [id=1]
+ |
+ |""".stripMargin)
+
+ val result6 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id = 1)")
+ assert(result6.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result6.collect()(0).length == 4)
+ assert(result6.collect()(0)(3) ===
+ """Partition Values: [id=1]
+ |
+ |""".stripMargin)
+
+ sql(s"ALTER TABLE $tbl SET LOCATION 's3://bucket/path'")
+ val result7 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'tb*'")
+ assert(result7.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result7.collect()(0).length == 4)
+ assert(result7.collect()(0)(1) === "tbl")
+ assert(result7.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Location: s3://bucket/path
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+ }
+ }
+
+ test("show table extended for v2 multi tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ val table1 = "tbl1"
+ val table2 = "tbl2"
+ withTable(table1, table2) {
+ sql(s"CREATE TABLE $catalog.$namespace.$table1 (id1 bigint, data1
string) " +
+ s"$defaultUsing PARTITIONED BY (id1)")
+ sql(s"CREATE TABLE $catalog.$namespace.$table2 (id2 bigint, data2
string) " +
+ s"$defaultUsing PARTITIONED BY (id2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table*'")
+ .sort("tableName")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().length == 3)
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(1) === "tbl")
+ assert(result.collect()(0)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+ assert(result.collect()(1).length == 4)
+ assert(result.collect()(1)(1) === "tbl1")
+ assert(result.collect()(1)(3) ===
+ s"""Namespace: ns1.ns2
+ |Table: tbl1
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id1`
+ |Schema: root
+ | |-- id1: long (nullable = true)
+ | |-- data1: string (nullable = true)
+ |
+ |""".stripMargin)
+ assert(result.collect()(2).length == 4)
+ assert(result.collect()(2)(1) === "tbl2")
Review Comment:
```suggestion
assert(result.collect()(2)(1) === table2)
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
Review Comment:
```suggestion
|Table: $table
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result2 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'$table'")
+ assert(result2.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result2.collect()(0).length == 4)
+ assert(result2.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result3 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'tb*'")
+ assert(result3.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result3.collect()(0).length == 4)
+ assert(result3.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
Review Comment:
```suggestion
s"""Namespace: $namespace
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ShowTablesSuite.scala:
##########
@@ -49,57 +50,286 @@ class ShowTablesSuite extends command.ShowTablesSuiteBase
with CommandSuiteBase
}
}
- // The test fails for V1 catalog with the error:
- // org.apache.spark.sql.AnalysisException:
- // The namespace in session catalog must have exactly one name part:
spark_catalog.ns1.ns2.tbl
- 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"SHOW TABLE EXTENDED is not supported for v2
tables"))
+ test("show table in a not existing namespace") {
+ val e = intercept[NoSuchNamespaceException] {
+ runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
}
+ checkError(e,
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
+
+ test("show table extended in a not existing namespace") {
+ checkError(
+ exception = intercept[NoSuchNamespaceException] {
+ sql(s"SHOW TABLE EXTENDED FROM $catalog.unknown LIKE '*tbl*'")
+ },
+ errorClass = "SCHEMA_NOT_FOUND",
+ parameters = Map("schemaName" -> "`unknown`"))
+ }
- val namespace = s"$catalog.ns1.ns2"
+ test("show table extended in a not existing table") {
+ val table = "nonexist"
+ withTable(s"$catalog.$table") {
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect().isEmpty)
+ }
+ }
+
+ test("show table extended in non-partitioned table") {
+ val namespace = "ns1.ns2"
val table = "tbl"
- withTable(s"$namespace.$table") {
- sql(s"CREATE TABLE $namespace.$table (id bigint, data string) " +
- s"$defaultUsing 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)
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing")
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 1)")
+ },
+ errorClass = "_LEGACY_ERROR_TEMP_1231",
+ parameters = Map("key" -> "id", "tblName" ->
s"$catalog.$namespace.$table")
+ )
}
}
- // TODO(SPARK-33393): Support SHOW TABLE EXTENDED in DSv2
- test("SHOW TABLE EXTENDED: an existing table") {
- val table = "people"
- withTable(s"$catalog.$table") {
- sql(s"CREATE TABLE $catalog.$table (name STRING, id INT) $defaultUsing")
+ test("show table extended in multi-partition table") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id1 bigint, id2 bigint, data string) " +
+ s"$defaultUsing PARTITIONED BY (id1, id2)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id1 = 1, id2 = 2)")
+
+ val result = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace " +
+ s"LIKE '$table' PARTITION(id1 = 1, id2 = 2)")
+ assert(result.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result.collect()(0).length == 4)
+ assert(result.collect()(0)(0) === namespace)
+ assert(result.collect()(0)(1) === s"$catalog.$namespace.$table")
+ assert(result.collect()(0)(2) === false)
+ assert(result.collect()(0)(3) ===
+ """Partition Values: [id1=1, id2=2]
+ |
+ |""".stripMargin)
+
checkError(
exception = intercept[AnalysisException] {
- sql(s"SHOW TABLE EXTENDED FROM $catalog LIKE '*$table*'").collect()
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id1 = 1)")
},
- errorClass = "_LEGACY_ERROR_TEMP_1200",
- parameters = Map("name" -> "SHOW TABLE EXTENDED")
+ errorClass = "_LEGACY_ERROR_TEMP_1232",
+ parameters = Map(
+ "specKeys" -> "id1",
+ "partitionColumnNames" -> "id1, id2",
+ "tableName" -> s"$catalog.$namespace.$table")
)
}
}
- test("show table in a not existing namespace") {
- val e = intercept[NoSuchNamespaceException] {
- runShowTablesSql(s"SHOW TABLES IN $catalog.unknown", Seq())
+ test("show table extended in a not existing partition") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+ checkError(
+ exception = intercept[NoSuchPartitionException] {
+ sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE '$table'
PARTITION(id = 2)")
+ },
+ errorClass = "PARTITIONS_NOT_FOUND",
+ parameters = Map(
+ "partitionList" -> "PARTITION (`id` = 2)",
+ "tableName" -> "`ns1`.`ns2`.`tbl`"
+ )
+ )
+ }
+ }
+
+ test("show table extended for v2 tables") {
+ val namespace = "ns1.ns2"
+ val table = "tbl"
+ withNamespaceAndTable(namespace, table, catalog) { tbl =>
+ sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing
PARTITIONED BY (id)")
+ sql(s"ALTER TABLE $tbl ADD PARTITION (id = 1)")
+
+ val result1 = sql(s"SHOW TABLE EXTENDED FROM $catalog.$namespace LIKE
'$table'")
+ assert(result1.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result1.collect()(0).length == 4)
+ assert(result1.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
+ |Type: MANAGED
+ |Provider: _
+ |Owner: ${Utils.getCurrentUserName()}
+ |Partition Provider: Catalog
+ |Partition Columns: `id`
+ |Schema: root
+ | |-- id: long (nullable = true)
+ | |-- data: string (nullable = true)
+ |
+ |""".stripMargin)
+
+ val result2 = sql(s"SHOW TABLE EXTENDED IN $catalog.$namespace LIKE
'$table'")
+ assert(result2.schema.fieldNames ===
+ Seq("namespace", "tableName", "isTemporary", "information"))
+ assert(result2.collect()(0).length == 4)
+ assert(result2.collect()(0)(3) ==
+ s"""Namespace: ns1.ns2
+ |Table: tbl
Review Comment:
```suggestion
|Table: $table
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]