pvary commented on a change in pull request #3980:
URL: https://github.com/apache/iceberg/pull/3980#discussion_r794471035



##########
File path: 
hive3/src/main/java/org/apache/iceberg/mr/hive/vector/ParquetSchemaFieldNameVisitor.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.mr.hive.vector;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.MetadataColumns;
+import org.apache.iceberg.parquet.TypeWithSchemaVisitor;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.types.Types;
+import org.apache.parquet.schema.GroupType;
+import org.apache.parquet.schema.MessageType;
+import org.apache.parquet.schema.Type;
+
+/**
+ * Collects the top level field names from Parquet schema. During schema visit 
it translates the expected schema's
+ * field names to what fields the visitor can match in the file schema to 
support column renames.
+ */
+class ParquetSchemaFieldNameVisitor extends TypeWithSchemaVisitor<Type> {
+  private final MessageType originalFileSchema;
+  private final Map<Integer, Type> typesById = Maps.newHashMap();
+  private StringBuilder sb = new StringBuilder();
+  private static final String DUMMY_COL_NAME = 
"<<DUMMY_FOR_RECREATED_FIELD_IN_FILESCHEMA>>";
+
+  ParquetSchemaFieldNameVisitor(MessageType originalFileSchema) {
+    this.originalFileSchema = originalFileSchema;
+  }
+
+  @Override
+  public Type message(Types.StructType expected, MessageType prunedFileSchema, 
List<Type> fields) {
+    return this.struct(expected, prunedFileSchema.asGroupType(), fields);
+  }
+
+  @Override
+  public Type struct(Types.StructType expected, GroupType struct, List<Type> 
fields) {
+    boolean isMessageType = struct instanceof MessageType;
+
+    List<Types.NestedField> expectedFields = expected != null ? 
expected.fields() : ImmutableList.of();
+    List<Type> types = 
Lists.newArrayListWithExpectedSize(expectedFields.size());
+
+    for (Types.NestedField field : expectedFields) {
+      int id = field.fieldId();
+      if (id == MetadataColumns.ROW_POSITION.fieldId() || id == 
MetadataColumns.IS_DELETED.fieldId()) {

Review comment:
       Why just skip these metadata columns? Why not skip the others 
(FILE_PATH/SPEC_ID/PARTITION_COLUMN_ID)?
   Maybe use `MetadataColumns.isMetadataColumn(field.name())`




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to