the-other-tim-brown commented on code in PR #599:
URL: https://github.com/apache/incubator-xtable/pull/599#discussion_r1899922000


##########
pom.xml:
##########
@@ -372,9 +373,9 @@
                 <scope>runtime</scope>
             </dependency>
             <dependency>
-                <groupId>com.amazonaws</groupId>
-                <artifactId>aws-java-sdk-bundle</artifactId>
-                <version>1.12.328</version>
+                <groupId>software.amazon.awssdk</groupId>

Review Comment:
   We should define the `glue` artifact and version here in the 
dependencyManagement section as well



##########
xtable-core/src/main/java/org/apache/xtable/catalog/glue/GlueCatalogConfig.java:
##########
@@ -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(

Review Comment:
   Can you just use `convertValue` for this instead of writing out to an 
intermediate string?



##########
xtable-core/src/main/java/org/apache/xtable/catalog/CatalogUtils.java:
##########
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.xtable.model.catalog.CatalogTableIdentifier;
+import org.apache.xtable.model.catalog.HierarchicalTableIdentifier;
+
+public class CatalogUtils {
+
+  public static HierarchicalTableIdentifier castToHierarchicalTableIdentifier(

Review Comment:
   Let's add a basic unit test for this?



##########
xtable-core/src/main/java/org/apache/xtable/catalog/glue/GlueCatalogConfig.java:
##########
@@ -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);

Review Comment:
   Is there a way to just do this parsing with jackson? Similar to what was 
done here: 
https://github.com/apache/incubator-xtable/commit/f6767883f8c27c4ad39e4bb54352fcdae964c11d#diff-ac70a3d50d9eed96fd75f20baf8289cddec6834b15ad6165c077769c3729760dR287



##########
xtable-core/src/main/java/org/apache/xtable/catalog/CatalogUtils.java:
##########
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.xtable.model.catalog.CatalogTableIdentifier;
+import org.apache.xtable.model.catalog.HierarchicalTableIdentifier;
+
+public class CatalogUtils {

Review Comment:
   Add a `@NoArgsConstructor(access = Private)` if this is meant to only expose 
methods and not allow developers to create instances



##########
xtable-core/src/main/java/org/apache/xtable/catalog/glue/DefaultGlueClientFactory.java:
##########
@@ -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) {

Review Comment:
   Can you define more specific exceptions to catch here? 



##########
xtable-core/src/main/java/org/apache/xtable/catalog/glue/table/IcebergGlueCatalogTableBuilder.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.table;
+
+import static 
org.apache.iceberg.BaseMetastoreTableOperations.METADATA_LOCATION_PROP;
+import static 
org.apache.iceberg.BaseMetastoreTableOperations.PREVIOUS_METADATA_LOCATION_PROP;
+import static org.apache.iceberg.BaseMetastoreTableOperations.TABLE_TYPE_PROP;
+import static 
org.apache.xtable.catalog.CatalogUtils.castToHierarchicalTableIdentifier;
+import static 
org.apache.xtable.catalog.glue.GlueCatalogSyncClient.GLUE_EXTERNAL_TABLE_TYPE;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.hadoop.conf.Configuration;
+
+import org.apache.iceberg.BaseTable;
+import org.apache.iceberg.hadoop.HadoopTables;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import org.apache.xtable.catalog.CatalogTableBuilder;
+import org.apache.xtable.catalog.glue.GlueSchemaExtractor;
+import org.apache.xtable.model.InternalTable;
+import org.apache.xtable.model.catalog.CatalogTableIdentifier;
+import org.apache.xtable.model.catalog.HierarchicalTableIdentifier;
+import org.apache.xtable.model.storage.TableFormat;
+
+import software.amazon.awssdk.services.glue.model.StorageDescriptor;
+import software.amazon.awssdk.services.glue.model.Table;
+import software.amazon.awssdk.services.glue.model.TableInput;
+
+/** Iceberg specific table operations for Glue catalog sync */
+public class IcebergGlueCatalogTableBuilder implements 
CatalogTableBuilder<TableInput, Table> {
+
+  private final GlueSchemaExtractor schemaExtractor;
+  private final HadoopTables hadoopTables;
+  private static final String tableFormat = TableFormat.ICEBERG;
+
+  public IcebergGlueCatalogTableBuilder(Configuration configuration) {
+    this.schemaExtractor = GlueSchemaExtractor.getInstance();
+    this.hadoopTables = new HadoopTables(configuration);
+  }
+
+  @VisibleForTesting
+  IcebergGlueCatalogTableBuilder(GlueSchemaExtractor schemaExtractor, 
HadoopTables hadoopTables) {
+    this.schemaExtractor = schemaExtractor;
+    this.hadoopTables = hadoopTables;
+  }
+
+  @Override
+  public TableInput getCreateTableRequest(
+      InternalTable table, CatalogTableIdentifier tableIdentifier) {
+    HierarchicalTableIdentifier tblIdentifier = 
castToHierarchicalTableIdentifier(tableIdentifier);
+    BaseTable fsTable = loadTableFromFs(table.getBasePath());
+    return TableInput.builder()
+        .name(tblIdentifier.getTableName())
+        .tableType(GLUE_EXTERNAL_TABLE_TYPE)
+        .parameters(getTableParameters(fsTable))
+        .storageDescriptor(
+            StorageDescriptor.builder()
+                .location(table.getBasePath())
+                .columns(schemaExtractor.toColumns(tableFormat, 
table.getReadSchema()))
+                .build())
+        .build();
+  }
+
+  @Override
+  public TableInput getUpdateTableRequest(
+      InternalTable table, Table catalogTable, CatalogTableIdentifier 
tableIdentifier) {
+    HierarchicalTableIdentifier tblIdentifier = 
castToHierarchicalTableIdentifier(tableIdentifier);
+    BaseTable icebergTable = loadTableFromFs(table.getBasePath());
+    Map<String, String> parameters = new HashMap<>(catalogTable.parameters());
+    parameters.put(PREVIOUS_METADATA_LOCATION_PROP, 
parameters.get(METADATA_LOCATION_PROP));
+    parameters.put(METADATA_LOCATION_PROP, 
getMetadataFileLocation(icebergTable));
+    parameters.putAll(icebergTable.properties());
+
+    return TableInput.builder()
+        .name(tblIdentifier.getTableName())
+        .tableType(GLUE_EXTERNAL_TABLE_TYPE)
+        .parameters(parameters)
+        .storageDescriptor(
+            StorageDescriptor.builder()
+                .location(table.getBasePath())
+                .columns(
+                    schemaExtractor.toColumns(tableFormat, 
table.getReadSchema(), catalogTable))
+                .build())
+        .build();
+  }
+
+  @VisibleForTesting
+  Map<String, String> getTableParameters(BaseTable icebergTable) {
+    Map<String, String> parameters = new HashMap<>(icebergTable.properties());
+    parameters.put(TABLE_TYPE_PROP, tableFormat);
+    parameters.put(METADATA_LOCATION_PROP, 
getMetadataFileLocation(icebergTable));
+    return parameters;
+  }
+
+  private BaseTable loadTableFromFs(String tableBasePath) {

Review Comment:
   Will this work with an external catalog for Iceberg?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to