You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2023/01/18 19:50:04 UTC

[GitHub] [iceberg] haizhou-zhao opened a new pull request, #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

haizhou-zhao opened a new pull request, #6621:
URL: https://github.com/apache/iceberg/pull/6621

   Change List:
   1. Added support for altering and dropping table owner for HiveCatalog
   2. Added corresponding unit test


-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] [HiveCatalog] Support Altering and Dropping Table Ownership [iceberg]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#issuecomment-2307946299

   This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.


-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] haizhou-zhao commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by "haizhou-zhao (via GitHub)" <gi...@apache.org>.
haizhou-zhao commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1097737870


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   @gaborkaszab First of all, at this moment, the actual logic of creating table differs from what you think, because all properties, including ownership, gets into iceberg metadata file on creation: [ref](https://github.com/apache/iceberg/blob/333227fbd13821365cec1bdbfcb9314a239bea0f/core/src/main/java/org/apache/iceberg/BaseMetastoreCatalog.java#L191)
   
   Secondly, I have a different thought on whether ownership should be in iceberg metadata file or not. Iceberg supports many forms of metastores and today Iceberg users are allowed to migrate their tables between metastores, such as between Hive Metastore (HMS), Nessie, JDBC, Dynamo, etc. [ref](https://github.com/apache/iceberg/blob/32cfb62fdb9dca215250e4ca8285754e9393767d/core/src/main/java/org/apache/iceberg/BaseMetastoreCatalog.java#L69) So I think the question becomes, whether Iceberg users only care about ownership when they are using HMS, or they they also care when they use other forms of metastore. I tend to believe that ownership is an Iceberg table attributes, not specific to any forms of metastore. Otherwise, a user who wants to migrate a table from Hive to Nessie, for example, would find the ownership info lost over the process of migration (and they have to manually set the ownership again in Nessie).
   
   Lastly, I favor allowing user to drop ownership, but I'm good with following your thought there to not allow. I can't imagine a use case for dropping ownership (yes, I agree with you why not just alter). Yet, I see no harm in allowing users to drop ownership, and I see ownership as a normal property just like others - if we are allowed to drop other iceberg or metastore properties, then making a logical exception for the ownership property so that the "unset" (set null/clear) operation is forbidden might be some inconsistency that users need to remember and be aware of when they use the code.



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] [HiveCatalog] Support Altering and Dropping Table Ownership [iceberg]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#issuecomment-2345009600

   This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.


-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] haizhou-zhao commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by "haizhou-zhao (via GitHub)" <gi...@apache.org>.
haizhou-zhao commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1102184009


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   Thanks @gaborkaszab.
   
   First, I think altering ownership is doable even if not having owner property in iceberg Metadata. Drop ownership is going to be hard (but if we don't support drop ownership then we care less about it)
   
   Summarizing our discussion above, the core question is: whether or not "owner" is an iceberg table/namespace property.
   
   @gaborkaszab I think you are arguing that the answer should be no, and I agree that all your points make perfect sense when the answer is no (that the "owner" property should have no business with Iceberg Metadata and should only be tracked by the metastore/catalog service people uses, whether it's Hive, Nessie, DynamoDB or JDBC)
   
   @szehon-ho and @danielcweeks would love to hear your opinion and vote before committing further.



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] haizhou-zhao commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1081701820


##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCatalog.java:
##########
@@ -328,6 +329,140 @@ public void testCreateTableCustomSortOrder() throws Exception {
     }
   }
 
+  @Test
+  public void testAlterTableOwner() throws IOException, TException {
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_1",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_other_owner"),
+        "some_owner",
+        "some_other_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_2",
+        ImmutableMap.of(),
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "another_owner"),
+        UserGroupInformation.getCurrentUser().getUserName(),
+        "another_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_noop_1",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableMap.of(),
+        "some_owner",
+        "some_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_noop_2",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableMap.of("unrelated_prop", "val"),
+        "some_owner",
+        "some_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_noop_3",
+        ImmutableMap.of(),
+        ImmutableMap.of(),
+        UserGroupInformation.getCurrentUser().getUserName(),
+        UserGroupInformation.getCurrentUser().getUserName());
+  }
+
+  private void alterTableAndVerifyOwner(
+      String db,
+      String tbl,
+      Map<String, String> properties,
+      Map<String, String> updates,
+      String expectedOwnerPostCreate,
+      String expectedOwnerPostAlter)
+      throws IOException, TException {
+    Schema schema = getTestSchema();
+    PartitionSpec spec = PartitionSpec.builderFor(schema).bucket("data", 16).build();
+    TableIdentifier tableIdent = TableIdentifier.of(db, tbl);
+    String location = temp.newFolder(tbl).toString();
+    try {
+      Table table = catalog.createTable(tableIdent, schema, spec, location, properties);
+      org.apache.hadoop.hive.metastore.api.Table hmsTable = metastoreClient.getTable(db, tbl);
+      Assert.assertEquals(expectedOwnerPostCreate, hmsTable.getOwner());
+      Assert.assertFalse(hmsTable.getParameters().containsKey(HiveCatalog.HMS_TABLE_OWNER));
+      UpdateProperties updateOps = table.updateProperties();
+      updates.forEach(updateOps::set);
+      updateOps.commit();
+      hmsTable = metastoreClient.getTable(db, tbl);
+      Assert.assertEquals(expectedOwnerPostAlter, hmsTable.getOwner());
+      Assert.assertFalse(hmsTable.getParameters().containsKey(HiveCatalog.HMS_TABLE_OWNER));
+    } finally {
+      catalog.dropTable(tableIdent);
+    }
+  }
+
+  @Test
+  public void testRemoveTableOwner() throws IOException, TException {
+    removeTableOwnerAndVerify(
+        DB_NAME,
+        "tbl_remove_owner_1",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableSet.of(HiveCatalog.HMS_TABLE_OWNER),
+        "some_owner",
+        UserGroupInformation.getCurrentUser().getUserName());
+    removeTableOwnerAndVerify(
+        DB_NAME,
+        "tbl_remove_owner_noop_1",
+        ImmutableMap.of(),
+        ImmutableSet.of(HiveCatalog.HMS_TABLE_OWNER),
+        UserGroupInformation.getCurrentUser().getUserName(),
+        UserGroupInformation.getCurrentUser().getUserName());
+    removeTableOwnerAndVerify(
+        DB_NAME,
+        "tbl_remove_owner_noop_2",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableSet.of(),
+        "some_owner",
+        "some_owner");
+    removeTableOwnerAndVerify(
+        DB_NAME,
+        "tbl_remove_owner_noop_3",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableSet.of("unrelated_prop"),
+        "some_owner",
+        "some_owner");
+    removeTableOwnerAndVerify(
+        DB_NAME,
+        "tbl_remove_owner_noop_4",
+        ImmutableMap.of(),
+        ImmutableSet.of(),
+        UserGroupInformation.getCurrentUser().getUserName(),
+        UserGroupInformation.getCurrentUser().getUserName());
+  }
+
+  private void removeTableOwnerAndVerify(

Review Comment:
   Ack. thx



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] haizhou-zhao commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by "haizhou-zhao (via GitHub)" <gi...@apache.org>.
haizhou-zhao commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1084710334


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   @gaborkaszab @szehon-ho I realized something: if we created table without explicitly specifying an owner (relying on default owner), then we won't be able to drop (set null) the table owner later. Reason is when creating a table without owner specified, the owner property is not tracked by Iceberg Metadata file (even though there is an owner - the default owner). The later drop will just be a noop instead of setting owner to null since it cannot detect this owner property disappeared.
   
   So I guess we have two way forward:
   1. We can totally ignore drop owner, so dropping owner of all table becomes a noop
   2. We can edit the create table code, by forcing creating table to always write the owner name to Iceberg Metadata file, whether with owner specified or not
   
   In anyway, the current implementation even after switched to set null is wrong, it causes inconsistent behavior:
   1. When invoking drop owner on a table created with owner specified, it will set null
   2. When invoking drop owner on a table created without owner specified, it will be a noop



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] haizhou-zhao commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by "haizhou-zhao (via GitHub)" <gi...@apache.org>.
haizhou-zhao commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1084710334


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   @gaborkaszab @szehon-ho I realized something: if we created table with default owner, then we won't be able to drop the table owner (flip from the default owner/current user to null). Reason is when creating a table without owner specified, the owner property is not tracked by Iceberg Metadata file (even though there is an owner - the default owner). The later drop will just be a noop instead of setting owner to null since it cannot detect this owner property disappeared.
   
   So I guess we have two way forward:
   1. We can totally ignore drop owner, so dropping owner of all table becomes a noop
   2. We can force creating table to always write the owner name to Iceberg Metadata file, whether with owner specified or not (when not specified then the default owner)
   
   In anyway, the current implementation even after switched to set null is wrong, it causes inconsistent behavior:
   1. When invoking drop owner on a table created with owner specified, it will set null
   2. When invoking drop owner on a table created without owner specified, it will be a noop



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] [HiveCatalog] Support Altering and Dropping Table Ownership [iceberg]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership
URL: https://github.com/apache/iceberg/pull/6621


-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] szehon-ho commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by GitBox <gi...@apache.org>.
szehon-ho commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1081718764


##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCatalog.java:
##########
@@ -328,6 +329,140 @@ public void testCreateTableCustomSortOrder() throws Exception {
     }
   }
 
+  @Test
+  public void testAlterTableOwner() throws IOException, TException {
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_1",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_other_owner"),
+        "some_owner",
+        "some_other_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_2",
+        ImmutableMap.of(),
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "another_owner"),
+        UserGroupInformation.getCurrentUser().getUserName(),
+        "another_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_noop_1",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableMap.of(),
+        "some_owner",
+        "some_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_noop_2",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableMap.of("unrelated_prop", "val"),
+        "some_owner",
+        "some_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_noop_3",
+        ImmutableMap.of(),
+        ImmutableMap.of(),
+        UserGroupInformation.getCurrentUser().getUserName(),
+        UserGroupInformation.getCurrentUser().getUserName());
+  }
+
+  private void alterTableAndVerifyOwner(

Review Comment:
   Nit: I think in most tests, we put the private at end of file?  So the ```@Test``` are all in the top and easier to find.



##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   Also too don't know of the use-case, but makes sense to me to set it to null 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.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] haizhou-zhao commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by "haizhou-zhao (via GitHub)" <gi...@apache.org>.
haizhou-zhao commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1084710334


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   @gaborkaszab @szehon-ho I realized something: if we created table without explicitly specifying an owner (relying on default owner), then we won't be able to drop the table owner (flip from the default owner/current user to null). Reason is when creating a table without owner specified, the owner property is not tracked by Iceberg Metadata file (even though there is an owner - the default owner). The later drop will just be a noop instead of setting owner to null since it cannot detect this owner property disappeared.
   
   So I guess we have two way forward:
   1. We can totally ignore drop owner, so dropping owner of all table becomes a noop
   2. We can force creating table to always write the owner name to Iceberg Metadata file, whether with owner specified or not (when not specified then the default owner)
   
   In anyway, the current implementation even after switched to set null is wrong, it causes inconsistent behavior:
   1. When invoking drop owner on a table created with owner specified, it will set null
   2. When invoking drop owner on a table created without owner specified, it will be a noop



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] haizhou-zhao commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by "haizhou-zhao (via GitHub)" <gi...@apache.org>.
haizhou-zhao commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1084710334


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   @gaborkaszab @szehon-ho I realized something: if we created table without explicitly specifying an owner (relying on default owner), then we won't be able to drop (set null) the table owner later. Reason is when creating a table without owner specified, the owner property is not tracked by Iceberg Metadata file (even though there is an owner - the default owner). The later drop will just be a noop instead of setting owner to null since it cannot detect this owner property disappeared.
   
   So I guess we have two way forward:
   1. We can totally ignore drop owner, so dropping owner of all table becomes a noop
   2. We can force creating table to always write the owner name to Iceberg Metadata file, whether with owner specified or not (when not specified then the default owner)
   
   In anyway, the current implementation even after switched to set null is wrong, it causes inconsistent behavior:
   1. When invoking drop owner on a table created with owner specified, it will set null
   2. When invoking drop owner on a table created without owner specified, it will be a noop



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] gaborkaszab commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by GitBox <gi...@apache.org>.
gaborkaszab commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1081178346


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   I wondering if the "drop ownership" use-case makes any sense. In case I'm not satisfied with the current owner of a table instead of dropping the owner I could assign it to someone (e.g. myself). I feel that setting the owner to the user who runs the updateProperties() query seems more like a side-effect rather than what a user might expect.
   However, I'm open for other opinions here.
   
   



##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCatalog.java:
##########
@@ -328,6 +329,140 @@ public void testCreateTableCustomSortOrder() throws Exception {
     }
   }
 
+  @Test
+  public void testAlterTableOwner() throws IOException, TException {
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_1",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_other_owner"),
+        "some_owner",
+        "some_other_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_2",
+        ImmutableMap.of(),
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "another_owner"),
+        UserGroupInformation.getCurrentUser().getUserName(),
+        "another_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_noop_1",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableMap.of(),
+        "some_owner",
+        "some_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_noop_2",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableMap.of("unrelated_prop", "val"),
+        "some_owner",
+        "some_owner");
+    alterTableAndVerifyOwner(
+        DB_NAME,
+        "tbl_alter_owner_noop_3",
+        ImmutableMap.of(),
+        ImmutableMap.of(),
+        UserGroupInformation.getCurrentUser().getUserName(),
+        UserGroupInformation.getCurrentUser().getUserName());
+  }
+
+  private void alterTableAndVerifyOwner(
+      String db,
+      String tbl,
+      Map<String, String> properties,
+      Map<String, String> updates,
+      String expectedOwnerPostCreate,
+      String expectedOwnerPostAlter)
+      throws IOException, TException {
+    Schema schema = getTestSchema();
+    PartitionSpec spec = PartitionSpec.builderFor(schema).bucket("data", 16).build();
+    TableIdentifier tableIdent = TableIdentifier.of(db, tbl);
+    String location = temp.newFolder(tbl).toString();
+    try {
+      Table table = catalog.createTable(tableIdent, schema, spec, location, properties);
+      org.apache.hadoop.hive.metastore.api.Table hmsTable = metastoreClient.getTable(db, tbl);
+      Assert.assertEquals(expectedOwnerPostCreate, hmsTable.getOwner());
+      Assert.assertFalse(hmsTable.getParameters().containsKey(HiveCatalog.HMS_TABLE_OWNER));
+      UpdateProperties updateOps = table.updateProperties();
+      updates.forEach(updateOps::set);
+      updateOps.commit();
+      hmsTable = metastoreClient.getTable(db, tbl);
+      Assert.assertEquals(expectedOwnerPostAlter, hmsTable.getOwner());
+      Assert.assertFalse(hmsTable.getParameters().containsKey(HiveCatalog.HMS_TABLE_OWNER));
+    } finally {
+      catalog.dropTable(tableIdent);
+    }
+  }
+
+  @Test
+  public void testRemoveTableOwner() throws IOException, TException {
+    removeTableOwnerAndVerify(
+        DB_NAME,
+        "tbl_remove_owner_1",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableSet.of(HiveCatalog.HMS_TABLE_OWNER),
+        "some_owner",
+        UserGroupInformation.getCurrentUser().getUserName());
+    removeTableOwnerAndVerify(
+        DB_NAME,
+        "tbl_remove_owner_noop_1",
+        ImmutableMap.of(),
+        ImmutableSet.of(HiveCatalog.HMS_TABLE_OWNER),
+        UserGroupInformation.getCurrentUser().getUserName(),
+        UserGroupInformation.getCurrentUser().getUserName());
+    removeTableOwnerAndVerify(
+        DB_NAME,
+        "tbl_remove_owner_noop_2",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableSet.of(),
+        "some_owner",
+        "some_owner");
+    removeTableOwnerAndVerify(
+        DB_NAME,
+        "tbl_remove_owner_noop_3",
+        ImmutableMap.of(HiveCatalog.HMS_TABLE_OWNER, "some_owner"),
+        ImmutableSet.of("unrelated_prop"),
+        "some_owner",
+        "some_owner");
+    removeTableOwnerAndVerify(
+        DB_NAME,
+        "tbl_remove_owner_noop_4",
+        ImmutableMap.of(),
+        ImmutableSet.of(),
+        UserGroupInformation.getCurrentUser().getUserName(),
+        UserGroupInformation.getCurrentUser().getUserName());
+  }
+
+  private void removeTableOwnerAndVerify(

Review Comment:
   nit: this seems almost identical to alterTableAndVerifyOwner except 1 line that decides if we are altering or removing. Can you please merge these two function together and make the updateProperties operation pluggable or being decided by some parameter?



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] szehon-ho commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by "szehon-ho (via GitHub)" <gi...@apache.org>.
szehon-ho commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1084720439


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   I like option 2, I think metadata file should be consistent with HMS metadata.  @gaborkaszab what do you think?



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] gaborkaszab commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by "gaborkaszab (via GitHub)" <gi...@apache.org>.
gaborkaszab commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1097453375


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   @haizhou-zhao, sorry for the delay with my answer.
   
   I might miss something here but I don't think that table ownership should be present in the Iceberg Metadata files nor should be a table property, it's rather an attribute of the table in HMS that could be provided during table creation. If you check [this line](https://github.com/apache/iceberg/blob/333227fbd13821365cec1bdbfcb9314a239bea0f/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java#L374) I deliberately remove the HMS_TABLE_OWNER from the table properties because this information should only present for tables in HiveCatalog in HMS. The reason TableMetadata.properties() is used for setting the table ownership is that there was no other way to pass this piece of information to HMS without changing the Iceberg API. But HMS_TABLE_OWNER is eventually not added as an actual table param.
   
   Following this logic I don't think that removing table ownership makes sense as a table should always have an owner. I'd vote for rejecting such requests rather than setting some default value. If the current user wants to grab the ownership of the table then it can change the ownership rather than removing it.
   So in general how I imagine this is to allow changing ownership via setting a table property (but at the end this shouldn't end up as an actual table property) and I'd not allow the user to remove table ownership.



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] gaborkaszab commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by "gaborkaszab (via GitHub)" <gi...@apache.org>.
gaborkaszab commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1100359365


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   Thanks for the heads-up, @haizhou-zhao!
   
   I did some debugging and HMS_TABLE_OWNER indeed makes it into the TableMetadata not just to HMS. However, when I introduced this property my intention was to use it only for table creation to pass this to HMS and not to make it part of the table properties nor the table metadata. This is the reason I explicitly remove it from the table properties [here](https://github.com/apache/iceberg/blob/eeb055a37705b8c8ff1e13acefe0ba24382c66fe/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java#L374). The reason this had to be provided as a table property is that this approach didn't require any Iceberg API changes, and the purpose was to pass it as table property, give it to HMS during table creation and then drop from the table properties as it have never existed there. Unfortunately as I see, as a side effect it made it into table metadata, that is unintentional (nice catch, btw).
   
   So long story short, I don't think that any of the Iceberg clients use HMS_TABLE_OWNER as a table metadata at all. I'm certain that it is not used for determining the owner of the table (I'm not sure how other catalogs keep track of this info, if they do at all).
   
   So that's why I was confused why we want to keep the owner in the metadata sync with the one in HMS because I only intended to add this piece of info into HMS and wasn't aware that accidentally I added it to the metadata as well.
   I'm wondering if it makes sense to get rid of HMS_TABLE_OWNER from the table metadata? It would make altering the owner difficult, right?
   
   A remark on the "drop ownership" part: well, it might be possible to drop other properties, but I still feel that dropping ownership simply doesn't make any sense especially that after dropping we have to set something as an owner and regardless of whoever we set, it feels like a side effect. I'd vote for not allow dropping ownership.



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] haizhou-zhao commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by "haizhou-zhao (via GitHub)" <gi...@apache.org>.
haizhou-zhao commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1102184009


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   Thanks @gaborkaszab.
   
   First, I think altering and dropping ownership are both doable even if not having owner property in iceberg Metadata. Maybe more if branches, but ultimately should be achievable.
   
   Summarizing our discussion above, the core question is: whether or not "owner" is an iceberg table/namespace property.
   
   @gaborkaszab I think you are arguing that the answer should be no, and I agree that all your points make perfect sense when the answer is no (that the "owner" property should have no business with Iceberg Metadata and should only be tracked by the metastore/catalog service people uses, whether it's Hive, Nessie, DynamoDB or JDBC)
   
   @szehon-ho and @danielcweeks would love to hear your opinion and vote before committing further.



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] haizhou-zhao commented on a diff in pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on code in PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#discussion_r1081700457


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -494,6 +494,17 @@ private void setHmsTableParameters(
     // remove any props from HMS that are no longer present in Iceberg table props
     obsoleteProps.forEach(parameters::remove);
 
+    // altering owner
+    if (metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER) != null) {
+      tbl.setOwner(metadata.properties().get(HiveCatalog.HMS_TABLE_OWNER));
+    }
+
+    // dropping owner: instead of leaving the owner blank/null, the owner will be
+    // default to whoever is making the current drop operation
+    if (obsoleteProps.contains(HiveCatalog.HMS_TABLE_OWNER)) {

Review Comment:
   Fair, I think that's a good point that perhaps simply removing owner and set null is closer to what users want. Trying to do some thing smart here might get user confused instead of helping.
   
   As for whether the "drop ownership" use case is needed overall, to be honest I personally do not have and cannot think of a use. However, from the code perspective, there's nothing stopping an iceberg user using iceberg APIs to remove `HiveCatalog.HMS_TABLE_OWNER` property. If that does happen, then I felt the actual intention of the user is to get rid of owner rather than do nothing. Maybe she wants to put the table into a state where only the admin and no other people could access it for a while before she knows for sure who the rightful owner should be.



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] haizhou-zhao commented on pull request #6621: [HiveCatalog] Support Altering and Dropping Table Ownership

Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on PR #6621:
URL: https://github.com/apache/iceberg/pull/6621#issuecomment-1396089374

   @gaborkaszab @danielcweeks @szehon-ho This is a follow up on previous PR at https://github.com/apache/iceberg/pull/6324, where @gaborkaszab and I discussed and believe it would be great to support alter/drop table ownership operations for HiveCatalog.


-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org