suhuruli commented on code in PR #60462:
URL: https://github.com/apache/spark/pull/60462#discussion_r4594139411


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalogSuite.scala:
##########
@@ -379,6 +379,54 @@ class V2SessionCatalogTableSuite extends 
V2SessionCatalogBaseSuite {
     assert(filterV2TableProperties(table.properties) == Map())
   }
 
+  test("SPARK-57670: alterTable keeps the comment and collation when no change 
names them") {
+    val catalog = newCatalog()
+    // A table created by DDL keeps its comment and default collation only in 
the dedicated fields
+    // of the catalog table, not in its properties.
+    spark.sql(s"CREATE TABLE $testIdentQuoted (id INT, data STRING) USING 
parquet " +
+      "COMMENT 'table comment' DEFAULT COLLATION UTF8_LCASE")
+    val created = 
catalog.loadTable(testIdent).asInstanceOf[V1Table].catalogTable
+    assert(created.comment.contains("table comment"))
+    assert(created.collation.contains("UTF8_LCASE"))
+    assert(!created.properties.contains(TableCatalog.PROP_COMMENT))
+    assert(!created.properties.contains(TableCatalog.PROP_COLLATION))
+
+    catalog.alterTable(testIdent, TableChange.setProperty("prop-1", "1"))
+    val afterSet = 
catalog.loadTable(testIdent).asInstanceOf[V1Table].catalogTable
+    assert(afterSet.properties.get("prop-1").contains("1"))
+    assert(afterSet.comment.contains("table comment"))
+    assert(afterSet.collation.contains("UTF8_LCASE"))
+
+    catalog.alterTable(testIdent, TableChange.removeProperty("prop-1"))
+    val afterRemove = 
catalog.loadTable(testIdent).asInstanceOf[V1Table].catalogTable
+    assert(!afterRemove.properties.contains("prop-1"))
+    assert(afterRemove.comment.contains("table comment"))
+    assert(afterRemove.collation.contains("UTF8_LCASE"))
+  }
+
+  test("SPARK-57670: alterTable sets or removes the comment and collation a 
change names") {
+    val catalog = newCatalog()
+    spark.sql(s"CREATE TABLE $testIdentQuoted (id INT, data STRING) USING 
parquet " +
+      "COMMENT 'table comment' DEFAULT COLLATION UTF8_LCASE")
+
+    catalog.alterTable(testIdent, 
TableChange.setProperty(TableCatalog.PROP_COMMENT, "new comment"))
+    val afterComment = 
catalog.loadTable(testIdent).asInstanceOf[V1Table].catalogTable
+    assert(afterComment.comment.contains("new comment"))
+    assert(afterComment.collation.contains("UTF8_LCASE"))
+
+    catalog.alterTable(testIdent, 
TableChange.setProperty(TableCatalog.PROP_COLLATION, "UNICODE"))
+    val afterCollation = 
catalog.loadTable(testIdent).asInstanceOf[V1Table].catalogTable
+    assert(afterCollation.comment.contains("new comment"))
+    assert(afterCollation.collation.contains("UNICODE"))
+
+    catalog.alterTable(testIdent,

Review Comment:
   Added two tests to `V2SessionCatalogTableSuite`: "SPARK-57670: alterTable 
that removes only the comment keeps the collation" sends only 
`RemoveProperty(comment)`, the change `COMMENT ON TABLE ... IS NULL` issues, to 
a table with a comment and a default collation and checks that the comment is 
gone and the collation remains; "SPARK-57670: alterTable that removes only the 
collation keeps the comment" does the reverse. Both pass on the current code. 
To check that they pin the per-field rule, I temporarily made the collation 
branch of `V2SessionCatalog.alterTable` test the comment key: both tests 
failed, and they pass again with the branch restored. Only the tests are 
committed.



-- 
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]

Reply via email to