Skip to content

Commit

Permalink
fixup! 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 Nov 14, 2024
1 parent 0f14163 commit 5a19171
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1200,8 +1200,6 @@ private RESTViewBuilder(SessionContext context, TableIdentifier identifier) {
checkViewIdentifierIsValid(identifier);
this.identifier = identifier;
this.context = context;
properties.putAll(
PropertyUtil.propertiesWithPrefix(properties(), CatalogProperties.VIEW_DEFAULT_PREFIX));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@
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
Expand Down Expand Up @@ -81,8 +85,21 @@ protected BaseViewBuilder(TableIdentifier identifier) {
Preconditions.checkArgument(
isValidIdentifier(identifier), "Invalid view identifier: %s", identifier);
this.identifier = identifier;
this.properties.putAll(
PropertyUtil.propertiesWithPrefix(properties(), CatalogProperties.VIEW_DEFAULT_PREFIX));
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<String, String> viewDefaultProperties() {
Map<String, String> viewDefaultProperties =
PropertyUtil.propertiesWithPrefix(properties(), CatalogProperties.VIEW_DEFAULT_PREFIX);
LOG.info(
"View properties set at catalog level through catalog properties: {}",
viewDefaultProperties);
return viewDefaultProperties;
}

@Override
Expand Down
31 changes: 30 additions & 1 deletion core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ 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()).containsEntry("key1", "catalog-default-key1");

assertThat(view.currentVersion())
.isEqualTo(
Expand All @@ -128,6 +127,36 @@ public void basicCreateView() {
assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse();
}

@Test
public void defaultViewProperties() {
TableIdentifier identifier = TableIdentifier.of("ns", "view");

if (requiresNamespaceCreate()) {
catalog().createNamespace(identifier.namespace());
}

assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse();

String location =
Paths.get(tempDir.toUri().toString(), Paths.get("ns", "view").toString()).toString();
View view =
catalog()
.buildView(identifier)
.withSchema(SCHEMA)
.withDefaultNamespace(identifier.namespace())
.withDefaultCatalog(catalog().name())
.withQuery("spark", "select * from ns.tbl")
.withProperty("prop1", "val1")
.withLocation(location)
.create();

assertThat(view).isNotNull();
assertThat(view.properties()).containsEntry("key1", "catalog-default-key1");

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");
Expand Down

0 comments on commit 5a19171

Please sign in to comment.