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 Nov 24, 2024
1 parent 08cb705 commit eb8b60b
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,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 @@ -797,7 +812,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 @@ -637,6 +637,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 @@ -18,8 +18,10 @@
*/
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.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.junit.jupiter.api.BeforeEach;

public class TestInMemoryCatalog extends CatalogTests<InMemoryCatalog> {
Expand All @@ -28,7 +30,10 @@ public class TestInMemoryCatalog extends CatalogTests<InMemoryCatalog> {
@BeforeEach
public void before() {
this.catalog = new InMemoryCatalog();
this.catalog.initialize("in-memory-catalog", ImmutableMap.of());
Map<String, String> properties = Maps.newHashMap();
properties.put(CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key1", "catalog-default-key1");
properties.put(CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key2", "catalog-default-key2");
this.catalog.initialize("in-memory-catalog", properties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ private JdbcCatalog initCatalog(String catalogName, Map<String, String> props) {
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(props);

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

catalog = new JdbcCatalog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public <T extends RESTResponse> T execute(
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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ public void before() throws TException {
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.TABLE_DEFAULT_PREFIX + "default-key1",
"catalog-default-key1",
CatalogProperties.TABLE_DEFAULT_PREFIX + "default-key2",
"catalog-default-key2"),
HIVE_METASTORE_EXTENSION.hiveConf());
String dbPath = HIVE_METASTORE_EXTENSION.metastore().getDatabasePath(DB_NAME);
Database db = new Database(DB_NAME, "description", dbPath, Maps.newHashMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ private NessieCatalog initNessieCatalog(String ref) {
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("nessie", options, hadoopConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ static RESTCatalog initCatalogClient() {
CatalogProperties.URI,
String.format("http://localhost:%s/", RESTCatalogServer.REST_PORT_DEFAULT));
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");
catalogProperties.putIfAbsent(
CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1");
catalogProperties.putIfAbsent(
Expand Down

0 comments on commit eb8b60b

Please sign in to comment.