kroushan-nit commented on code in PR #632:
URL: https://github.com/apache/incubator-xtable/pull/632#discussion_r1937258340


##########
xtable-api/src/main/java/org/apache/xtable/conversion/ExternalCatalogConfig.java:
##########
@@ -61,5 +61,5 @@ public class ExternalCatalogConfig {
   /**
    * The properties for this catalog, used for providing any custom behaviour 
during catalog sync
    */
-  @NonNull @Builder.Default Map<String, String> catalogProperties = 
Collections.emptyMap();

Review Comment:
   do you want `catalogProperties` to be set explicitly even when empty?



##########
xtable-aws/src/main/java/org/apache/xtable/glue/GlueCatalogConfig.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.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.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;

Review Comment:
   We are not initialising the config using constructor but converting 
`Map<String, String>` to `GlueCatalogConfig`, so don't think final can be used



##########
xtable-aws/src/main/java/org/apache/xtable/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.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 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.glue.GlueCatalogSyncClient;
+import org.apache.xtable.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(GlueCatalogSyncClient.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(GlueCatalogSyncClient.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) {
+    return (BaseTable) hadoopTables.load(tableBasePath);

Review Comment:
   what do you mean when you say "existing catalog"?
   
   Currently, we assume that table can be loaded using Hadoop catalog. Support 
for loading the table using configured iceberg catalog will be added in the 
future



-- 
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