imback82 commented on a change in pull request #31494:
URL: https://github.com/apache/spark/pull/31494#discussion_r572305204
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/connector/AlterTableTests.scala
##########
@@ -1141,6 +1141,36 @@ trait AlterTableTests extends SharedSparkSession {
}
}
+ test("AlterTable: remove nonexistent table property") {
+ val t = s"${catalogAndNamespace}table_name"
+ withTable(t) {
+ sql(s"CREATE TABLE $t (id int) USING $v2Format TBLPROPERTIES('test' =
'34')")
+
+ val tableName = fullTableName(t)
+ val table = getTableMetadata(tableName)
+
+ assert(table.name === tableName)
+ assert(table.properties ===
+ withDefaultOwnership(Map("provider" -> v2Format, "test" ->
"34")).asJava)
+
+ val exc = intercept[AnalysisException] {
+ sql(s"ALTER TABLE $t UNSET TBLPROPERTIES ('unknown')")
+ }
+ assert(exc.getMessage.contains("Attempted to unset non-existent property
'unknown'"))
+
+ // Reserved property "comment" should be allowed regardless.
+ sql(s"ALTER TABLE $t UNSET TBLPROPERTIES ('comment')")
Review comment:
The "comment" property seems to be treated differently that other
reserved properties (not checked in the following):
https://github.com/apache/spark/blob/3b26bc25362a245a610c3e222b971b4ae612bc3e/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala#L2836-L2850
The following works:
```
scala> sql("CREATE TABLE t (id int) TBLPROPERTIES('comment' = 'hello')")
scala> sql("DESCRIBE EXTENDED t").show
+--------------------+--------------------+-------+
| col_name| data_type|comment|
+--------------------+--------------------+-------+
| id| int| null|
| | | |
|# Detailed Table ...| | |
| Database| default| |
| Table| t| |
| Owner| terryk| |
| Created Time|Mon Feb 08 11:08:...| |
| Last Access| UNKNOWN| |
| Created By| Spark 3.0.1| |
| Type| MANAGED| |
| Provider| hive| |
| Comment| hello| |
```
Note the following to see how v1 command can unset the comment using this
command:
https://github.com/apache/spark/blob/3b26bc25362a245a610c3e222b971b4ae612bc3e/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala#L315-L316
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]