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



##########
File path: 
hive3/src/main/java/org/apache/iceberg/mr/hive/vector/ParquetSchemaFieldNameVisitor.java
##########
@@ -0,0 +1,109 @@
+/*
+ * 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 to 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 Map<Integer, Type> typesById = Maps.newHashMap();
+  private StringBuilder sb = new StringBuilder();
+
+  ParquetSchemaFieldNameVisitor() {
+  }
+
+  @Override
+  public Type message(Types.StructType expected, MessageType message, 
List<Type> fields) {
+    return this.struct(expected, message.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()) {
+        Type fieldInFileSchema = typesById.get(id);
+        if (fieldInFileSchema == null) {
+          // New field - not in this parquet file yet, add the new field name 
instead of null
+          appendToColNamesList(isMessageType, field.name());
+        } else {
+          // Already present column in this parquet file, add the original name
+          types.add(fieldInFileSchema);
+          appendToColNamesList(isMessageType, fieldInFileSchema.getName());

Review comment:
       Actually Hive's column pruning info only contains the top level column 
names, it is unable to prune within nested types unfortunately.. Hence there's 
no need to deal with those anyway




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