Github user xuanyuanking commented on a diff in the pull request: https://github.com/apache/spark/pull/19773#discussion_r152753785 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala --- @@ -318,16 +318,26 @@ case class AlterTableChangeColumnCommand( s"'${newColumn.name}' with type '${newColumn.dataType}'") } - val newSchema = table.schema.fields.map { field => + val typeChanged = originColumn.dataType != newColumn.dataType + val newDataSchema = table.dataSchema.fields.map { field => if (field.name == originColumn.name) { - // Create a new column from the origin column with the new comment. - addComment(field, newColumn.getComment) + // Add the comment to a column, if comment is empty, return the original column. + val newField = newColumn.getComment.map(field.withComment(_)).getOrElse(field) + if (typeChanged) { + newField.copy(dataType = newColumn.dataType) + } else { + newField + } } else { field } } - val newTable = table.copy(schema = StructType(newSchema)) - catalog.alterTable(newTable) + val newTable = table.copy(schema = StructType(newDataSchema ++ table.partitionSchema)) + if (typeChanged) { + catalog.alterTableDataSchema(tableName, StructType(newDataSchema)) --- End diff -- [HIVE-3672](https://issues.apache.org/jira/browse/HIVE-3672) Hive support this by adding new command of `ALTER TABLE <table_name> PARTITION COLUMN (<column_name> <new type>)`. So here maybe I should throw an AnalysisException while user change the type of partition column?
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org