Skip to content

Commit 92b2f31

Browse files
committed
support change column comment for external hive table
1 parent b14993e commit 92b2f31

File tree

2 files changed

+5
-5
lines changed
  • sql/core/src
    • main/scala/org/apache/spark/sql/execution/command
    • test/scala/org/apache/spark/sql/execution/command

2 files changed

+5
-5
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ case class AlterTableChangeColumnCommand(
314314
val resolver = sparkSession.sessionState.conf.resolver
315315
DDLUtils.verifyAlterTableType(catalog, table, isView = false)
316316

317-
// Find the origin column from schema by column name.
318-
val originColumn = findColumnByName(table.schema, columnName, resolver)
317+
// Find the origin column from dataSchema by column name.
318+
val originColumn = findColumnByName(table.dataSchema, columnName, resolver)
319319
// Throw an AnalysisException if the column name/dataType is changed.
320320
if (!columnEqual(originColumn, newColumn, resolver)) {
321321
throw new AnalysisException(
@@ -324,16 +324,15 @@ case class AlterTableChangeColumnCommand(
324324
s"'${newColumn.name}' with type '${newColumn.dataType}'")
325325
}
326326

327-
val newSchema = table.schema.fields.map { field =>
327+
val newDataSchema = table.dataSchema.fields.map { field =>
328328
if (field.name == originColumn.name) {
329329
// Create a new column from the origin column with the new comment.
330330
addComment(field, newColumn.getComment)
331331
} else {
332332
field
333333
}
334334
}
335-
val newTable = table.copy(schema = StructType(newSchema))
336-
catalog.alterTable(newTable)
335+
catalog.alterTableDataSchema(tableName, StructType(newDataSchema))
337336

338337
Seq.empty[Row]
339338
}

sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,7 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
15971597
// Ensure that change column will preserve other metadata fields.
15981598
sql("ALTER TABLE dbx.tab1 CHANGE COLUMN col1 col1 INT COMMENT 'this is col1'")
15991599
assert(getMetadata("col1").getString("key") == "value")
1600+
assert(getMetadata("col1").getString("comment") == "this is col1")
16001601
}
16011602

16021603
test("drop build-in function") {

0 commit comments

Comments
 (0)