-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-17612][SQL] Support DESCRIBE table PARTITION SQL syntax
#15168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
1deffcd
3007701
2420577
f419c4c
7371e48
9b445c2
9e81400
89d4424
e3d2faf
ec574ff
2ed1069
fc132e6
04c75e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| CREATE TABLE t (a STRING, b INT) PARTITIONED BY (c STRING, d STRING); | ||
|
|
||
| ALTER TABLE t ADD PARTITION (c='Us', d=1); | ||
|
|
||
| DESC t; | ||
|
|
||
| -- Ignore these because there exist timestamp results, e.g., `Create Table`. | ||
| -- DESC EXTENDED t; | ||
| -- DESC FORMATTED t; | ||
|
|
||
| DESC t PARTITION (c='Us', d=1); | ||
|
|
||
| -- Ignore these because there exist timestamp results, e.g., transient_lastDdlTime. | ||
| -- DESC EXTENDED t PARTITION (c='Us', d=1); | ||
| -- DESC FORMATTED t PARTITION (c='Us', d=1); | ||
|
|
||
| -- NoSuchPartitionException: Partition not found in table | ||
| DESC t PARTITION (c='Us', d=2); | ||
|
|
||
| -- AnalysisException: Partition spec is invalid | ||
| DESC t PARTITION (c='Us'); | ||
|
|
||
| -- ParseException: PARTITION specification is incomplete | ||
| DESC t PARTITION (c='Us', d); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- Number of queries: 7 | ||
|
|
||
|
|
||
| -- !query 0 | ||
| CREATE TABLE t (a STRING, b INT) PARTITIONED BY (c STRING, d STRING) | ||
| -- !query 0 schema | ||
| struct<> | ||
| -- !query 0 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 1 | ||
| ALTER TABLE t ADD PARTITION (c='Us', d=1) | ||
| -- !query 1 schema | ||
| struct<> | ||
| -- !query 1 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 2 | ||
| DESC t | ||
| -- !query 2 schema | ||
| struct<col_name:string,data_type:string,comment:string> | ||
| -- !query 2 output | ||
| # Partition Information | ||
| # col_name data_type comment | ||
| a string | ||
| b int | ||
| c string | ||
| c string | ||
| d string | ||
| d string | ||
|
|
||
|
|
||
| -- !query 3 | ||
| DESC t PARTITION (c='Us', d=1) | ||
| -- !query 3 schema | ||
| struct<col_name:string,data_type:string,comment:string> | ||
| -- !query 3 output | ||
| # Partition Information | ||
| # col_name data_type comment | ||
| a string | ||
| b int | ||
| c string | ||
| c string | ||
| d string | ||
| d string | ||
|
|
||
|
|
||
| -- !query 4 | ||
| DESC t PARTITION (c='Us', d=2) | ||
| -- !query 4 schema | ||
| struct<> | ||
| -- !query 4 output | ||
| org.apache.spark.sql.catalyst.analysis.NoSuchPartitionException | ||
| Partition not found in table 't' database 'default': | ||
| c -> Us | ||
| d -> 2; | ||
|
|
||
|
|
||
| -- !query 5 | ||
| DESC t PARTITION (c='Us') | ||
| -- !query 5 schema | ||
| struct<> | ||
| -- !query 5 output | ||
| org.apache.spark.sql.AnalysisException | ||
| Partition spec is invalid. The spec (c) must match the partition spec (c, d) defined in table '`default`.`t`'; | ||
|
|
||
|
|
||
| -- !query 6 | ||
| DESC t PARTITION (c='Us', d) | ||
| -- !query 6 schema | ||
| struct<> | ||
| -- !query 6 output | ||
| org.apache.spark.sql.catalyst.parser.ParseException | ||
|
|
||
| PARTITION specification is incomplete: `d`(line 1, pos 0) | ||
|
|
||
| == SQL == | ||
| DESC t PARTITION (c='Us', d) | ||
| ^^^ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ import org.apache.hadoop.fs.Path | |
|
|
||
| import org.apache.spark.sql._ | ||
| import org.apache.spark.sql.catalyst.TableIdentifier | ||
| import org.apache.spark.sql.catalyst.analysis.{EliminateSubqueryAliases, FunctionRegistry} | ||
| import org.apache.spark.sql.catalyst.analysis.{EliminateSubqueryAliases, FunctionRegistry, NoSuchPartitionException} | ||
| import org.apache.spark.sql.catalyst.catalog.CatalogTableType | ||
| import org.apache.spark.sql.catalyst.parser.ParseException | ||
| import org.apache.spark.sql.execution.datasources.{HadoopFsRelation, LogicalRelation} | ||
|
|
@@ -341,6 +341,81 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
| } | ||
| } | ||
|
|
||
| test("describe partition") { | ||
|
||
| withTable("partitioned_table") { | ||
| sql("CREATE TABLE partitioned_table (a STRING, b INT) PARTITIONED BY (c STRING, d STRING)") | ||
| sql("ALTER TABLE partitioned_table ADD PARTITION (c='Us', d=1)") | ||
|
|
||
| checkKeywordsExist(sql("DESC partitioned_table PARTITION (c='Us', d=1)"), | ||
| "# Partition Information", | ||
| "# col_name") | ||
|
|
||
| checkKeywordsExist(sql("DESC EXTENDED partitioned_table PARTITION (c='Us', d=1)"), | ||
| "# Partition Information", | ||
| "# col_name", | ||
| "Detailed Partition Information CatalogPartition(", | ||
| "Partition Values: [Us, 1]", | ||
| "Storage(Location:", | ||
| "Partition Parameters") | ||
|
|
||
| checkKeywordsExist(sql("DESC FORMATTED partitioned_table PARTITION (c='Us', d=1)"), | ||
| "# Partition Information", | ||
| "# col_name", | ||
| "# Detailed Partition Information", | ||
| "Partition Value:", | ||
| "Database:", | ||
| "Table:", | ||
| "Location:", | ||
| "Partition Parameters:", | ||
| "# Storage Information") | ||
| } | ||
| } | ||
|
|
||
| test("describe partition - error handling") { | ||
| withTable("partitioned_table", "datasource_table") { | ||
| sql("CREATE TABLE partitioned_table (a STRING, b INT) PARTITIONED BY (c STRING, d STRING)") | ||
| sql("ALTER TABLE partitioned_table ADD PARTITION (c='Us', d=1)") | ||
|
|
||
| val m = intercept[NoSuchPartitionException] { | ||
| sql("DESC partitioned_table PARTITION (c='Us', d=2)") | ||
| }.getMessage() | ||
| assert(m.contains("Partition not found in table")) | ||
|
|
||
| val m2 = intercept[AnalysisException] { | ||
| sql("DESC partitioned_table PARTITION (c='Us')") | ||
| }.getMessage() | ||
| assert(m2.contains("Partition spec is invalid")) | ||
|
|
||
| val m3 = intercept[ParseException] { | ||
| sql("DESC partitioned_table PARTITION (c='Us', d)") | ||
| }.getMessage() | ||
| assert(m3.contains("PARTITION specification is incomplete: `d`")) | ||
|
|
||
| spark | ||
| .range(1).select('id as 'a, 'id as 'b, 'id as 'c, 'id as 'd).write | ||
| .partitionBy("d") | ||
| .saveAsTable("datasource_table") | ||
| val m4 = intercept[AnalysisException] { | ||
| sql("DESC datasource_table PARTITION (d=2)") | ||
| }.getMessage() | ||
| assert(m4.contains("DESC PARTITION is not allowed on a datasource table")) | ||
|
|
||
| val m5 = intercept[AnalysisException] { | ||
| spark.range(10).select('id as 'a, 'id as 'b).createTempView("view1") | ||
| sql("DESC view1 PARTITION (c='Us', d=1)") | ||
| }.getMessage() | ||
| assert(m5.contains("DESC PARTITION is not allowed on a temporary view")) | ||
|
|
||
| withView("permanent_view") { | ||
| val m = intercept[AnalysisException] { | ||
| sql("CREATE VIEW permanent_view AS SELECT * FROM partitioned_table") | ||
| sql("DESC permanent_view PARTITION (c='Us', d=1)") | ||
| }.getMessage() | ||
| assert(m.contains("DESC PARTITION is not allowed on a view")) | ||
| } | ||
| } | ||
| } | ||
|
||
|
|
||
| test("SPARK-5371: union with null and sum") { | ||
| val df = Seq((1, 1)).toDF("c1", "c2") | ||
| df.createOrReplaceTempView("table1") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thank you!