[ https://issues.apache.org/jira/browse/HIVE-25255?focusedWorklogId=613973&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-613973 ]
ASF GitHub Bot logged work on HIVE-25255: ----------------------------------------- Author: ASF GitHub Bot Created on: 23/Jun/21 11:33 Start Date: 23/Jun/21 11:33 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #2418: URL: https://github.com/apache/hive/pull/2418#discussion_r657007337 ########## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java ########## @@ -262,17 +264,52 @@ public void preAlterTable(org.apache.hadoop.hive.metastore.api.Table hmsTable, E if (AlterTableType.ADDCOLS.equals(currentAlterTableOp)) { Collection<FieldSchema> addedCols = - HiveSchemaUtil.schemaDifference(hmsTable.getSd().getCols(), HiveSchemaUtil.convert(icebergTable.schema())); + HiveSchemaUtil.newColumns(hmsTable.getSd().getCols(), HiveSchemaUtil.convert(icebergTable.schema())); + if (!addedCols.isEmpty()) { + updateSchema = icebergTable.updateSchema(); + } + for (FieldSchema addedCol : addedCols) { + updateSchema.addColumn( + addedCol.getName(), + HiveSchemaUtil.convert(TypeInfoUtils.getTypeInfoFromTypeString(addedCol.getType())), + addedCol.getComment() + ); + } + } else if (AlterTableType.REPLACE_COLUMNS.equals(currentAlterTableOp)) { + List<FieldSchema> icebergSchema = HiveSchemaUtil.convert(icebergTable.schema()); + List<FieldSchema> hmsSchema = hmsTable.getSd().getCols(); + Collection<FieldSchema> droppedCols = HiveSchemaUtil.newColumns(icebergSchema, hmsSchema); + Collection<FieldSchema> addedCols = HiveSchemaUtil.newColumns(hmsSchema, icebergSchema); + Collection<FieldSchema> typeUpdated = HiveSchemaUtil.updatedTypeColumns(hmsSchema, icebergSchema); + Collection<FieldSchema> commentUpdated = HiveSchemaUtil.updatedCommentColumns(hmsSchema, icebergSchema); + if (!droppedCols.isEmpty() || !addedCols.isEmpty() || !typeUpdated.isEmpty() || !commentUpdated.isEmpty()) { + updateSchema = icebergTable.updateSchema(); + } + + for (FieldSchema droppedCol : droppedCols) { + updateSchema.deleteColumn(droppedCol.getName()); + } + for (FieldSchema addedCol : addedCols) { - if (updateSchema == null) { - updateSchema = icebergTable.updateSchema(); - } updateSchema.addColumn( addedCol.getName(), HiveSchemaUtil.convert(TypeInfoUtils.getTypeInfoFromTypeString(addedCol.getType())), addedCol.getComment() ); } + + for (FieldSchema updatedCol : typeUpdated) { + Type newType = HiveSchemaUtil.convert(TypeInfoUtils.getTypeInfoFromTypeString(updatedCol.getType())); + if (!(newType instanceof Type.PrimitiveType)) { Review comment: What happens when we try to convert primitive types that are not compatible? -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 613973) Time Spent: 1h (was: 50m) > Support ALTER TABLE REPLACE COLUMNS for Iceberg > ----------------------------------------------- > > Key: HIVE-25255 > URL: https://issues.apache.org/jira/browse/HIVE-25255 > Project: Hive > Issue Type: New Feature > Reporter: Marton Bod > Assignee: Marton Bod > Priority: Major > Labels: pull-request-available > Time Spent: 1h > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.4#803005)