forked from nbauernfeind/deephaven-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add generic Iceberg catalog adapter creation to Java / Python (d…
…eephaven#5754) ### Java, connecting to a RESTCatalog using MinIO ``` import io.deephaven.iceberg.util.*; properties = new HashMap<>(); properties.put("type", "rest"); properties.put("uri", "http://rest:8181"); properties.put("client.region", "us-east-1"); properties.put("s3.access-key-id", "admin"); properties.put("s3.secret-access-key", "password"); properties.put("s3.endpoint", "http://minio:9000"); adapter = IcebergTools.createAdapter("generic-adapter", properties); ``` ### Python, connecting to a RESTCatalog using MinIO ``` from deephaven.experimental import iceberg adapter = iceberg.adapter(name="generic-adapter", properties={ "type" : "rest", "uri" : "http://rest:8181", "client.region" : "us-east-1", "s3.access-key-id" : "admin", "s3.secret-access-key" : "password", "s3.endpoint" : "http://minio:9000" }); ``` ### Java, connecting to AWS Glue NOTE: credentials set in local environment ``` import io.deephaven.iceberg.util.*; properties = new HashMap<>(); properties.put("type", "glue"); properties.put("uri", "s3://lab-warehouse/sales"); adapter = IcebergTools.createAdapter("generic-adapter", properties); ``` ### Python, connecting to AWS Glue NOTE: credentials set in local environment ``` from deephaven.experimental import iceberg adapter = iceberg.adapter(name="generic-adapter", properties={ "type" : "glue", "uri" : "s3://lab-warehouse/sales", "warehouse" : "s3://lab-warehouse/sales", }); ```
- Loading branch information
Showing
18 changed files
with
543 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ions/iceberg/s3/src/main/java/io/deephaven/iceberg/util/S3InstructionsProviderPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending | ||
// | ||
package io.deephaven.iceberg.util; | ||
|
||
import com.google.auto.service.AutoService; | ||
import io.deephaven.extensions.s3.Credentials; | ||
import io.deephaven.extensions.s3.S3Instructions; | ||
import io.deephaven.iceberg.internal.DataInstructionsProviderPlugin; | ||
import org.apache.iceberg.aws.AwsClientProperties; | ||
import org.apache.iceberg.aws.s3.S3FileIOProperties; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
/** | ||
* {@link io.deephaven.iceberg.internal.DataInstructionsProviderPlugin} implementation used for reading files from S3. | ||
*/ | ||
@AutoService(io.deephaven.iceberg.internal.DataInstructionsProviderPlugin.class) | ||
@SuppressWarnings("unused") | ||
public final class S3InstructionsProviderPlugin implements DataInstructionsProviderPlugin { | ||
@Override | ||
public Object createInstructions(@NotNull final URI uri, @NotNull final Map<String, String> properties) { | ||
// If the URI scheme is "s3","s3a","s3n" or if the properties contain one of these specific keys, we can | ||
// create a useful S3Instructions object. | ||
if (uri.getScheme().equals("s3") | ||
|| uri.getScheme().equals("s3a") | ||
|| uri.getScheme().equals("s3n") | ||
|| properties.containsKey(AwsClientProperties.CLIENT_REGION) | ||
|| properties.containsKey(S3FileIOProperties.ACCESS_KEY_ID) | ||
|| properties.containsKey(S3FileIOProperties.SECRET_ACCESS_KEY) | ||
|| properties.containsKey(S3FileIOProperties.ENDPOINT)) { | ||
|
||
final S3Instructions.Builder builder = S3Instructions.builder(); | ||
if (properties.containsKey(AwsClientProperties.CLIENT_REGION)) { | ||
builder.regionName(properties.get(AwsClientProperties.CLIENT_REGION)); | ||
} | ||
if (properties.containsKey(S3FileIOProperties.ENDPOINT)) { | ||
builder.endpointOverride(properties.get(S3FileIOProperties.ENDPOINT)); | ||
} | ||
if (properties.containsKey(S3FileIOProperties.ACCESS_KEY_ID) | ||
&& properties.containsKey(S3FileIOProperties.SECRET_ACCESS_KEY)) { | ||
builder.credentials( | ||
Credentials.basic(properties.get(S3FileIOProperties.ACCESS_KEY_ID), | ||
properties.get(S3FileIOProperties.SECRET_ACCESS_KEY))); | ||
} | ||
return builder.build(); | ||
} | ||
|
||
// We have no useful properties for creating an S3Instructions object. | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.