hive-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (Jira)" <j...@apache.org>
Subject [jira] [Work logged] (HIVE-25255) Support ALTER TABLE REPLACE COLUMNS for Iceberg
Date Tue, 06 Jul 2021 11:09:00 GMT

     [ https://issues.apache.org/jira/browse/HIVE-25255?focusedWorklogId=619055&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-619055
]

ASF GitHub Bot logged work on HIVE-25255:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 06/Jul/21 11:08
            Start Date: 06/Jul/21 11:08
    Worklog Time Spent: 10m 
      Work Description: marton-bod commented on a change in pull request #2418:
URL: https://github.com/apache/hive/pull/2418#discussion_r663975175



##########
File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java
##########
@@ -474,6 +480,43 @@ private static PartitionSpec spec(Configuration configuration, Schema
schema, Pr
     }
   }
 
+  private void handleReplaceColumns(org.apache.hadoop.hive.metastore.api.Table hmsTable)
throws MetaException {
+    HiveSchemaUtil.SchemaDifference schemaDifference = HiveSchemaUtil.getSchemaDiff(hmsTable.getSd().getCols(),
+        HiveSchemaUtil.convert(icebergTable.schema()), true);
+    if (!schemaDifference.isEmpty()) {
+      updateSchema = icebergTable.updateSchema();
+    } else {
+      // we should get here if the user restated the exactly the existing columns in the
REPLACE COLUMNS command
+      LOG.info("Found no difference between new and old schema for ALTER TABLE REPLACE COLUMNS
for" +
+          " table: {}. There will be no Iceberg commit.", hmsTable.getTableName());

Review comment:
       Done

##########
File path: iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/HiveSchemaUtil.java
##########
@@ -138,22 +137,88 @@ public static Type convert(TypeInfo typeInfo) {
   }
 
   /**
-   * Produces the difference of two FieldSchema lists by only taking into account the field
name and type.
+   * Returns a SchemaDifference containing those fields which are present in only one of
the collections, as well as
+   * those fields which are present in both (in terms of the name) but their type or comment
has changed.
    * @param minuendCollection Collection of fields to subtract from
    * @param subtrahendCollection Collection of fields to subtract
-   * @return the result list of difference
+   * @param bothDirections Whether or not to compute the missing fields from the minuendCollection
as well
+   * @return the difference between the two schemas
    */
-  public static Collection<FieldSchema> schemaDifference(
-      Collection<FieldSchema> minuendCollection, Collection<FieldSchema> subtrahendCollection)
{
+  public static SchemaDifference getSchemaDiff(Collection<FieldSchema> minuendCollection,
+                                               Collection<FieldSchema> subtrahendCollection,
boolean bothDirections) {
+    SchemaDifference difference = new SchemaDifference();
 
-    Function<FieldSchema, FieldSchema> unsetCommentFunc = fs -> new FieldSchema(fs.getName(),
fs.getType(), null);
-    Set<FieldSchema> subtrahendWithoutComment =
-        subtrahendCollection.stream().map(unsetCommentFunc).collect(Collectors.toSet());
+    for (FieldSchema first : minuendCollection) {
+      boolean found = false;
+      for (FieldSchema second : subtrahendCollection) {
+        if (first.getName().equals(second.getName())) {
+          found = true;
+          if (!Objects.equals(first.getType(), second.getType())) {
+            difference.typeChanged(first);
+          }
+          if (!Objects.equals(first.getComment(), second.getComment())) {
+            difference.commentChanged(first);
+          }
+        }
+      }
+      if (!found) {
+        difference.missingFromSecond(first);
+      }
+    }
+
+    if (bothDirections) {
+      SchemaDifference otherWay = getSchemaDiff(subtrahendCollection, minuendCollection,
false);
+      otherWay.missingFromSecond().forEach(difference::missingFromFirst);
+    }
 
-    return minuendCollection.stream()
-        .filter(fs -> !subtrahendWithoutComment.contains(unsetCommentFunc.apply(fs))).collect(Collectors.toList());
+    return difference;
   }
 
+  public static class SchemaDifference {
+    private final List<FieldSchema> missingFromFirst = new ArrayList<>();
+    private final List<FieldSchema> missingFromSecond = new ArrayList<>();
+    private final List<FieldSchema> typeChanged = new ArrayList<>();
+    private final List<FieldSchema> commentChanged = new ArrayList<>();
+
+    public List<FieldSchema> missingFromFirst() {

Review comment:
       Good point, renamed the methods

##########
File path: iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/HiveSchemaUtil.java
##########
@@ -138,22 +137,88 @@ public static Type convert(TypeInfo typeInfo) {
   }
 
   /**
-   * Produces the difference of two FieldSchema lists by only taking into account the field
name and type.
+   * Returns a SchemaDifference containing those fields which are present in only one of
the collections, as well as
+   * those fields which are present in both (in terms of the name) but their type or comment
has changed.
    * @param minuendCollection Collection of fields to subtract from
    * @param subtrahendCollection Collection of fields to subtract
-   * @return the result list of difference
+   * @param bothDirections Whether or not to compute the missing fields from the minuendCollection
as well
+   * @return the difference between the two schemas
    */
-  public static Collection<FieldSchema> schemaDifference(
-      Collection<FieldSchema> minuendCollection, Collection<FieldSchema> subtrahendCollection)
{
+  public static SchemaDifference getSchemaDiff(Collection<FieldSchema> minuendCollection,
+                                               Collection<FieldSchema> subtrahendCollection,
boolean bothDirections) {
+    SchemaDifference difference = new SchemaDifference();
 
-    Function<FieldSchema, FieldSchema> unsetCommentFunc = fs -> new FieldSchema(fs.getName(),
fs.getType(), null);
-    Set<FieldSchema> subtrahendWithoutComment =
-        subtrahendCollection.stream().map(unsetCommentFunc).collect(Collectors.toSet());
+    for (FieldSchema first : minuendCollection) {
+      boolean found = false;
+      for (FieldSchema second : subtrahendCollection) {
+        if (first.getName().equals(second.getName())) {

Review comment:
       I didn't use it because `name` should never be null, unlike comment (and maybe type?).
Anyways, I've changed it to use Objects.equals to be safe and for symmetry.




-- 
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-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 619055)
    Time Spent: 2h 40m  (was: 2.5h)

> 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: 2h 40m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message