You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/12/21 23:26:12 UTC

[GitHub] [iceberg] JonasJ-ap commented on a diff in pull request #6449: WIP: Core, Spark: Adding support for Migrating Delta Lake Table to Iceberg Table

JonasJ-ap commented on code in PR #6449:
URL: https://github.com/apache/iceberg/pull/6449#discussion_r1054932981


##########
core/src/main/java/org/apache/iceberg/DeltaLakeDataTypeVisitor.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.iceberg;
+
+import io.delta.standalone.types.ArrayType;
+import io.delta.standalone.types.DataType;
+import io.delta.standalone.types.MapType;
+import io.delta.standalone.types.StructField;
+import io.delta.standalone.types.StructType;
+import java.util.List;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+
+public class DeltaLakeDataTypeVisitor<T> {
+  public static <T> T visit(DataType type, DeltaLakeDataTypeVisitor<T> visitor) {
+    if (type instanceof StructType) {
+      StructField[] fields = ((StructType) type).getFields();
+      List<T> fieldResults = Lists.newArrayListWithExpectedSize(fields.length);
+
+      for (StructField field : fields) {
+        fieldResults.add(visitor.field(field, visit(field.getDataType(), visitor)));
+      }
+
+      return visitor.struct((StructType) type, fieldResults);
+
+    } else if (type instanceof MapType) {
+      return visitor.map(
+          (MapType) type,
+          visit(((MapType) type).getKeyType(), visitor),
+          visit(((MapType) type).getValueType(), visitor));
+
+    } else if (type instanceof ArrayType) {
+      return visitor.array((ArrayType) type, visit(((ArrayType) type).getElementType(), visitor));
+
+    } else {
+      return visitor.atomic(type);
+    }
+  }
+
+  public T struct(StructType struct, List<T> fieldResults) {
+    return null;

Review Comment:
   The actual implementations of these functions are higly dependent on the actual type we want to convert to. I think maybe we can make these methods abstract and make actual implementation in `DeltaLakeTypeToType`. Do you think it is ok to implement in this way?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org