Skip to content

Commit

Permalink
Core: Set missing table-default property in RESTSessionCatalog
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Dec 31, 2024
1 parent e3f50e5 commit 05649d0
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,21 @@ private Builder(TableIdentifier ident, Schema schema, SessionContext context) {
this.ident = ident;
this.schema = schema;
this.context = context;
propertiesBuilder.putAll(tableDefaultProperties());
}

/**
* Get default table properties set at Catalog level through catalog properties.
*
* @return default table properties specified in catalog properties
*/
private Map<String, String> tableDefaultProperties() {
Map<String, String> tableDefaultProperties =
PropertyUtil.propertiesWithPrefix(properties(), CatalogProperties.TABLE_DEFAULT_PREFIX);
LOG.info(
"Table properties set at catalog level through catalog properties: {}",
tableDefaultProperties);
return tableDefaultProperties;
}

@Override
Expand Down Expand Up @@ -827,7 +842,7 @@ public Table create() {
.withPartitionSpec(spec)
.withWriteOrder(writeOrder)
.withLocation(location)
.setProperties(propertiesBuilder.build())
.setProperties(propertiesBuilder.buildKeepingLast())
.build();

LoadTableResponse response =
Expand Down
24 changes: 24 additions & 0 deletions core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,30 @@ public void testCompleteCreateTable() {
.isEqualTo(UUID.fromString(((BaseTable) table).operations().current().uuid()));
}

@Test
public void testDefaultTableProperties() {
C catalog = catalog();

TableIdentifier ident = TableIdentifier.of("ns", "table");

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

assertThat(catalog.tableExists(ident)).as("Table should not exist").isFalse();

Table table =
catalog()
.buildTable(ident, SCHEMA)
.withProperty("default-key2", "catalog-overridden-key2")
.create();
assertThat(table.properties())
.containsEntry("default-key1", "catalog-default-key1")
.containsEntry("default-key2", "catalog-overridden-key2");

assertThat(catalog.dropTable(ident)).as("Should successfully drop table").isTrue();
}

@Test
public void testLoadTable() {
C catalog = catalog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.iceberg.inmemory;

import java.util.Map;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.catalog.CatalogTests;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -28,7 +29,15 @@ public class TestInMemoryCatalog extends CatalogTests<InMemoryCatalog> {

@BeforeEach
public void before() {
this.catalog = initCatalog("in-memory-catalog", ImmutableMap.of());
this.catalog =
initCatalog(
"in-memory-catalog",
ImmutableMap.<String, String>builder()
.put(
CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key1", "catalog-default-key1")
.put(
CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key2", "catalog-default-key2")
.buildOrThrow());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ protected JdbcCatalog initCatalog(String catalogName, Map<String, String> additi
properties.put(JdbcCatalog.PROPERTY_PREFIX + "password", "password");
warehouseLocation = this.tableDir.toAbsolutePath().toString();
properties.put(CatalogProperties.WAREHOUSE_LOCATION, warehouseLocation);
properties.put(CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key1", "catalog-default-key1");
properties.put(CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key2", "catalog-default-key2");
properties.put("type", "jdbc");
properties.putAll(additionalProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ protected JdbcCatalog initCatalog(String catalogName, Map<String, String> additi
properties.put(JdbcCatalog.PROPERTY_PREFIX + "username", "user");
properties.put(JdbcCatalog.PROPERTY_PREFIX + "password", "password");
properties.put(CatalogProperties.WAREHOUSE_LOCATION, tableDir.toAbsolutePath().toString());
properties.put(CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key1", "catalog-default-key1");
properties.put(CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key2", "catalog-default-key2");
properties.put(JdbcUtil.SCHEMA_VERSION_PROPERTY, JdbcUtil.SchemaVersion.V1.name());
properties.putAll(additionalProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ protected RESTCatalog initCatalog(String catalogName, Map<String, String> additi
httpServer.getURI().toString(),
CatalogProperties.FILE_IO_IMPL,
"org.apache.iceberg.inmemory.InMemoryFileIO",
CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key1",
"catalog-default-key1",
CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key2",
"catalog-default-key2",
"credential",
"catalog:12345");
catalog.initialize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ protected HiveCatalog initCatalog(String catalogName, Map<String, String> additi
Map<String, String> properties =
ImmutableMap.of(
CatalogProperties.CLIENT_POOL_CACHE_EVICTION_INTERVAL_MS,
String.valueOf(TimeUnit.SECONDS.toMillis(10)));
String.valueOf(TimeUnit.SECONDS.toMillis(10)),
CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key1",
"catalog-default-key1",
CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key2",
"catalog-default-key2");

return (HiveCatalog)
CatalogUtil.loadCatalog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ protected NessieCatalog initCatalog(
CatalogProperties.URI,
uri,
CatalogProperties.WAREHOUSE_LOCATION,
temp.toUri().toString());
temp.toUri().toString(),
CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key1",
"catalog-default-key1",
CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key2",
"catalog-default-key2");

return (NessieCatalog)
CatalogUtil.buildIcebergCatalog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ static RESTCatalog initCatalogClient(Map<String, String> properties) {
catalogProperties.putIfAbsent(
CatalogProperties.URI, String.format("http://localhost:%s/", port));
catalogProperties.putIfAbsent(CatalogProperties.WAREHOUSE_LOCATION, "rck_warehouse");
catalogProperties.putIfAbsent(
CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key1", "catalog-default-key1");
catalogProperties.putIfAbsent(
CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key2", "catalog-default-key2");

RESTCatalog catalog = new RESTCatalog();
catalog.setConf(new Configuration());
Expand Down

0 comments on commit 05649d0

Please sign in to comment.