-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[590] Add Iceberg Glue Catalog Sync implementation
- Loading branch information
1 parent
6e09f5d
commit d6ae25a
Showing
21 changed files
with
2,576 additions
and
1 deletion.
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
57 changes: 57 additions & 0 deletions
57
xtable-core/src/main/java/org/apache/xtable/catalog/TableFormatUtils.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,57 @@ | ||
/* | ||
* 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.xtable.catalog; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.iceberg.TableProperties; | ||
|
||
import org.apache.xtable.exception.NotSupportedException; | ||
import org.apache.xtable.model.storage.TableFormat; | ||
|
||
public class TableFormatUtils { | ||
|
||
public static String getTableDataLocation( | ||
String tableFormat, String tableLocation, Map<String, String> properties) { | ||
switch (tableFormat) { | ||
case TableFormat.ICEBERG: | ||
return getIcebergDataLocation(tableLocation, properties); | ||
case TableFormat.HUDI: | ||
return tableLocation; | ||
default: | ||
throw new NotSupportedException("Unsupported table format: " + tableFormat); | ||
} | ||
} | ||
|
||
/** Get iceberg table data files location */ | ||
private static String getIcebergDataLocation( | ||
String tableLocation, Map<String, String> properties) { | ||
String dataLocation = properties.get(TableProperties.WRITE_DATA_LOCATION); | ||
if (dataLocation == null) { | ||
dataLocation = properties.get(TableProperties.WRITE_FOLDER_STORAGE_LOCATION); | ||
if (dataLocation == null) { | ||
dataLocation = properties.get(TableProperties.OBJECT_STORE_PATH); | ||
if (dataLocation == null) { | ||
dataLocation = String.format("%s/data", tableLocation); | ||
} | ||
} | ||
} | ||
return dataLocation; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
xtable-core/src/main/java/org/apache/xtable/catalog/glue/DefaultGlueClientFactory.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,75 @@ | ||
/* | ||
* 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.xtable.catalog.glue; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import org.apache.xtable.reflection.ReflectionUtils; | ||
|
||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.glue.GlueClient; | ||
import software.amazon.awssdk.services.glue.GlueClientBuilder; | ||
|
||
/** | ||
* Factory class for creating and configuring instances of {@link GlueClient} with settings provided | ||
* by {@link GlueCatalogConfig}. | ||
* | ||
* <p>This factory is responsible for setting the AWS region and credentials for the Glue client. If | ||
* a custom credentials provider class is specified in {@code GlueCatalogConfig}, it will use | ||
* reflection to instantiate the provider; otherwise, it defaults to the standard AWS credentials | ||
* provider. | ||
*/ | ||
public class DefaultGlueClientFactory extends GlueClientFactory { | ||
|
||
public DefaultGlueClientFactory(GlueCatalogConfig glueConfig) { | ||
super(glueConfig); | ||
} | ||
|
||
public GlueClient getGlueClient() { | ||
GlueClientBuilder builder = GlueClient.builder(); | ||
if (!StringUtils.isEmpty(glueConfig.getRegion())) { | ||
builder.region(Region.of(glueConfig.getRegion())); | ||
} | ||
|
||
AwsCredentialsProvider credentialsProvider; | ||
if (!StringUtils.isEmpty(glueConfig.getClientCredentialsProviderClass())) { | ||
String className = glueConfig.getClientCredentialsProviderClass(); | ||
try { | ||
credentialsProvider = | ||
ReflectionUtils.createInstanceOfClassFromStaticMethod( | ||
className, | ||
"create", | ||
new Class<?>[] {Map.class}, | ||
new Object[] {glueConfig.getClientCredentialConfigs()}); | ||
} catch (Exception e) { | ||
credentialsProvider = | ||
ReflectionUtils.createInstanceOfClassFromStaticMethod(className, "create"); | ||
} | ||
} else { | ||
credentialsProvider = DefaultCredentialsProvider.create(); | ||
} | ||
|
||
builder.credentialsProvider(credentialsProvider); | ||
return builder.build(); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
xtable-core/src/main/java/org/apache/xtable/catalog/glue/GlueCatalogConfig.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,92 @@ | ||
/* | ||
* 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.xtable.catalog.glue; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
/** Configurations for setting up Glue client and running Glue catalog operations */ | ||
@Getter | ||
@EqualsAndHashCode | ||
@ToString | ||
public class GlueCatalogConfig { | ||
|
||
private static final ObjectMapper OBJECT_MAPPER = | ||
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
|
||
public static final String CLIENT_CREDENTIAL_PROVIDER_PREFIX = | ||
"externalCatalog.glue.credentials.provider."; | ||
|
||
@JsonProperty("externalCatalog.glue.catalogId") | ||
private String catalogId; | ||
|
||
@JsonProperty("externalCatalog.glue.region") | ||
private String region; | ||
|
||
@JsonProperty("externalCatalog.glue.credentialsProviderClass") | ||
private String clientCredentialsProviderClass; | ||
|
||
/** | ||
* In case a credentialsProviderClass is configured and require additional properties for | ||
* instantiation, those properties should start with {@link #CLIENT_CREDENTIAL_PROVIDER_PREFIX}. | ||
* | ||
* <p>For ex: if credentialsProviderClass requires `accessKey` and `secretAccessKey`, they should | ||
* be configured using below keys: | ||
* <li>externalCatalog.glue.credentials.provider.accessKey | ||
* <li>externalCatalog.glue.credentials.provider.secretAccessKey | ||
*/ | ||
@Setter private Map<String, String> clientCredentialConfigs; | ||
|
||
/** Creates GlueCatalogConfig from given key-value map */ | ||
public static GlueCatalogConfig of(Map<String, String> properties) { | ||
try { | ||
GlueCatalogConfig glueCatalogConfig = | ||
OBJECT_MAPPER.readValue( | ||
OBJECT_MAPPER.writeValueAsString(properties), GlueCatalogConfig.class); | ||
Map<String, String> clientCredentialProperties = | ||
propertiesWithPrefix(properties, CLIENT_CREDENTIAL_PROVIDER_PREFIX); | ||
glueCatalogConfig.setClientCredentialConfigs(clientCredentialProperties); | ||
return glueCatalogConfig; | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static Map<String, String> propertiesWithPrefix( | ||
Map<String, String> properties, String prefix) { | ||
if (properties == null || properties.isEmpty()) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
return properties.entrySet().stream() | ||
.filter(e -> e.getKey().startsWith(prefix)) | ||
.collect(Collectors.toMap(e -> e.getKey().replaceFirst(prefix, ""), Map.Entry::getValue)); | ||
} | ||
} |
Oops, something went wrong.