[ https://issues.apache.org/jira/browse/HIVE-25256?focusedWorklogId=622502&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-622502 ]
ASF GitHub Bot logged work on HIVE-25256: ----------------------------------------- Author: ASF GitHub Bot Created on: 14/Jul/21 13:28 Start Date: 14/Jul/21 13:28 Worklog Time Spent: 10m Work Description: marton-bod commented on a change in pull request #2463: URL: https://github.com/apache/hive/pull/2463#discussion_r669615214 ########## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java ########## @@ -505,19 +512,82 @@ private void handleReplaceColumns(org.apache.hadoop.hive.metastore.api.Table hms } for (FieldSchema updatedCol : schemaDifference.getTypeChanged()) { - Type newType = HiveSchemaUtil.convert(TypeInfoUtils.getTypeInfoFromTypeString(updatedCol.getType())); - if (!(newType instanceof Type.PrimitiveType)) { - throw new MetaException(String.format("Cannot promote type of column: '%s' to a non-primitive type: %s.", - updatedCol.getName(), newType)); - } - updateSchema.updateColumn(updatedCol.getName(), (Type.PrimitiveType) newType, updatedCol.getComment()); + updateSchema.updateColumn(updatedCol.getName(), getPrimitiveTypeOrThrow(updatedCol), updatedCol.getComment()); } for (FieldSchema updatedCol : schemaDifference.getCommentChanged()) { updateSchema.updateColumnDoc(updatedCol.getName(), updatedCol.getComment()); } } + private void handleChangeColumn(org.apache.hadoop.hive.metastore.api.Table hmsTable) throws MetaException { + List<FieldSchema> hmsCols = hmsTable.getSd().getCols(); + List<FieldSchema> icebergCols = HiveSchemaUtil.convert(icebergTable.schema()); + // compute schema difference for renames, type/comment changes + HiveSchemaUtil.SchemaDifference schemaDifference = HiveSchemaUtil.getSchemaDiff(hmsCols, icebergCols, true); + // check column reorder (which could happen even in the absence of any rename, type or comment change) + Map<String, String> renameMapping = ImmutableMap.of(); + if (!schemaDifference.getMissingFromSecond().isEmpty()) { + renameMapping = ImmutableMap.of( + schemaDifference.getMissingFromSecond().get(0).getName(), + schemaDifference.getMissingFromFirst().get(0).getName()); + } + Pair<String, Optional<String>> outOfOrder = HiveSchemaUtil.getFirstOutOfOrderColumn(hmsCols, icebergCols, + renameMapping); + + if (!schemaDifference.isEmpty() || outOfOrder != null) { + updateSchema = icebergTable.updateSchema(); + } else { + // we should get here if the user restated the exactly the existing column in the CHANGE COLUMN command Review comment: Updated the comment, let me know if this clarifies it. -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 622502) Time Spent: 1.5h (was: 1h 20m) > Support ALTER TABLE CHANGE COLUMN for Iceberg > --------------------------------------------- > > Key: HIVE-25256 > URL: https://issues.apache.org/jira/browse/HIVE-25256 > Project: Hive > Issue Type: New Feature > Reporter: Marton Bod > Assignee: Marton Bod > Priority: Major > Labels: pull-request-available > Time Spent: 1.5h > Remaining Estimate: 0h > > In order to provide support for renaming/changing the data type of a single > column, we should add alter table change column support for Iceberg tables. -- This message was sent by Atlassian Jira (v8.3.4#803005)