-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
210 additions
and
2 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
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
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
69 changes: 69 additions & 0 deletions
69
...ore/src/main/java/org/apache/doris/datasource/iceberg/IcebergS3TablesExternalCatalog.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,69 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.datasource.iceberg; | ||
|
||
import org.apache.doris.datasource.CatalogProperty; | ||
import org.apache.doris.datasource.iceberg.s3tables.CustomAwsCredentialsProvider; | ||
import org.apache.doris.datasource.property.PropertyConverter; | ||
import org.apache.doris.datasource.property.constants.S3Properties; | ||
|
||
import com.google.common.collect.Maps; | ||
import org.apache.iceberg.CatalogProperties; | ||
import org.apache.iceberg.aws.AwsClientProperties; | ||
import org.apache.iceberg.aws.s3.S3FileIOProperties; | ||
import software.amazon.s3tables.iceberg.S3TablesCatalog; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class IcebergS3TablesExternalCatalog extends IcebergExternalCatalog { | ||
|
||
public IcebergS3TablesExternalCatalog(long catalogId, String name, String resource, Map<String, String> props, | ||
String comment) { | ||
super(catalogId, name, comment); | ||
props = PropertyConverter.convertToMetaProperties(props); | ||
catalogProperty = new CatalogProperty(resource, props); | ||
} | ||
|
||
@Override | ||
protected void initCatalog() { | ||
icebergCatalogType = ICEBERG_S3_TABLES; | ||
S3TablesCatalog s3TablesCatalog = new S3TablesCatalog(); | ||
Map<String, String> s3TablesCatalogProperties = convertToS3TablesCatalogProperties(); | ||
String warehouse = catalogProperty.getHadoopProperties().get(CatalogProperties.WAREHOUSE_LOCATION); | ||
s3TablesCatalogProperties.put(CatalogProperties.WAREHOUSE_LOCATION, warehouse); | ||
s3TablesCatalog.initialize(getName(), s3TablesCatalogProperties); | ||
catalog = s3TablesCatalog; | ||
} | ||
|
||
private Map<String, String> convertToS3TablesCatalogProperties() { | ||
Map<String, String> props = catalogProperty.getProperties(); | ||
Map<String, String> s3Properties = Maps.newHashMap(); | ||
s3Properties.put("client.credentials-provider", CustomAwsCredentialsProvider.class.getName()); | ||
if (props.containsKey(S3Properties.ACCESS_KEY)) { | ||
s3Properties.put("client.credentials-provider.s3.access-key-id", props.get(S3Properties.ACCESS_KEY)); | ||
} | ||
if (props.containsKey(S3Properties.SECRET_KEY)) { | ||
s3Properties.put("client.credentials-provider.s3.secret-access-key", props.get(S3Properties.SECRET_KEY)); | ||
} | ||
if (props.containsKey(S3Properties.REGION)) { | ||
s3Properties.put("client.region", props.get(S3Properties.REGION)); | ||
} | ||
return s3Properties; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../main/java/org/apache/doris/datasource/iceberg/s3tables/CustomAwsCredentialsProvider.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,43 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.datasource.iceberg.s3tables; | ||
|
||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentials; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
|
||
import java.util.Map; | ||
|
||
public class CustomAwsCredentialsProvider implements AwsCredentialsProvider { | ||
private final String accessKeyId; | ||
private final String secretAccessKey; | ||
|
||
public CustomAwsCredentialsProvider(String accessKeyId, String secretAccessKey) { | ||
this.accessKeyId = accessKeyId; | ||
this.secretAccessKey = secretAccessKey; | ||
} | ||
|
||
@Override | ||
public AwsCredentials resolveCredentials() { | ||
return AwsBasicCredentials.create(accessKeyId, secretAccessKey); | ||
} | ||
|
||
public static CustomAwsCredentialsProvider create(Map<String, String> props) { | ||
return new CustomAwsCredentialsProvider(props.get("s3.access-key-id"), props.get("s3.secret-access-key")); | ||
} | ||
} |
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
70 changes: 70 additions & 0 deletions
70
fe/fe-core/src/test/java/org/apache/doris/datasource/s3tables/S3TablesTest.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,70 @@ | ||
package org.apache.doris.datasource.s3tables; | ||
|
||
import org.apache.doris.datasource.iceberg.s3tables.CustomAwsCredentialsProvider; | ||
|
||
import org.apache.iceberg.FileScanTask; | ||
import org.apache.iceberg.Table; | ||
import org.apache.iceberg.TableScan; | ||
import org.apache.iceberg.catalog.Namespace; | ||
import org.apache.iceberg.catalog.TableIdentifier; | ||
import org.apache.iceberg.io.CloseableIterable; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.s3tables.iceberg.S3TablesCatalog; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class S3TablesTest { | ||
|
||
@Test | ||
public void testS3TablesCatalog() { | ||
S3TablesCatalog s3TablesCatalog = new S3TablesCatalog(); | ||
Map<String, String> s3Properties = new HashMap<>(); | ||
|
||
// ak, sk | ||
String accessKeyId = ""; | ||
String secretKey = ""; | ||
|
||
s3Properties.put("client.region", "us-east-1"); | ||
s3Properties.put("client.credentials-provider", CustomAwsCredentialsProvider.class.getName()); | ||
s3Properties.put("client.credentials-provider.s3.access-key-id", accessKeyId); | ||
s3Properties.put("client.credentials-provider.s3.secret-access-key", secretKey); | ||
|
||
String warehouse = "arn:aws:s3tables:us-east-1:169698404049:bucket/yy-s3-table-bucket"; | ||
s3Properties.put("warehouse", warehouse); | ||
|
||
try { | ||
s3TablesCatalog.initialize("s3tables", s3Properties); | ||
System.out.println("Successfully initialized S3 Tables catalog!"); | ||
|
||
try { | ||
// 1. list namespaces | ||
List<Namespace> namespaces = s3TablesCatalog.listNamespaces(); | ||
System.out.println("Successfully listed namespaces:"); | ||
for (Namespace namespace : namespaces) { | ||
System.out.println(namespace); | ||
// 2. list tables | ||
List<TableIdentifier> tblIdentifiers = s3TablesCatalog.listTables(namespace); | ||
for (TableIdentifier tblId : tblIdentifiers) { | ||
// 3. load table and list files | ||
System.out.println(tblId); | ||
Table tbl = s3TablesCatalog.loadTable(tblId); | ||
System.out.println(tbl.schema()); | ||
TableScan scan = tbl.newScan(); | ||
CloseableIterable<FileScanTask> fileScanTasks = scan.planFiles(); | ||
for (FileScanTask task : fileScanTasks) { | ||
System.out.println(task.file()); | ||
} | ||
} | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
System.out.println("Note: Could not list namespaces - " + e.getMessage()); | ||
} | ||
} catch (Exception e) { | ||
System.err.println("Error connecting to S3 Tables: " + e.getMessage()); | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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