From dd7e1fa63834bdac1a1252c671f2a81e598ae518 Mon Sep 17 00:00:00 2001 From: Wenchen Fan Date: Fri, 16 Jun 2017 14:38:59 +0800 Subject: [PATCH] unset table properties should keep the table comment --- .../spark/sql/execution/command/ddl.scala | 4 +- .../resources/sql-tests/inputs/describe.sql | 8 + .../sql-tests/results/describe.sql.out | 201 ++++++++++++------ 3 files changed, 148 insertions(+), 65 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala index f924b3d914635..413f5f3ba539c 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala @@ -264,14 +264,14 @@ case class AlterTableUnsetPropertiesCommand( DDLUtils.verifyAlterTableType(catalog, table, isView) if (!ifExists) { propKeys.foreach { k => - if (!table.properties.contains(k)) { + if (!table.properties.contains(k) && k != "comment") { throw new AnalysisException( s"Attempted to unset non-existent property '$k' in table '${table.identifier}'") } } } // If comment is in the table property, we reset it to None - val tableComment = if (propKeys.contains("comment")) None else table.properties.get("comment") + val tableComment = if (propKeys.contains("comment")) None else table.comment val newProperties = table.properties.filter { case (k, _) => !propKeys.contains(k) } val newTable = table.copy(properties = newProperties, comment = tableComment) catalog.alterTable(newTable) diff --git a/sql/core/src/test/resources/sql-tests/inputs/describe.sql b/sql/core/src/test/resources/sql-tests/inputs/describe.sql index 91b966829f8fb..a222e11916cda 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/describe.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/describe.sql @@ -28,6 +28,14 @@ DESC FORMATTED t; DESC EXTENDED t; +ALTER TABLE t UNSET TBLPROPERTIES (e); + +DESC EXTENDED t; + +ALTER TABLE t UNSET TBLPROPERTIES (comment); + +DESC EXTENDED t; + DESC t PARTITION (c='Us', d=1); DESC EXTENDED t PARTITION (c='Us', d=1); diff --git a/sql/core/src/test/resources/sql-tests/results/describe.sql.out b/sql/core/src/test/resources/sql-tests/results/describe.sql.out index ab9f2783f06bb..e2b79e8f7801d 100644 --- a/sql/core/src/test/resources/sql-tests/results/describe.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/describe.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 32 +-- Number of queries: 36 -- !query 0 @@ -166,10 +166,85 @@ Partition Provider Catalog -- !query 11 -DESC t PARTITION (c='Us', d=1) +ALTER TABLE t UNSET TBLPROPERTIES (e) -- !query 11 schema -struct +struct<> -- !query 11 output + + + +-- !query 12 +DESC EXTENDED t +-- !query 12 schema +struct +-- !query 12 output +a string +b int +c string +d string +# Partition Information +# col_name data_type comment +c string +d string + +# Detailed Table Information +Database default +Table t +Created [not included in comparison] +Last Access [not included in comparison] +Type MANAGED +Provider parquet +Num Buckets 2 +Bucket Columns [`a`] +Sort Columns [`b`] +Comment table_comment +Location [not included in comparison]sql/core/spark-warehouse/t +Storage Properties [a=1, b=2] +Partition Provider Catalog + + +-- !query 13 +ALTER TABLE t UNSET TBLPROPERTIES (comment) +-- !query 13 schema +struct<> +-- !query 13 output + + + +-- !query 14 +DESC EXTENDED t +-- !query 14 schema +struct +-- !query 14 output +a string +b int +c string +d string +# Partition Information +# col_name data_type comment +c string +d string + +# Detailed Table Information +Database default +Table t +Created [not included in comparison] +Last Access [not included in comparison] +Type MANAGED +Provider parquet +Num Buckets 2 +Bucket Columns [`a`] +Sort Columns [`b`] +Location [not included in comparison]sql/core/spark-warehouse/t +Storage Properties [a=1, b=2] +Partition Provider Catalog + + +-- !query 15 +DESC t PARTITION (c='Us', d=1) +-- !query 15 schema +struct +-- !query 15 output a string b int c string @@ -180,11 +255,11 @@ c string d string --- !query 12 +-- !query 16 DESC EXTENDED t PARTITION (c='Us', d=1) --- !query 12 schema +-- !query 16 schema struct --- !query 12 output +-- !query 16 output a string b int c string @@ -209,11 +284,11 @@ Location [not included in comparison]sql/core/spark-warehouse/t Storage Properties [a=1, b=2] --- !query 13 +-- !query 17 DESC FORMATTED t PARTITION (c='Us', d=1) --- !query 13 schema +-- !query 17 schema struct --- !query 13 output +-- !query 17 output a string b int c string @@ -238,31 +313,31 @@ Location [not included in comparison]sql/core/spark-warehouse/t Storage Properties [a=1, b=2] --- !query 14 +-- !query 18 DESC t PARTITION (c='Us', d=2) --- !query 14 schema +-- !query 18 schema struct<> --- !query 14 output +-- !query 18 output org.apache.spark.sql.catalyst.analysis.NoSuchPartitionException Partition not found in table 't' database 'default': c -> Us d -> 2; --- !query 15 +-- !query 19 DESC t PARTITION (c='Us') --- !query 15 schema +-- !query 19 schema struct<> --- !query 15 output +-- !query 19 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 16 +-- !query 20 DESC t PARTITION (c='Us', d) --- !query 16 schema +-- !query 20 schema struct<> --- !query 16 output +-- !query 20 output org.apache.spark.sql.catalyst.parser.ParseException PARTITION specification is incomplete: `d`(line 1, pos 0) @@ -272,55 +347,55 @@ DESC t PARTITION (c='Us', d) ^^^ --- !query 17 +-- !query 21 DESC temp_v --- !query 17 schema +-- !query 21 schema struct --- !query 17 output +-- !query 21 output a string b int c string d string --- !query 18 +-- !query 22 DESC TABLE temp_v --- !query 18 schema +-- !query 22 schema struct --- !query 18 output +-- !query 22 output a string b int c string d string --- !query 19 +-- !query 23 DESC FORMATTED temp_v --- !query 19 schema +-- !query 23 schema struct --- !query 19 output +-- !query 23 output a string b int c string d string --- !query 20 +-- !query 24 DESC EXTENDED temp_v --- !query 20 schema +-- !query 24 schema struct --- !query 20 output +-- !query 24 output a string b int c string d string --- !query 21 +-- !query 25 DESC temp_Data_Source_View --- !query 21 schema +-- !query 25 schema struct --- !query 21 output +-- !query 25 output intType int test comment test1 stringType string dateType date @@ -339,42 +414,42 @@ arrayType array structType struct --- !query 22 +-- !query 26 DESC temp_v PARTITION (c='Us', d=1) --- !query 22 schema +-- !query 26 schema struct<> --- !query 22 output +-- !query 26 output org.apache.spark.sql.AnalysisException DESC PARTITION is not allowed on a temporary view: temp_v; --- !query 23 +-- !query 27 DESC v --- !query 23 schema +-- !query 27 schema struct --- !query 23 output +-- !query 27 output a string b int c string d string --- !query 24 +-- !query 28 DESC TABLE v --- !query 24 schema +-- !query 28 schema struct --- !query 24 output +-- !query 28 output a string b int c string d string --- !query 25 +-- !query 29 DESC FORMATTED v --- !query 25 schema +-- !query 29 schema struct --- !query 25 output +-- !query 29 output a string b int c string @@ -392,11 +467,11 @@ View Query Output Columns [a, b, c, d] Table Properties [view.query.out.col.3=d, view.query.out.col.0=a, view.query.out.numCols=4, view.default.database=default, view.query.out.col.1=b, view.query.out.col.2=c] --- !query 26 +-- !query 30 DESC EXTENDED v --- !query 26 schema +-- !query 30 schema struct --- !query 26 output +-- !query 30 output a string b int c string @@ -414,42 +489,42 @@ View Query Output Columns [a, b, c, d] Table Properties [view.query.out.col.3=d, view.query.out.col.0=a, view.query.out.numCols=4, view.default.database=default, view.query.out.col.1=b, view.query.out.col.2=c] --- !query 27 +-- !query 31 DESC v PARTITION (c='Us', d=1) --- !query 27 schema +-- !query 31 schema struct<> --- !query 27 output +-- !query 31 output org.apache.spark.sql.AnalysisException DESC PARTITION is not allowed on a view: v; --- !query 28 +-- !query 32 DROP TABLE t --- !query 28 schema +-- !query 32 schema struct<> --- !query 28 output +-- !query 32 output --- !query 29 +-- !query 33 DROP VIEW temp_v --- !query 29 schema +-- !query 33 schema struct<> --- !query 29 output +-- !query 33 output --- !query 30 +-- !query 34 DROP VIEW temp_Data_Source_View --- !query 30 schema +-- !query 34 schema struct<> --- !query 30 output +-- !query 34 output --- !query 31 +-- !query 35 DROP VIEW v --- !query 31 schema +-- !query 35 schema struct<> --- !query 31 output +-- !query 35 output