emilie-wang commented on code in PR #632:
URL: https://github.com/apache/incubator-xtable/pull/632#discussion_r1937745643


##########
xtable-aws/src/main/java/org/apache/xtable/glue/GlueSchemaExtractor.java:
##########
@@ -0,0 +1,216 @@
+/*
+ * 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.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import org.apache.commons.lang3.StringUtils;
+
+import org.apache.hudi.common.util.VisibleForTesting;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+import org.apache.xtable.exception.NotSupportedException;
+import org.apache.xtable.exception.SchemaExtractorException;
+import org.apache.xtable.model.schema.InternalField;
+import org.apache.xtable.model.schema.InternalSchema;
+
+import software.amazon.awssdk.services.glue.model.Column;
+import software.amazon.awssdk.services.glue.model.Table;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class GlueSchemaExtractor {
+  private static final GlueSchemaExtractor INSTANCE = new 
GlueSchemaExtractor();
+  private static final String FIELD_ID = "field.id";
+  private static final String FIELD_OPTIONAL = "field.optional";
+  private static final String FIELD_CURRENT = "field.current";
+
+  public static GlueSchemaExtractor getInstance() {
+    return INSTANCE;
+  }
+
+  /**
+   * Extract column list from OneTable schema
+   *
+   * @param tableFormat tableFormat to handle format specific type conversion
+   * @param tableSchema OneTable schema
+   * @return glue table column list
+   */
+  public List<Column> toColumns(String tableFormat, InternalSchema 
tableSchema) {
+    return toColumns(tableFormat, tableSchema, null);
+  }
+
+  public List<Column> toColumns(
+      String tableFormat, InternalSchema tableSchema, Table existingTable) {
+    List<Column> columns = Lists.newArrayList();
+    Set<String> addedNames = Sets.newHashSet();
+    for (InternalField field : tableSchema.getFields()) {
+      if (!addedNames.contains(field.getName())) {
+        int fieldId = field.getFieldId() != null ? field.getFieldId() : -1;
+        Column.Builder builder =
+            Column.builder()
+                .name(field.getName())
+                .type(toTypeString(field.getSchema(), tableFormat))
+                .parameters(
+                    ImmutableMap.of(
+                        getColumnProperty(tableFormat, FIELD_ID),
+                        Integer.toString(fieldId),
+                        getColumnProperty(tableFormat, FIELD_OPTIONAL),
+                        Boolean.toString(field.getSchema().isNullable()),
+                        getColumnProperty(tableFormat, FIELD_CURRENT),
+                        "true"));
+
+        if (!StringUtils.isEmpty(field.getSchema().getComment())) {
+          builder.comment(field.getSchema().getComment());

Review Comment:
   For the AWS Glue catalog, it does have a restriction on comment length 
(cannot exceed 255 ) that other catalogs like HMS don't have: 
https://docs.aws.amazon.com/glue/latest/webapi/API_Column.html#:~:text=Maximum%20length%20of%20255.&text=A%20free%2Dform%20text%20comment.
   Can you consider trimming the comment if it exceeds the max length? 
Otherwise the request to Glue will be denied with error. 



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