illiabarbashov-sketch commented on code in PR #6936:
URL: https://github.com/apache/hive/pull/6936#discussion_r4457501659


##########
standalone-metastore/metastore-rest-catalog/src/main/java/org/apache/iceberg/rest/HMSCatalogAdapter.java:
##########
@@ -513,8 +540,108 @@ private RESTResponse dropView(Map<String, String> vars) {
 
   private LoadViewResponse registerView(Map<String, String> vars, Object body) 
{
     Namespace namespace = namespaceFromPathVars(vars);
+    // The registered metadata file is not rewritten, so it keeps any 
HMS-managed properties; they are not copied
+    // into HMS (HMSTablePropertyHelper) and are set from HMS in the response.
     RegisterViewRequest request = castRequest(RegisterViewRequest.class, body);
-    return CatalogHandlers.registerView(asViewCatalog, namespace, request);
+    return withViewAuthorization(TableIdentifier.of(namespace, request.name()),
+        CatalogHandlers.registerView(asViewCatalog, namespace, request));
+  }
+
+  /**
+   * Whether a view property is reserved for state HMS manages: the 
authorization marker, under either name, and
+   * the owner unless client-supplied owners are enabled.
+   */
+  private boolean isReservedViewProperty(String key) {
+    return HiveCatalog.isViewAuthorizationProperty(key) ||
+        (!clientSuppliedOwnerEnabled && 
HiveCatalog.HMS_TABLE_OWNER.equalsIgnoreCase(key));
+  }
+
+  private Map<String, String> withoutReservedProperties(Map<String, String> 
properties) {
+    Map<String, String> kept = new HashMap<>(properties);
+    kept.keySet().removeIf(this::isReservedViewProperty);
+    return kept;
+  }
+
+  /**
+   * Drops the reserved properties (see {@link #isReservedViewProperty}) from 
a view creation, so that they are not
+   * stored in the Iceberg view metadata file. Dropping rather than rejecting 
keeps clients that send back the
+   * properties of a loaded view working.
+   */
+  private CreateViewRequest withoutReservedProperties(CreateViewRequest 
request) {
+    if 
(request.properties().keySet().stream().noneMatch(this::isReservedViewProperty))
 {
+      return request;
+    }
+    return ImmutableCreateViewRequest.builder()
+        .from(request)
+        .properties(withoutReservedProperties(request.properties()))
+        .build();
+  }
+
+  /** Drops the reserved properties from the property updates of a view 
update; see the creation overload. */
+  private UpdateTableRequest withoutReservedProperties(UpdateTableRequest 
request) {

Review Comment:
   These reserved properties related methods as well as the 
withViewAuthorization method increase the size of the adapter class notably. 
I'm thinking if they can be moved somewhere. I thought about HMSAuthorizer 
companion for IcebergAuthorizer might be one way to deal with it. What are your 
thoughts?



-- 
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]

Reply via email to