deniskuzZ commented on code in PR #5715:
URL: https://github.com/apache/hive/pull/5715#discussion_r2048816686
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java:
##########
@@ -927,6 +931,52 @@ private void
handleAddColumns(org.apache.hadoop.hive.metastore.api.Table hmsTabl
updateSchema.commit();
}
+ private void handleDropColumn(org.apache.hadoop.hive.metastore.api.Table
hmsTable) throws MetaException {
+ List<FieldSchema> hmsCols = hmsTable.getSd().getCols();
+ List<FieldSchema> icebergCols =
HiveSchemaUtil.convert(icebergTable.schema());
+
+ HiveSchemaUtil.SchemaDifference schemaDifference =
HiveSchemaUtil.getSchemaDiff(hmsCols, icebergCols, true);
+
+ if (schemaDifference.getMissingFromFirst().size() > 1) {
+ throw new MetaException("Cannot drop more than one column");
+ }
+
+ if (!schemaDifference.getMissingFromFirst().isEmpty()) {
+ schemaDifference.getMissingFromFirst().forEach(icebergCols::remove);
+ }
+
+ Pair<String, Optional<String>> outOfOrder =
HiveSchemaUtil.getReorderedColumn(
+ hmsCols, icebergCols, ImmutableMap.of());
+
+ if (!schemaDifference.getMissingFromSecond().isEmpty()) {
+ throw new MetaException("Unsupported operation to use DROP COLUMN for
adding a column");
+ }
+
+ if (!schemaDifference.getTypeChanged().isEmpty()) {
+ throw new MetaException("Unsupported operation to use DROP COLUMN for
changing a column type");
+ }
+
+ if (!schemaDifference.getCommentChanged().isEmpty()) {
+ throw new MetaException("Unsupported operation to use DROP COLUMN for
changing a column comment");
+ }
+
+ if (outOfOrder != null) {
Review Comment:
i would expect a much simple logic, similar to handleAddColumns
````
Collection<FieldSchema> removedCols =
HiveSchemaUtil.getSchemaDiff(HiveSchemaUtil.convert(icebergTable.schema()),
hmsTable.getSd().getCols(), false)
.getMissingFromSecond();
if (removedCols.isEmpty()) {
return;
}
transaction = icebergTable.newTransaction();
transaction.updateSchema()
.deleteColumn(removedCol.get(0).getName());
.commit();
}
````
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java:
##########
@@ -927,6 +931,52 @@ private void
handleAddColumns(org.apache.hadoop.hive.metastore.api.Table hmsTabl
updateSchema.commit();
}
+ private void handleDropColumn(org.apache.hadoop.hive.metastore.api.Table
hmsTable) throws MetaException {
+ List<FieldSchema> hmsCols = hmsTable.getSd().getCols();
+ List<FieldSchema> icebergCols =
HiveSchemaUtil.convert(icebergTable.schema());
+
+ HiveSchemaUtil.SchemaDifference schemaDifference =
HiveSchemaUtil.getSchemaDiff(hmsCols, icebergCols, true);
+
+ if (schemaDifference.getMissingFromFirst().size() > 1) {
+ throw new MetaException("Cannot drop more than one column");
+ }
+
+ if (!schemaDifference.getMissingFromFirst().isEmpty()) {
+ schemaDifference.getMissingFromFirst().forEach(icebergCols::remove);
+ }
+
+ Pair<String, Optional<String>> outOfOrder =
HiveSchemaUtil.getReorderedColumn(
+ hmsCols, icebergCols, ImmutableMap.of());
+
+ if (!schemaDifference.getMissingFromSecond().isEmpty()) {
+ throw new MetaException("Unsupported operation to use DROP COLUMN for
adding a column");
+ }
+
+ if (!schemaDifference.getTypeChanged().isEmpty()) {
+ throw new MetaException("Unsupported operation to use DROP COLUMN for
changing a column type");
+ }
+
+ if (!schemaDifference.getCommentChanged().isEmpty()) {
+ throw new MetaException("Unsupported operation to use DROP COLUMN for
changing a column comment");
+ }
+
+ if (outOfOrder != null) {
Review Comment:
@ramitg254, why couldn't you reuse the code snippet shared above?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]