Skip to content

Commit

Permalink
Add support for Iceberg catalog warehouse property in REST
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcweeks authored and ebyhr committed Feb 21, 2023
1 parent c790560 commit fba39d6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/src/main/sphinx/connector/iceberg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ Property Name Description
``iceberg.rest-catalog.uri`` REST server API endpoint URI (required).
Example: ``http://iceberg-with-rest:8181``

``iceberg.rest-catalog.warehouse`` Warehouse identifier/location for the catalog (optional).
Example: ``s3://my_bucket/warehouse_location``

``iceberg.rest-catalog.security`` The type of security to use (default: ``NONE``). ``OAUTH2``
requires either a ``token`` or ``credential``.
Example: ``OAUTH2``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.validation.constraints.NotNull;

import java.net.URI;
import java.util.Optional;

public class IcebergRestCatalogConfig
{
Expand All @@ -35,6 +36,7 @@ public enum SessionType
}

private URI restUri;
private Optional<String> warehouse = Optional.empty();
private Security security = Security.NONE;
private SessionType sessionType = SessionType.NONE;

Expand Down Expand Up @@ -81,4 +83,17 @@ public IcebergRestCatalogConfig setSessionType(SessionType sessionType)
this.sessionType = sessionType;
return this;
}

public Optional<String> getWarehouse()
{
return warehouse;
}

@Config("iceberg.rest-catalog.warehouse")
@ConfigDescription("The warehouse location/identifier to use with the REST catalog server")
public IcebergRestCatalogConfig setWarehouse(String warehouse)
{
this.warehouse = Optional.ofNullable(warehouse);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.inject.Inject;

import java.net.URI;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

Expand All @@ -38,6 +39,7 @@ public class TrinoIcebergRestCatalogFactory
private final CatalogName catalogName;
private final String trinoVersion;
private final URI serverUri;
private final Optional<String> warehouse;
private final SessionType sessionType;
private final SecurityProperties securityProperties;
private final boolean uniqueTableLocation;
Expand All @@ -57,6 +59,7 @@ public TrinoIcebergRestCatalogFactory(
this.trinoVersion = requireNonNull(nodeVersion, "nodeVersion is null").toString();
requireNonNull(restConfig, "restConfig is null");
this.serverUri = restConfig.getBaseUri();
this.warehouse = restConfig.getWarehouse();
this.sessionType = restConfig.getSessionType();
this.securityProperties = requireNonNull(securityProperties, "securityProperties is null");
requireNonNull(icebergConfig, "icebergConfig is null");
Expand All @@ -71,6 +74,7 @@ public synchronized TrinoCatalog create(ConnectorIdentity identity)
if (icebergCatalog == null) {
ImmutableMap.Builder<String, String> properties = ImmutableMap.builder();
properties.put(CatalogProperties.URI, serverUri.toString());
warehouse.ifPresent(location -> properties.put(CatalogProperties.WAREHOUSE_LOCATION, location));
properties.put("trino-version", trinoVersion);
properties.putAll(securityProperties.get());
RESTSessionCatalog icebergCatalogInstance = new RESTSessionCatalog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void testDefaults()
{
assertRecordedDefaults(recordDefaults(IcebergRestCatalogConfig.class)
.setBaseUri(null)
.setWarehouse(null)
.setSessionType(IcebergRestCatalogConfig.SessionType.NONE)
.setSecurity(IcebergRestCatalogConfig.Security.NONE));
}
Expand All @@ -38,12 +39,14 @@ public void testExplicitPropertyMappings()
{
Map<String, String> properties = ImmutableMap.<String, String>builder()
.put("iceberg.rest-catalog.uri", "http://localhost:1234")
.put("iceberg.rest-catalog.warehouse", "test_warehouse_identifier")
.put("iceberg.rest-catalog.security", "OAUTH2")
.put("iceberg.rest-catalog.session", "USER")
.buildOrThrow();

IcebergRestCatalogConfig expected = new IcebergRestCatalogConfig()
.setBaseUri("http://localhost:1234")
.setWarehouse("test_warehouse_identifier")
.setSessionType(IcebergRestCatalogConfig.SessionType.USER)
.setSecurity(IcebergRestCatalogConfig.Security.OAUTH2);

Expand Down

0 comments on commit fba39d6

Please sign in to comment.