diff --git a/core/src/main/java/org/apache/iceberg/CatalogProperties.java b/core/src/main/java/org/apache/iceberg/CatalogProperties.java index 339c59b45d..25d331c832 100644 --- a/core/src/main/java/org/apache/iceberg/CatalogProperties.java +++ b/core/src/main/java/org/apache/iceberg/CatalogProperties.java @@ -29,6 +29,7 @@ public class CatalogProperties { public static final String WAREHOUSE_LOCATION = "warehouse"; 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 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 903e5dc518..0a78210425 100644 --- a/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java +++ b/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java @@ -1318,6 +1318,21 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog checkViewIdentifierIsValid(identifier); this.identifier = identifier; this.context = context; + this.properties.putAll(viewDefaultProperties()); + } + + /** + * Get default view properties set at Catalog level through catalog properties. + * + * @return default view properties specified in catalog properties + */ + private Map viewDefaultProperties() { + Map viewDefaultProperties = + PropertyUtil.propertiesWithPrefix(properties(), CatalogProperties.VIEW_DEFAULT_PREFIX); + LOG.info( + "View properties set at catalog level through catalog properties: {}", + viewDefaultProperties); + return viewDefaultProperties; } @Override 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 6e2d6ff5e8..2f747c5455 100644 --- a/core/src/main/java/org/apache/iceberg/view/BaseMetastoreViewCatalog.java +++ b/core/src/main/java/org/apache/iceberg/view/BaseMetastoreViewCatalog.java @@ -21,6 +21,7 @@ package org.apache.iceberg.view; import java.util.List; import java.util.Map; import org.apache.iceberg.BaseMetastoreCatalog; +import org.apache.iceberg.CatalogProperties; import org.apache.iceberg.EnvironmentContext; import org.apache.iceberg.Schema; import org.apache.iceberg.Transaction; @@ -33,8 +34,13 @@ import org.apache.iceberg.exceptions.NoSuchViewException; import org.apache.iceberg.relocated.com.google.common.base.Preconditions; import org.apache.iceberg.relocated.com.google.common.collect.Lists; import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.util.PropertyUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public abstract class BaseMetastoreViewCatalog extends BaseMetastoreCatalog implements ViewCatalog { + private static final Logger LOG = LoggerFactory.getLogger(BaseMetastoreViewCatalog.class); + protected abstract ViewOperations newViewOps(TableIdentifier identifier); @Override @@ -79,6 +85,21 @@ public abstract class BaseMetastoreViewCatalog extends BaseMetastoreCatalog impl Preconditions.checkArgument( isValidIdentifier(identifier), "Invalid view identifier: %s", identifier); this.identifier = identifier; + this.properties.putAll(viewDefaultProperties()); + } + + /** + * Get default view properties set at Catalog level through catalog properties. + * + * @return default view properties specified in catalog properties + */ + private Map viewDefaultProperties() { + Map viewDefaultProperties = + PropertyUtil.propertiesWithPrefix(properties(), CatalogProperties.VIEW_DEFAULT_PREFIX); + LOG.info( + "View properties set at catalog level through catalog properties: {}", + viewDefaultProperties); + return viewDefaultProperties; } @Override 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 76731f58a6..65e4e26315 100644 --- a/core/src/test/java/org/apache/iceberg/inmemory/TestInMemoryViewCatalog.java +++ b/core/src/test/java/org/apache/iceberg/inmemory/TestInMemoryViewCatalog.java @@ -18,6 +18,7 @@ */ package org.apache.iceberg.inmemory; +import org.apache.iceberg.CatalogProperties; import org.apache.iceberg.catalog.Catalog; import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; import org.apache.iceberg.view.ViewCatalogTests; @@ -29,7 +30,12 @@ public class TestInMemoryViewCatalog extends ViewCatalogTests { @BeforeEach public void before() { this.catalog = new InMemoryCatalog(); - this.catalog.initialize("in-memory-catalog", ImmutableMap.of()); + this.catalog.initialize( + "in-memory-catalog", + ImmutableMap.builder() + .put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1") + .put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key2", "catalog-default-key2") + .build()); } @Override 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 a66532d90f..9b8ca3a906 100644 --- a/core/src/test/java/org/apache/iceberg/jdbc/TestJdbcViewCatalog.java +++ b/core/src/test/java/org/apache/iceberg/jdbc/TestJdbcViewCatalog.java @@ -57,6 +57,8 @@ public class TestJdbcViewCatalog extends ViewCatalogTests { properties.put(JdbcCatalog.PROPERTY_PREFIX + "password", "password"); properties.put(CatalogProperties.WAREHOUSE_LOCATION, tableDir.toAbsolutePath().toString()); 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"); 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 40a206896b..cfc22ca767 100644 --- a/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java +++ b/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java @@ -72,7 +72,11 @@ public class TestRESTViewCatalog extends ViewCatalogTests { this.backendCatalog = new InMemoryCatalog(); this.backendCatalog.initialize( "in-memory", - ImmutableMap.of(CatalogProperties.WAREHOUSE_LOCATION, warehouse.getAbsolutePath())); + ImmutableMap.builder() + .put(CatalogProperties.WAREHOUSE_LOCATION, warehouse.getAbsolutePath()) + .put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1") + .put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key2", "catalog-default-key2") + .build()); RESTCatalogAdapter adaptor = new RESTCatalogAdapter(backendCatalog) { 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 3d7d64ddb7..ee9d8cdfd2 100644 --- a/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalogWithAssumedViewSupport.java +++ b/core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalogWithAssumedViewSupport.java @@ -90,6 +90,10 @@ public class TestRESTViewCatalogWithAssumedViewSupport extends TestRESTViewCatal "catalog:12345", // assume that the server supports view endpoints RESTSessionCatalog.VIEW_ENDPOINTS_SUPPORTED, - "true")); + "true", + CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", + "catalog-default-key1", + CatalogProperties.VIEW_DEFAULT_PREFIX + "key2", + "catalog-default-key2")); } } 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 b3765bb1ea..d365defb29 100644 --- a/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java +++ b/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java @@ -127,6 +127,37 @@ public abstract class ViewCatalogTests { CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE, ImmutableMap.of( CatalogProperties.CLIENT_POOL_CACHE_EVICTION_INTERVAL_MS, - String.valueOf(TimeUnit.SECONDS.toMillis(10))), + String.valueOf(TimeUnit.SECONDS.toMillis(10)), + CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", + "catalog-default-key1", + CatalogProperties.VIEW_DEFAULT_PREFIX + "key2", + "catalog-default-key2"), 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 cb2c61e9dc..94a1c1ec34 100644 --- a/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieViewCatalog.java +++ b/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieViewCatalog.java @@ -128,7 +128,11 @@ public class TestNessieViewCatalog extends ViewCatalogTests { CatalogProperties.WAREHOUSE_LOCATION, temp.toUri().toString(), "client-api-version", - apiVersion == NessieApiVersion.V2 ? "2" : "1"); + apiVersion == NessieApiVersion.V2 ? "2" : "1", + CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", + "catalog-default-key1", + CatalogProperties.VIEW_DEFAULT_PREFIX + "key2", + "catalog-default-key2"); 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 adeba47093..23e53da217 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 @@ -96,6 +96,10 @@ class RCKUtils { catalogProperties.putIfAbsent( CatalogProperties.URI, String.format("http://localhost:%s/", port)); catalogProperties.putIfAbsent(CatalogProperties.WAREHOUSE_LOCATION, "rck_warehouse"); + catalogProperties.putIfAbsent( + CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1"); + catalogProperties.putIfAbsent( + CatalogProperties.VIEW_DEFAULT_PREFIX + "key2", "catalog-default-key2"); RESTCatalog catalog = new RESTCatalog(); catalog.setConf(new Configuration());