rdblue commented on a change in pull request #4184:
URL: https://github.com/apache/iceberg/pull/4184#discussion_r814268405



##########
File path: 
core/src/main/java/org/apache/iceberg/rest/responses/RESTCatalogConfigResponse.java
##########
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg.rest.responses;
+
+import java.util.Map;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+
+/**
+ * Represents a response to requesting server-side provided configuration for 
the REST catalog.
+ * This allows client provided values to be overridden by the server or 
defaulted if not provided by the client.
+ * <p>
+ * The catalog properties, with overrides and defaults applied, should be used 
to configure the catalog and for all
+ * subsequent requests after this initial config request.
+ * <p>
+ * Configuration from the server consists of two sets of key/value pairs.
+ * <ul>
+ *   <li> defaults - properties that should be used as default configuration 
</li>
+ *   <li> overrides - properties that should be used to override client 
configuration </li>
+ * </ul>
+ */
+public class RESTCatalogConfigResponse {
+
+  private Map<String, String> defaults;
+  private Map<String, String> overrides;
+
+  public RESTCatalogConfigResponse() {
+    // Required for Jackson deserialization
+  }
+
+  private RESTCatalogConfigResponse(Map<String, String> defaults, Map<String, 
String> overrides) {
+    this.defaults = defaults;
+    this.overrides = overrides;
+    validate();
+  }
+
+  RESTCatalogConfigResponse validate() {
+    return this;
+  }
+
+  /**
+   * Properties that should be used as default configuration. {@code defaults} 
have the lowest priority
+   * and should be applied before the client provided configuration.
+   *
+   * @return properties that should be used as default configuration
+   */
+  public Map<String, String> defaults() {
+    return defaults != null ? defaults : ImmutableMap.of();
+  }
+
+  /**
+   * Properties that should be used to override client configuration. {@code 
overrides} have the highest priority
+   * and should be applied after defaults and any client-provided 
configuration properties.
+   *
+   * @return properties that should be given higher precedence than any client 
provided input
+   */
+  public Map<String, String> overrides() {
+    return overrides != null ? overrides : ImmutableMap.of();
+  }
+
+  /**
+   * Merge client-provided config with server side provided configuration to 
return a single
+   * properties map which will be used for instantiating and configuring the 
REST catalog.
+   *
+   * @param clientProperties - Client provided configuration
+   * @return Merged configuration, with precedence in the order overrides, 
then client properties, and then defaults.
+   */
+  public Map<String, String> merge(Map<String, String> clientProperties) {
+    Preconditions.checkNotNull(clientProperties,
+        "Cannot merge client properties with server-provided properties. 
Invalid client configuration: null");
+    Map<String, String> merged = Maps.newHashMap(defaults);
+    merged.putAll(clientProperties);
+    merged.putAll(overrides);
+    return merged;

Review comment:
       Given your point below about using `null`, do you think it's a good idea 
to go through this list and prune out the keys with null values? Then you could 
return `ImmutableMap.copyOf(merged)`.




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