Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/19773#discussion_r152480007
--- 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 --
What is the Hive's behavior if users change the column type of partition
schema?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]