gaborkaszab commented on code in PR #6045:
URL: https://github.com/apache/iceberg/pull/6045#discussion_r1015406783
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java:
##########
@@ -518,11 +522,36 @@ private Map<String, String> convertToMetadata(Database
database) {
if (database.getDescription() != null) {
meta.put("comment", database.getDescription());
}
+ if (database.getOwnerName() != null) {
+ meta.put(TableProperties.HMS_DB_OWNER, database.getOwnerName());
+ if (database.getOwnerType() != null) {
+ meta.put(TableProperties.HMS_DB_OWNER_TYPE,
database.getOwnerType().name());
+ }
+ }
return meta;
}
Database convertToDatabase(Namespace namespace, Map<String, String> meta) {
+ Preconditions.checkArgument(
Review Comment:
In my understanding Preconditions are for checking some internal state that
should be always true. Here, if I'm not mistaken you use it to verify user
input. This seems a bit odd for me.
##########
core/src/main/java/org/apache/iceberg/TableProperties.java:
##########
@@ -360,5 +360,7 @@ private TableProperties() {}
public static final String UPSERT_ENABLED = "write.upsert.enabled";
public static final boolean UPSERT_ENABLED_DEFAULT = false;
- public static final String HMS_TABLE_OWNER = "hms_table_owner";
+ public static final String HMS_TABLE_OWNER = "hive.metastore.table.owner";
Review Comment:
What I'm not sure about is if we release 1.1.0 now with HMS_TABLE_OWNER =
"hms_table_owner" but then we change this property to
"hive.metastore.table.owner" then when this patch gets released (most probably
in 1.2.0) wouldn't it be a breaking change?
@danielcweeks could you please share your view on this?
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java:
##########
@@ -518,11 +522,36 @@ private Map<String, String> convertToMetadata(Database
database) {
if (database.getDescription() != null) {
meta.put("comment", database.getDescription());
}
+ if (database.getOwnerName() != null) {
+ meta.put(TableProperties.HMS_DB_OWNER, database.getOwnerName());
+ if (database.getOwnerType() != null) {
+ meta.put(TableProperties.HMS_DB_OWNER_TYPE,
database.getOwnerType().name());
+ }
+ }
return meta;
}
Database convertToDatabase(Namespace namespace, Map<String, String> meta) {
+ Preconditions.checkArgument(
+ meta.get(TableProperties.HMS_DB_OWNER_TYPE) == null
+ || meta.get(TableProperties.HMS_DB_OWNER) != null,
+ "Setting "
+ + TableProperties.HMS_DB_OWNER_TYPE
+ + " without setting "
+ + TableProperties.HMS_DB_OWNER
+ + "is not allowed");
+
+ Preconditions.checkArgument(
Review Comment:
Same here
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java:
##########
@@ -539,12 +541,22 @@ Database convertToDatabase(Namespace namespace,
Map<String, String> meta) {
database.setDescription(value);
} else if (key.equals("location")) {
database.setLocationUri(value);
+ } else if (key.equals(TableProperties.HMS_DB_OWNER)) {
+ database.setOwnerName(value);
+ } else if (key.equals(TableProperties.HMS_DB_OWNER_TYPE) && value !=
null) {
+ database.setOwnerType(PrincipalType.valueOf(value));
Review Comment:
See my comment above about preconditions.
##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCatalog.java:
##########
@@ -448,6 +575,59 @@ public void testRemoveNamespaceProperties() throws
TException {
});
}
+ @Test
+ public void testRemoveNamespaceOwnership() throws TException {
+ Map<String, String> prop = ImmutableMap.of(HiveCatalog.HMS_DB_OWNER,
"some_owner");
+ removeNamespaceOwnershipAndVerify("remove_individual_ownership", prop);
+
+ prop =
+ ImmutableMap.of(
+ HiveCatalog.HMS_DB_OWNER,
+ "some_owner",
+ HiveCatalog.HMS_DB_OWNER_TYPE,
+ PrincipalType.GROUP.name());
+ removeNamespaceOwnershipAndVerify("remove_group_ownership", prop);
+
+ prop = ImmutableMap.of();
+
+ removeNamespaceOwnershipAndVerify("remove_ownership_noop", prop);
Review Comment:
This tests that what happens when there is no specific owner/ownertype set
for the namespace but then we try to remove them, right?
What would also be beneficial in my opinion is to create the namespace with
some owner and then run a noop remove and check if the owner is still the same
what we provided during creation.
##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCatalog.java:
##########
@@ -448,6 +540,36 @@ public void testRemoveNamespaceProperties() throws
TException {
});
}
+ @Test
+ public void testRemoveNamespaceOwnership() throws TException {
+ Map<String, String> prop = ImmutableMap.of(TableProperties.HMS_DB_OWNER,
"some_owner");
+ removeNamespaceOwnershipAndVerify("remove_individual_ownership", prop);
+ prop =
+ ImmutableMap.of(
+ TableProperties.HMS_DB_OWNER,
+ "some_owner",
+ TableProperties.HMS_DB_OWNER_TYPE,
+ PrincipalType.GROUP.name());
+ removeNamespaceOwnershipAndVerify("remove_group_ownership", prop);
+ }
+
+ private void removeNamespaceOwnershipAndVerify(String name, Map<String,
String> prop)
Review Comment:
I think you got me wrong. I just wanted to say that when you call
catalog.createNamespace() at L619 then you immediately call
catalog.removeNamespace(). To be on the safe side I'd add an extra check
between these two steps that right after creating the namespace the owner and
owner type are as expected.
##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCatalog.java:
##########
@@ -358,6 +359,63 @@ public void testCreateNamespace() throws Exception {
"There no same location for db and namespace",
database2.getLocationUri(), hiveLocalDir);
}
+ @Test
+ public void testCreateNamespaceWithOwnership() throws Exception {
+ Map<String, String> prop =
+ ImmutableMap.of(
+ TableProperties.HMS_DB_OWNER,
+ "apache",
+ TableProperties.HMS_DB_OWNER_TYPE,
+ PrincipalType.USER.name());
+
+ String expectedOwner = "apache";
+ PrincipalType expectedOwnerType = PrincipalType.USER;
Review Comment:
No, what I meant is to instead of this:
`String expectedOwner = "apache";
PrincipalType expectedOwnerType = PrincipalType.USER;
createNamespaceAndVerifyOwnership("userOwnership", prop, expectedOwner,
expectedOwnerType);`
we could have this:
`createNamespaceAndVerifyOwnership(
"userOwnership",
prop,
"apache",
PrincipalType.USER);`
Might be personal preference. Let me know if you feel that this wouldn't
improve readability.
--
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]