beliefer commented on code in PR #42524:
URL: https://github.com/apache/spark/pull/42524#discussion_r1361853134
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala:
##########
@@ -377,7 +377,10 @@ case class AlterTableChangeColumnCommand(
val resolver = sparkSession.sessionState.conf.resolver
DDLUtils.verifyAlterTableType(catalog, table, isView = false)
- // Find the origin column from dataSchema by column name.
+ // Check that the column is not a partition column
+ if (table.partitionSchema.fieldNames.exists(resolver(columnName, _))) {
+ throw
QueryCompilationErrors.cannotAlterPartitionColumn(table.qualifiedName,
columnName)
+ }
val originColumn = findColumnByName(table.dataSchema, columnName, resolver)
Review Comment:
It seems we should keep the origin comment here.
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala:
##########
@@ -2405,6 +2405,21 @@ abstract class DDLSuite extends QueryTest with
DDLSuiteBase {
"operation" -> "generated columns")
)
}
+
+ test("SPARK-44837: Error when altering partition column in non-delta table")
{
+ withTable("t") {
+ sql("CREATE TABLE t(i INT, j INT, k INT) USING parquet PARTITIONED BY
(i, j)")
+ val e = intercept[AnalysisException] {
+ sql("ALTER TABLE t ALTER COLUMN i COMMENT 'comment'")
+ }
+ checkError(
+ exception = e,
+ errorClass = "CANNOT_ALTER_PARTITION_COLUMN",
+ sqlState = "428FR",
+ parameters = Map("tableName" -> "`spark_catalog`.`default`.`t`",
+ "columnName" -> "`i`"))
Review Comment:
```suggestion
checkError(
exception = intercept[AnalysisException] {
sql("ALTER TABLE t ALTER COLUMN i COMMENT 'comment'")
},
errorClass = "CANNOT_ALTER_PARTITION_COLUMN",
sqlState = "428FR",
parameters = Map("tableName" -> "`spark_catalog`.`default`.`t`",
"columnName" -> "`i`"))
```
--
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]