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 2022/01/31 00:56:15 UTC

[GitHub] [iceberg] SinghAsDev commented on a change in pull request #4011: Allow table defaults to be configured and/ or enforced at catalog level using catalog properties.

SinghAsDev commented on a change in pull request #4011:
URL: https://github.com/apache/iceberg/pull/4011#discussion_r795286751



##########
File path: api/src/main/java/org/apache/iceberg/catalog/Catalog.java
##########
@@ -388,6 +392,59 @@ default TableBuilder buildTable(TableIdentifier identifier, Schema schema) {
   default void initialize(String name, Map<String, String> properties) {
   }
 
+  /**
+   * Get catalog properties.
+   *
+   * @return catalog properties
+   */
+  Map<String, String> properties();
+
+  /**
+   * Get default table properties set at Catalog level through catalog properties.
+   *
+   * @return default table properties specified in catalog properties
+   */
+  default Map<String, String> tableCreateDefaultProperties() {
+    String tableCreateDefaultPrefix = "table.create.default.";
+    Map<String, String> props = properties() == null ? Collections.emptyMap() : properties();
+
+    return props.entrySet().stream()
+        .filter(e -> e.getKey().toLowerCase(Locale.ROOT).startsWith(tableCreateDefaultPrefix))
+        .collect(Collectors.toMap(e -> e.getKey().replace(tableCreateDefaultPrefix, ""),
+            Map.Entry::getValue));
+  }
+
+  /**
+   * Get table properties that are enforced at Catalog level through catalog properties.
+   *
+   * @return default table properties enforced through catalog properties
+   */
+  default Map<String, String> tableCreateEnforcedProperties() {
+    String tableCreateEnforcedPrefix = "table.create.enforced.";
+    Map<String, String> props = properties() == null ? Collections.emptyMap() : properties();
+
+    return props.entrySet().stream()
+        .filter(e -> e.getKey().toLowerCase(Locale.ROOT).startsWith(tableCreateEnforcedPrefix))
+        .collect(Collectors.toMap(e -> e.getKey().replace(tableCreateEnforcedPrefix, ""),
+            Map.Entry::getValue));
+  }
+
+  /**
+   * Return updated table properties with table properties defaults and enforcements set at Catalog level through
+   * catalog properties.
+   *
+   * @return updated table properties with defaults and enforcements set at Catalog level
+   */
+  default Map<String, String> overrideTableProperties(Map<String, String> tableProperties) {
+    Map<String, String> props = tableProperties == null ? Collections.emptyMap() : tableProperties;
+
+    return Stream.concat(Stream.concat(
+        tableCreateDefaultProperties().entrySet().stream(),
+            props.entrySet().stream()),

Review comment:
       Thanks for the pointer, updated.




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