Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Set missing table-default property in RESTSessionCatalog #11646

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 26 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 @@ -653,6 +653,32 @@ 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")
.withProperty("prop1", "val1")
.create();
assertThat(table.properties())
.containsEntry("default-key1", "catalog-default-key1")
.containsEntry("default-key2", "catalog-overridden-key2")
.containsEntry("prop1", "val1");

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");
catalogProperties.putIfAbsent(
CatalogProperties.VIEW_DEFAULT_PREFIX + "key1", "catalog-default-key1");
catalogProperties.putIfAbsent(
Expand Down