Skip to content

Commit

Permalink
Core: Add support for view-default property in catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Sep 2, 2024
1 parent ae820ff commit a130aaa
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private 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";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.iceberg.rest;

import static org.apache.iceberg.util.PropertyUtil.propertiesWithPrefix;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalListener;
Expand Down Expand Up @@ -1200,6 +1202,7 @@ private RESTViewBuilder(SessionContext context, TableIdentifier identifier) {
checkViewIdentifierIsValid(identifier);
this.identifier = identifier;
this.context = context;
properties.putAll(propertiesWithPrefix(properties(), CatalogProperties.VIEW_DEFAULT_PREFIX));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
*/
package org.apache.iceberg.view;

import static org.apache.iceberg.util.PropertyUtil.propertiesWithPrefix;

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;
Expand Down Expand Up @@ -79,6 +82,8 @@ protected BaseViewBuilder(TableIdentifier identifier) {
Preconditions.checkArgument(
isValidIdentifier(identifier), "Invalid view identifier: %s", identifier);
this.identifier = identifier;
this.properties.putAll(
propertiesWithPrefix(properties(), CatalogProperties.VIEW_DEFAULT_PREFIX));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +30,11 @@ public class TestInMemoryViewCatalog extends ViewCatalogTests<InMemoryCatalog> {
@BeforeEach
public void before() {
this.catalog = new InMemoryCatalog();
this.catalog.initialize("in-memory-catalog", ImmutableMap.of());
this.catalog.initialize(
"in-memory-catalog",
ImmutableMap.<String, String>builder()
.put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1")
.build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void before() {
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");

catalog = new JdbcCatalog();
catalog.setConf(new Configuration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public void createCatalog() throws Exception {
this.backendCatalog = new InMemoryCatalog();
this.backendCatalog.initialize(
"in-memory",
ImmutableMap.of(CatalogProperties.WAREHOUSE_LOCATION, warehouse.getAbsolutePath()));
ImmutableMap.<String, String>builder()
.put(CatalogProperties.WAREHOUSE_LOCATION, warehouse.getAbsolutePath())
.put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1")
.build());

RESTCatalogAdapter adaptor =
new RESTCatalogAdapter(backendCatalog) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.apache.iceberg.types.Types.NestedField.required;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -107,6 +108,7 @@ public void basicCreateView() {
assertThat(view.currentVersion().operation()).isEqualTo("create");
assertThat(view.schemas()).hasSize(1).containsKey(0);
assertThat(view.versions()).hasSize(1).containsExactly(view.currentVersion());
assertThat(view.properties()).contains(entry("key1", "catalog-default-key1"));

assertThat(view.currentVersion())
.isEqualTo(
Expand Down Expand Up @@ -871,6 +873,7 @@ public void createOrReplaceView(boolean useCreateOrReplace) {
assertThat(replacedView.name()).isEqualTo(ViewUtil.fullViewName(catalog().name(), identifier));
assertThat(((BaseView) replacedView).operations().current().metadataFileLocation()).isNotNull();
assertThat(replacedView.properties())
.containsEntry("key1", "catalog-default-key1")
.containsEntry("prop1", "val1")
.containsEntry("prop2", "val2")
.containsEntry("replacedProp1", "val1")
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/spark-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Both catalogs are configured using properties nested under the catalog name. Com
| spark.sql.catalog._catalog-name_.cache.expiration-interval-ms | `30000` (30 seconds) | Duration after which cached catalog entries are expired; Only effective if `cache-enabled` is `true`. `-1` disables cache expiration and `0` disables caching entirely, irrespective of `cache-enabled`. Default is `30000` (30 seconds) |
| 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 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 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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ private NessieCatalog initNessieCatalog(String ref) {
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");
newCatalog.initialize("nessie", options);
return newCatalog;
}
Expand Down

0 comments on commit a130aaa

Please sign in to comment.