You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by et...@apache.org on 2025/03/18 06:31:57 UTC

(iceberg) branch main updated: Core: Add `view-override` catalog property (#12534)

This is an automated email from the ASF dual-hosted git repository.

etudenhoefner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/main by this push:
     new 8f6ebb5b36 Core: Add `view-override` catalog property (#12534)
8f6ebb5b36 is described below

commit 8f6ebb5b36a0263edfcb04e0c104b26225f95b07
Author: Yuya Ebihara <eb...@gmail.com>
AuthorDate: Tue Mar 18 15:31:51 2025 +0900

    Core: Add `view-override` catalog property (#12534)
---
 .../java/org/apache/iceberg/CatalogProperties.java |  1 +
 .../apache/iceberg/rest/RESTSessionCatalog.java    | 18 ++++++++++++
 .../iceberg/view/BaseMetastoreViewCatalog.java     | 18 ++++++++++++
 .../iceberg/inmemory/TestInMemoryViewCatalog.java  |  3 ++
 .../apache/iceberg/jdbc/TestJdbcViewCatalog.java   |  3 ++
 .../apache/iceberg/rest/TestRESTViewCatalog.java   |  3 ++
 .../TestRESTViewCatalogWithAssumedViewSupport.java |  8 +++++-
 .../org/apache/iceberg/view/ViewCatalogTests.java  | 33 ++++++++++++++++++++++
 docs/docs/spark-configuration.md                   |  1 +
 .../apache/iceberg/hive/TestHiveViewCatalog.java   |  8 +++++-
 .../iceberg/nessie/TestNessieViewCatalog.java      |  8 +++++-
 .../java/org/apache/iceberg/rest/RCKUtils.java     |  6 ++++
 12 files changed, 107 insertions(+), 3 deletions(-)

diff --git a/core/src/main/java/org/apache/iceberg/CatalogProperties.java b/core/src/main/java/org/apache/iceberg/CatalogProperties.java
index 25d331c832..c17ed59b26 100644
--- a/core/src/main/java/org/apache/iceberg/CatalogProperties.java
+++ b/core/src/main/java/org/apache/iceberg/CatalogProperties.java
@@ -30,6 +30,7 @@ public class CatalogProperties {
   public static final String TABLE_DEFAULT_PREFIX = "table-default.";
   public static final String TABLE_OVERRIDE_PREFIX = "table-override.";
   public static final String VIEW_DEFAULT_PREFIX = "view-default.";
+  public static final String VIEW_OVERRIDE_PREFIX = "view-override.";
   public static final String METRICS_REPORTER_IMPL = "metrics-reporter-impl";
 
   /**
diff --git a/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java b/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java
index b46e821f50..a48751e5ae 100644
--- a/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java
+++ b/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java
@@ -1205,6 +1205,20 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog
       return viewDefaultProperties;
     }
 
+    /**
+     * Get view properties that are enforced at Catalog level through catalog properties.
+     *
+     * @return overriding view properties enforced through catalog properties
+     */
+    private Map<String, String> viewOverrideProperties() {
+      Map<String, String> viewOverrideProperties =
+          PropertyUtil.propertiesWithPrefix(properties(), CatalogProperties.VIEW_OVERRIDE_PREFIX);
+      LOG.info(
+          "View properties enforced at catalog level through catalog properties: {}",
+          viewOverrideProperties);
+      return viewOverrideProperties;
+    }
+
     @Override
     public ViewBuilder withSchema(Schema newSchema) {
       this.schema = newSchema;
@@ -1268,6 +1282,8 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog
               .putAllSummary(EnvironmentContext.get())
               .build();
 
+      properties.putAll(viewOverrideProperties());
+
       CreateViewRequest request =
           ImmutableCreateViewRequest.builder()
               .name(identifier.name())
@@ -1365,6 +1381,8 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog
               .putAllSummary(EnvironmentContext.get())
               .build();
 
+      properties.putAll(viewOverrideProperties());
+
       ViewMetadata.Builder builder =
           ViewMetadata.buildFrom(metadata)
               .setProperties(properties)
diff --git a/core/src/main/java/org/apache/iceberg/view/BaseMetastoreViewCatalog.java b/core/src/main/java/org/apache/iceberg/view/BaseMetastoreViewCatalog.java
index 2f747c5455..76e87711a9 100644
--- a/core/src/main/java/org/apache/iceberg/view/BaseMetastoreViewCatalog.java
+++ b/core/src/main/java/org/apache/iceberg/view/BaseMetastoreViewCatalog.java
@@ -102,6 +102,20 @@ public abstract class BaseMetastoreViewCatalog extends BaseMetastoreCatalog impl
       return viewDefaultProperties;
     }
 
+    /**
+     * Get view properties that are enforced at Catalog level through catalog properties.
+     *
+     * @return overriding view properties enforced through catalog properties
+     */
+    private Map<String, String> viewOverrideProperties() {
+      Map<String, String> viewOverrideProperties =
+          PropertyUtil.propertiesWithPrefix(properties(), CatalogProperties.VIEW_OVERRIDE_PREFIX);
+      LOG.info(
+          "View properties enforced at catalog level through catalog properties: {}",
+          viewOverrideProperties);
+      return viewOverrideProperties;
+    }
+
     @Override
     public ViewBuilder withSchema(Schema newSchema) {
       this.schema = newSchema;
@@ -187,6 +201,8 @@ public abstract class BaseMetastoreViewCatalog extends BaseMetastoreCatalog impl
               .putAllSummary(EnvironmentContext.get())
               .build();
 
+      properties.putAll(viewOverrideProperties());
+
       ViewMetadata viewMetadata =
           ViewMetadata.builder()
               .setProperties(properties)
@@ -236,6 +252,8 @@ public abstract class BaseMetastoreViewCatalog extends BaseMetastoreCatalog impl
               .putAllSummary(EnvironmentContext.get())
               .build();
 
+      properties.putAll(viewOverrideProperties());
+
       ViewMetadata.Builder builder =
           ViewMetadata.buildFrom(metadata)
               .setProperties(properties)
diff --git a/core/src/test/java/org/apache/iceberg/inmemory/TestInMemoryViewCatalog.java b/core/src/test/java/org/apache/iceberg/inmemory/TestInMemoryViewCatalog.java
index 79f187b1f6..4ae8c792e5 100644
--- a/core/src/test/java/org/apache/iceberg/inmemory/TestInMemoryViewCatalog.java
+++ b/core/src/test/java/org/apache/iceberg/inmemory/TestInMemoryViewCatalog.java
@@ -35,6 +35,9 @@ public class TestInMemoryViewCatalog extends ViewCatalogTests<InMemoryCatalog> {
         ImmutableMap.<String, String>builder()
             .put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1")
             .put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key2", "catalog-default-key2")
+            .put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key3", "catalog-default-key3")
+            .put(CatalogProperties.VIEW_OVERRIDE_PREFIX + "key3", "catalog-override-key3")
+            .put(CatalogProperties.VIEW_OVERRIDE_PREFIX + "key4", "catalog-override-key4")
             .build());
   }
 
diff --git a/core/src/test/java/org/apache/iceberg/jdbc/TestJdbcViewCatalog.java b/core/src/test/java/org/apache/iceberg/jdbc/TestJdbcViewCatalog.java
index 2ac12015ab..0deab3b827 100644
--- a/core/src/test/java/org/apache/iceberg/jdbc/TestJdbcViewCatalog.java
+++ b/core/src/test/java/org/apache/iceberg/jdbc/TestJdbcViewCatalog.java
@@ -59,6 +59,9 @@ public class TestJdbcViewCatalog extends ViewCatalogTests<JdbcCatalog> {
     properties.put(JdbcUtil.SCHEMA_VERSION_PROPERTY, JdbcUtil.SchemaVersion.V1.name());
     properties.put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1");
     properties.put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key2", "catalog-default-key2");
+    properties.put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key3", "catalog-default-key3");
+    properties.put(CatalogProperties.VIEW_OVERRIDE_PREFIX + "key3", "catalog-override-key3");
+    properties.put(CatalogProperties.VIEW_OVERRIDE_PREFIX + "key4", "catalog-override-key4");
 
     catalog = new JdbcCatalog();
     catalog.setConf(new Configuration());
diff --git a/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java b/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java
index 0214e8762a..3abb40fad0 100644
--- a/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java
+++ b/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java
@@ -78,6 +78,9 @@ public class TestRESTViewCatalog extends ViewCatalogTests<RESTCatalog> {
             .put(CatalogProperties.WAREHOUSE_LOCATION, warehouse.getAbsolutePath())
             .put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1")
             .put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key2", "catalog-default-key2")
+            .put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key3", "catalog-default-key3")
+            .put(CatalogProperties.VIEW_OVERRIDE_PREFIX + "key3", "catalog-override-key3")
+            .put(CatalogProperties.VIEW_OVERRIDE_PREFIX + "key4", "catalog-override-key4")
             .build());
 
     RESTCatalogAdapter adaptor =
diff --git a/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalogWithAssumedViewSupport.java b/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalogWithAssumedViewSupport.java
index ee9d8cdfd2..b6e2076934 100644
--- a/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalogWithAssumedViewSupport.java
+++ b/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalogWithAssumedViewSupport.java
@@ -94,6 +94,12 @@ public class TestRESTViewCatalogWithAssumedViewSupport extends TestRESTViewCatal
             CatalogProperties.VIEW_DEFAULT_PREFIX + "key1",
             "catalog-default-key1",
             CatalogProperties.VIEW_DEFAULT_PREFIX + "key2",
-            "catalog-default-key2"));
+            "catalog-default-key2",
+            CatalogProperties.VIEW_DEFAULT_PREFIX + "key3",
+            "catalog-default-key3",
+            CatalogProperties.VIEW_OVERRIDE_PREFIX + "key3",
+            "catalog-override-key3",
+            CatalogProperties.VIEW_OVERRIDE_PREFIX + "key4",
+            "catalog-override-key4"));
   }
 }
diff --git a/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java b/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
index 3bdf0cb8a1..81f0d6d577 100644
--- a/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
+++ b/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
@@ -163,6 +163,39 @@ public abstract class ViewCatalogTests<C extends ViewCatalog & SupportsNamespace
     assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse();
   }
 
+  @Test
+  public void overrideViewProperties() {
+    TableIdentifier identifier = TableIdentifier.of("ns", "view");
+
+    if (requiresNamespaceCreate()) {
+      catalog().createNamespace(identifier.namespace());
+    }
+
+    assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse();
+
+    View view =
+        catalog()
+            .buildView(identifier)
+            .withSchema(SCHEMA)
+            .withDefaultNamespace(identifier.namespace())
+            .withDefaultCatalog(catalog().name())
+            .withQuery("spark", "select * from ns.tbl")
+            .withProperty("key4", "catalog-overridden-key4")
+            .withProperty("prop1", "val1")
+            .create();
+
+    assertThat(view).isNotNull();
+    assertThat(view.properties())
+        .containsEntry("key1", "catalog-default-key1")
+        .containsEntry("key2", "catalog-default-key2")
+        .containsEntry("key3", "catalog-override-key3")
+        .containsEntry("key4", "catalog-override-key4")
+        .containsEntry("prop1", "val1");
+
+    assertThat(catalog().dropView(identifier)).isTrue();
+    assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse();
+  }
+
   @Test
   public void completeCreateView() {
     TableIdentifier identifier = TableIdentifier.of("ns", "view");
diff --git a/docs/docs/spark-configuration.md b/docs/docs/spark-configuration.md
index 54adf15e29..0b791003fb 100644
--- a/docs/docs/spark-configuration.md
+++ b/docs/docs/spark-configuration.md
@@ -78,6 +78,7 @@ Both catalogs are configured using properties nested under the catalog name. Com
 | spark.sql.catalog._catalog-name_.table-default._propertyKey_  |                               | Default Iceberg table property value for property key _propertyKey_, which will be set on tables created by this catalog if not overridden                                                                                               |
 | spark.sql.catalog._catalog-name_.table-override._propertyKey_ |                               | Enforced Iceberg table property value for property key _propertyKey_, which cannot be overridden on table creation by user                                                                                                               |
 | spark.sql.catalog._catalog-name_.view-default._propertyKey_  |                               | Default Iceberg view property value for property key _propertyKey_, which will be set on views created by this catalog if not overridden                                                                                               |
+| spark.sql.catalog._catalog-name_.view-override._propertyKey_ |                               | Enforced Iceberg view property value for property key _propertyKey_, which cannot be overridden on view creation by user                                                                                                               |
 | spark.sql.catalog._catalog-name_.use-nullable-query-schema | `true` or `false` | Whether to preserve fields' nullability when creating the table using CTAS and RTAS. If set to `true`, all fields will be marked as nullable. If set to `false`, fields' nullability will be preserved. The default value is `true`. Available in Spark 3.5 and above.   |
 
 Additional properties can be found in common [catalog configuration](configuration.md#catalog-properties).
diff --git a/hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveViewCatalog.java b/hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveViewCatalog.java
index 8578afc8fb..06b8a88a74 100644
--- a/hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveViewCatalog.java
+++ b/hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveViewCatalog.java
@@ -70,7 +70,13 @@ public class TestHiveViewCatalog extends ViewCatalogTests<HiveCatalog> {
                     CatalogProperties.VIEW_DEFAULT_PREFIX + "key1",
                     "catalog-default-key1",
                     CatalogProperties.VIEW_DEFAULT_PREFIX + "key2",
-                    "catalog-default-key2"),
+                    "catalog-default-key2",
+                    CatalogProperties.VIEW_DEFAULT_PREFIX + "key3",
+                    "catalog-default-key3",
+                    CatalogProperties.VIEW_OVERRIDE_PREFIX + "key3",
+                    "catalog-override-key3",
+                    CatalogProperties.VIEW_OVERRIDE_PREFIX + "key4",
+                    "catalog-override-key4"),
                 HIVE_METASTORE_EXTENSION.hiveConf());
   }
 
diff --git a/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieViewCatalog.java b/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieViewCatalog.java
index 94a1c1ec34..7bc24451c8 100644
--- a/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieViewCatalog.java
+++ b/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieViewCatalog.java
@@ -132,7 +132,13 @@ public class TestNessieViewCatalog extends ViewCatalogTests<NessieCatalog> {
             CatalogProperties.VIEW_DEFAULT_PREFIX + "key1",
             "catalog-default-key1",
             CatalogProperties.VIEW_DEFAULT_PREFIX + "key2",
-            "catalog-default-key2");
+            "catalog-default-key2",
+            CatalogProperties.VIEW_DEFAULT_PREFIX + "key3",
+            "catalog-default-key3",
+            CatalogProperties.VIEW_OVERRIDE_PREFIX + "key3",
+            "catalog-override-key3",
+            CatalogProperties.VIEW_OVERRIDE_PREFIX + "key4",
+            "catalog-override-key4");
     newCatalog.initialize("nessie", options);
     return newCatalog;
   }
diff --git a/open-api/src/testFixtures/java/org/apache/iceberg/rest/RCKUtils.java b/open-api/src/testFixtures/java/org/apache/iceberg/rest/RCKUtils.java
index 741585c170..4bd060d788 100644
--- a/open-api/src/testFixtures/java/org/apache/iceberg/rest/RCKUtils.java
+++ b/open-api/src/testFixtures/java/org/apache/iceberg/rest/RCKUtils.java
@@ -104,6 +104,12 @@ class RCKUtils {
         CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1");
     catalogProperties.putIfAbsent(
         CatalogProperties.VIEW_DEFAULT_PREFIX + "key2", "catalog-default-key2");
+    catalogProperties.putIfAbsent(
+        CatalogProperties.VIEW_DEFAULT_PREFIX + "key3", "catalog-default-key3");
+    catalogProperties.putIfAbsent(
+        CatalogProperties.VIEW_OVERRIDE_PREFIX + "key3", "catalog-override-key3");
+    catalogProperties.putIfAbsent(
+        CatalogProperties.VIEW_OVERRIDE_PREFIX + "key4", "catalog-override-key4");
     catalogProperties.putIfAbsent(
         CatalogProperties.TABLE_DEFAULT_PREFIX + "override-key3", "catalog-default-key3");
     catalogProperties.putIfAbsent(