You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2021/04/28 07:18:17 UTC

[GitHub] [hive] lcspinter opened a new pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

lcspinter opened a new pull request #2230:
URL: https://github.com/apache/hive/pull/2230


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
     2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
     3. Ensure you have added or run the appropriate tests for your PR: 
     4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX:  Your PR title ...'.
     5. Be sure to keep the PR description updated to reflect all changes.
     6. Please write your PR title to summarize what this PR proposes.
     7. If possible, provide a concise example to reproduce the issue for a faster review.
   
   -->
   
   ### What changes were proposed in this pull request?
   When running ALTER TABLE ... SET/UNSET TBLPROPERTIES on an Iceberg table the properties should be updated on the Iceberg side as well. 
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   The collection of changed property keys are collected on `AbstractAlterTableOperation` and stored in `EnvironemntContext`. `HiveIcebergMetaHook#commitAlterTable` takes care of the processing of `EnvironmentContext` and updating of the iceberg table. 
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   No
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   Manual test and unit test
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   


-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] marton-bod commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
marton-bod commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r622134869



##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaHook.java
##########
@@ -48,6 +48,9 @@
   public List<String> allowedAlterTypes = ImmutableList.of("ADDPROPS", "DROPPROPS");
   String ALTERLOCATION = "ALTERLOCATION";
   String ALLOW_PARTITION_KEY_CHANGE = "allow_partition_key_change";
+  String SET_PROPERTIES = "set_properties";
+  String UNSET_PROPERTIES = "unset_properties";
+  String PROPERTIES_SEPARATOR = "\n";

Review comment:
       Not sure which characters are unsupported in a key, but I think `'` might work better as a separator due to the rules of the query language (since `'` is used to mark the end of the table props in the SQL, e.g. `'key'='value'`)




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] marton-bod commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
marton-bod commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r622142344



##########
File path: iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerNoScan.java
##########
@@ -535,6 +538,38 @@ public void testCreateTableWithoutColumnComments() {
     }
   }
 
+  @Test
+  public void testAlterTableProperties() {
+    TableIdentifier identifier = TableIdentifier.of("default", "customers");
+    shell.executeStatement("CREATE EXTERNAL TABLE customers (" +
+        "t_int INT,  " +
+        "t_string STRING) " +
+        "STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler' " +
+        testTables.locationForCreateTableSQL(identifier) +
+        testTables.propertiesForCreateTableSQL(ImmutableMap.of()));

Review comment:
       why is this part needed here?




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] marton-bod commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
marton-bod commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r622134869



##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaHook.java
##########
@@ -48,6 +48,9 @@
   public List<String> allowedAlterTypes = ImmutableList.of("ADDPROPS", "DROPPROPS");
   String ALTERLOCATION = "ALTERLOCATION";
   String ALLOW_PARTITION_KEY_CHANGE = "allow_partition_key_change";
+  String SET_PROPERTIES = "set_properties";
+  String UNSET_PROPERTIES = "unset_properties";
+  String PROPERTIES_SEPARATOR = "\n";

Review comment:
       Not sure which characters are unsupported in a key, but I think ' might work better as a separator due to the rules of the query language (since ' is used to mark the end of the table props in the SQL, e.g. 'key'='value')




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] marton-bod commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
marton-bod commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r622145076



##########
File path: iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerNoScan.java
##########
@@ -535,6 +538,38 @@ public void testCreateTableWithoutColumnComments() {
     }
   }
 
+  @Test
+  public void testAlterTableProperties() {
+    TableIdentifier identifier = TableIdentifier.of("default", "customers");
+    shell.executeStatement("CREATE EXTERNAL TABLE customers (" +
+        "t_int INT,  " +
+        "t_string STRING) " +
+        "STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler' " +
+        testTables.locationForCreateTableSQL(identifier) +
+        testTables.propertiesForCreateTableSQL(ImmutableMap.of()));
+    String propKey = "dummy";
+    String propValue = "dummy_val";
+    shell.executeStatement(String.format("ALTER TABLE customers SET TBLPROPERTIES('%s'='%s')", propKey, propValue));
+    // Check the Iceberg table parameters
+    Table icebergTable = testTables.loadTable(identifier);
+    Assert.assertTrue(icebergTable.properties().containsKey(propKey));
+    Assert.assertEquals(icebergTable.properties().get(propKey), propValue);
+    propValue = "new_dummy_val";
+    shell.executeStatement(String.format("ALTER TABLE customers SET TBLPROPERTIES('%s'='%s')", propKey, propValue));

Review comment:
       nit: for readability, would it make sense to separate the 3 sections with a comment, e.g.
   `// adding a new property`, 
   `// changing the value of an existing property`, 
   `// removing/unsetting an existing prop` ..., etc.




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] lcspinter commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
lcspinter commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r622128377



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/AbstractAlterTableOperation.java
##########
@@ -136,6 +137,22 @@ private void finalizeAlterTableWithWriteIdOp(Table table, Table oldTable, List<P
 
     try {
       environmentContext.putToProperties(HiveMetaHook.ALTER_TABLE_OPERATION_TYPE, desc.getType().name());
+      if (desc.getType() == AlterTableType.ADDPROPS) {
+        Map<String, String> oldTableParameters = oldTable.getParameters();
+        environmentContext.putToProperties(HiveMetaHook.SET_PROPERTIES,
+            table.getParameters().entrySet().stream()
+                .filter(e -> !oldTableParameters.containsKey(e.getKey()) ||
+                    !oldTableParameters.get(e.getKey()).equals(e.getValue()))
+                .map(Map.Entry::getKey)
+                .collect(Collectors.joining(HiveMetaHook.PROPERTIES_SEPARATOR)));

Review comment:
       I've added a separate check to look for the separator among the property keys and throw an exception if an invalid character is found.




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] lcspinter merged pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
lcspinter merged pull request #2230:
URL: https://github.com/apache/hive/pull/2230


   


-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] marton-bod commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
marton-bod commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r622134869



##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaHook.java
##########
@@ -48,6 +48,9 @@
   public List<String> allowedAlterTypes = ImmutableList.of("ADDPROPS", "DROPPROPS");
   String ALTERLOCATION = "ALTERLOCATION";
   String ALLOW_PARTITION_KEY_CHANGE = "allow_partition_key_change";
+  String SET_PROPERTIES = "set_properties";
+  String UNSET_PROPERTIES = "unset_properties";
+  String PROPERTIES_SEPARATOR = "\n";

Review comment:
       Not sure which characters are unsupported in a key, but I think `'` might work better as a separator due to the rules of the query language (since ' is used to mark the end of the table props in the SQL, e.g. `'key'='value'`)




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] lcspinter commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
lcspinter commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r622157966



##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaHook.java
##########
@@ -48,6 +48,9 @@
   public List<String> allowedAlterTypes = ImmutableList.of("ADDPROPS", "DROPPROPS");
   String ALTERLOCATION = "ALTERLOCATION";
   String ALLOW_PARTITION_KEY_CHANGE = "allow_partition_key_change";
+  String SET_PROPERTIES = "set_properties";
+  String UNSET_PROPERTIES = "unset_properties";
+  String PROPERTIES_SEPARATOR = "\n";

Review comment:
       I like that. Adding `'` to the property key, even if it's escaped, will result in an exception during query parsing.




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] pvary commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
pvary commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r621938901



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/AbstractAlterTableOperation.java
##########
@@ -136,6 +137,22 @@ private void finalizeAlterTableWithWriteIdOp(Table table, Table oldTable, List<P
 
     try {
       environmentContext.putToProperties(HiveMetaHook.ALTER_TABLE_OPERATION_TYPE, desc.getType().name());
+      if (desc.getType() == AlterTableType.ADDPROPS) {
+        Map<String, String> oldTableParameters = oldTable.getParameters();
+        environmentContext.putToProperties(HiveMetaHook.SET_PROPERTIES,
+            table.getParameters().entrySet().stream()
+                .filter(e -> !oldTableParameters.containsKey(e.getKey()) ||
+                    !oldTableParameters.get(e.getKey()).equals(e.getValue()))
+                .map(Map.Entry::getKey)
+                .collect(Collectors.joining(HiveMetaHook.PROPERTIES_SEPARATOR)));

Review comment:
       Does this handle the situation where the separator appears in one of the key/value?




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] lcspinter commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
lcspinter commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r622159444



##########
File path: iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerNoScan.java
##########
@@ -535,6 +538,38 @@ public void testCreateTableWithoutColumnComments() {
     }
   }
 
+  @Test
+  public void testAlterTableProperties() {
+    TableIdentifier identifier = TableIdentifier.of("default", "customers");
+    shell.executeStatement("CREATE EXTERNAL TABLE customers (" +
+        "t_int INT,  " +
+        "t_string STRING) " +
+        "STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler' " +
+        testTables.locationForCreateTableSQL(identifier) +
+        testTables.propertiesForCreateTableSQL(ImmutableMap.of()));

Review comment:
       The location is needed for HadoopTable tests. The properties section is needed to set the catalog type correctly.




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] marton-bod commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
marton-bod commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r622344816



##########
File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java
##########
@@ -251,6 +254,21 @@ public void commitAlterTable(org.apache.hadoop.hive.metastore.api.Table hmsTable
       }
       HiveTableUtil.importFiles(preAlterTableProperties.tableLocation, preAlterTableProperties.format,
           partitionSpecProxy, preAlterTableProperties.partitionKeys, catalogProperties, conf);
+    } else {
+      Map<String, String> contextProperties = context.getProperties();
+      if (contextProperties.containsKey(ALTER_TABLE_OPERATION_TYPE) &&
+          allowedAlterTypes.contains(contextProperties.get(ALTER_TABLE_OPERATION_TYPE))) {
+        Map<String, String> hmsTableParameters = hmsTable.getParameters();
+        Splitter splitter = Splitter.on(PROPERTIES_SEPARATOR);
+        UpdateProperties icebergUpdateProperties = icebergTable.updateProperties();
+        if (contextProperties.containsKey(SET_PROPERTIES)) {
+          splitter.splitToList(contextProperties.get(SET_PROPERTIES))
+              .forEach(k -> icebergUpdateProperties.set(k, hmsTableParameters.get(k)));
+        } else {

Review comment:
       maybe make this `else if (contextProperties.containsKey(UNSET_PROPERTIES))`? We might later call this method from other alter table ops (e.g. schema change) and we wouldn't want to enter this block then




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] marton-bod commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
marton-bod commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r622145371



##########
File path: iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerNoScan.java
##########
@@ -29,10 +29,13 @@
 import java.util.Properties;
 import java.util.Set;
 import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;

Review comment:
       is this a leftover import?




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] lcspinter commented on a change in pull request #2230: HIVE-25065: Implement ALTER TABLE for setting iceberg table properties

Posted by GitBox <gi...@apache.org>.
lcspinter commented on a change in pull request #2230:
URL: https://github.com/apache/hive/pull/2230#discussion_r622159586



##########
File path: iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerNoScan.java
##########
@@ -535,6 +538,38 @@ public void testCreateTableWithoutColumnComments() {
     }
   }
 
+  @Test
+  public void testAlterTableProperties() {
+    TableIdentifier identifier = TableIdentifier.of("default", "customers");
+    shell.executeStatement("CREATE EXTERNAL TABLE customers (" +
+        "t_int INT,  " +
+        "t_string STRING) " +
+        "STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler' " +
+        testTables.locationForCreateTableSQL(identifier) +
+        testTables.propertiesForCreateTableSQL(ImmutableMap.of()));
+    String propKey = "dummy";
+    String propValue = "dummy_val";
+    shell.executeStatement(String.format("ALTER TABLE customers SET TBLPROPERTIES('%s'='%s')", propKey, propValue));
+    // Check the Iceberg table parameters
+    Table icebergTable = testTables.loadTable(identifier);
+    Assert.assertTrue(icebergTable.properties().containsKey(propKey));
+    Assert.assertEquals(icebergTable.properties().get(propKey), propValue);
+    propValue = "new_dummy_val";
+    shell.executeStatement(String.format("ALTER TABLE customers SET TBLPROPERTIES('%s'='%s')", propKey, propValue));

Review comment:
       Fixed.

##########
File path: iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerNoScan.java
##########
@@ -29,10 +29,13 @@
 import java.util.Properties;
 import java.util.Set;
 import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;

Review comment:
       yes.




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org