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 16, 2024
1 parent 8df92de commit 4afe084
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 7 deletions.
15 changes: 15 additions & 0 deletions core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,21 @@ private RESTViewBuilder(SessionContext context, TableIdentifier identifier) {
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<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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void before() {
"in-memory-catalog",
ImmutableMap.<String, String>builder()
.put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1")
.put(CatalogProperties.VIEW_DEFAULT_PREFIX + "key2", "catalog-default-key2")
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void before() {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void createCatalog() throws Exception {
ImmutableMap.<String, String>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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public <T extends RESTResponse> T handleRequest(
"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"));
}
}
10 changes: 5 additions & 5 deletions core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,22 @@ public void defaultViewProperties() {

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("key2", "catalog-overridden-key2")
.withProperty("prop1", "val1")
.withLocation(location)
.create();

assertThat(view).isNotNull();
assertThat(view.properties()).containsEntry("key1", "catalog-default-key1");
assertThat(view.properties())
.containsEntry("key1", "catalog-default-key1")
.containsEntry("key2", "catalog-overridden-key2")
.containsEntry("prop1", "val1");

assertThat(catalog().dropView(identifier)).isTrue();
assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse();
Expand Down Expand Up @@ -901,7 +902,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ private NessieCatalog initNessieCatalog(String ref) {
"client-api-version",
apiVersion == NessieApiVersion.V2 ? "2" : "1",
CatalogProperties.VIEW_DEFAULT_PREFIX + "key1",
"catalog-default-key1");
"catalog-default-key1",
CatalogProperties.VIEW_DEFAULT_PREFIX + "key2",
"catalog-default-key2");
newCatalog.initialize("nessie", options);
return newCatalog;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ static RESTCatalog initCatalogClient() {
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());
Expand Down

0 comments on commit 4afe084

Please sign in to comment.