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/01/26 12:07:27 UTC

[GitHub] [iceberg] szlta commented on a change in pull request #3980: Hive: Parquet vectorization support for Hive 3

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



##########
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:
       Only top level column names are required. Hive's Parquet (and ORC too) vectorized record reader doesn't take nested column pruning into account, and while we can't have the same column name twice within the top level, I don't think this would be a problem.




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