Github user ppadma commented on a diff in the pull request:

    https://github.com/apache/drill/pull/789#discussion_r108559596
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/columnreaders/ParquetSchema.java
 ---
    @@ -0,0 +1,207 @@
    +/*
    + * 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.drill.exec.store.parquet.columnreaders;
    +
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +
    +import org.apache.drill.common.expression.SchemaPath;
    +import org.apache.drill.common.types.TypeProtos;
    +import org.apache.drill.common.types.Types;
    +import org.apache.drill.common.types.TypeProtos.DataMode;
    +import org.apache.drill.exec.exception.SchemaChangeException;
    +import org.apache.drill.exec.expr.TypeHelper;
    +import org.apache.drill.exec.physical.impl.OutputMutator;
    +import org.apache.drill.exec.record.MaterializedField;
    +import org.apache.drill.exec.server.options.OptionManager;
    +import org.apache.drill.exec.store.parquet.ParquetReaderUtility;
    +import org.apache.drill.exec.vector.NullableIntVector;
    +import org.apache.parquet.column.ColumnDescriptor;
    +import org.apache.parquet.format.SchemaElement;
    +import org.apache.parquet.hadoop.metadata.BlockMetaData;
    +import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
    +import org.apache.parquet.hadoop.metadata.ParquetMetadata;
    +
    +import com.google.common.collect.Lists;
    +
    +/**
    + * Mapping from the schema of the Parquet file to that of the record reader
    + * to the schema that Drill and the Parquet reader uses.
    + */
    +
    +public class ParquetSchema {
    +  private Collection<SchemaPath> selectedCols;
    +  // This is a parallel list to the columns list above, it is used to 
determine the subset of the project
    +  // pushdown columns that do not appear in this file
    +  private boolean[] columnsFound;
    +  private ParquetMetadata footer;
    +  private Map<String, SchemaElement> schemaElements;
    +  private int columnsToScan;
    +  private List<ColumnDescriptor> columns;
    +  private List<ParquetColumnMetadata> columnMd = new ArrayList<>();
    +  private int bitWidthAllFixedFields;
    +  private boolean allFieldsFixedLength = true;
    +  private long groupRecordCount;
    +  private int recordsPerBatch;
    +  private int rowGroupIndex;
    +  private final OptionManager options;
    +
    +  public ParquetSchema(OptionManager options, int rowGroupIndex) {
    +    selectedCols = null;
    +    this.rowGroupIndex = rowGroupIndex;
    +    this.options = options;
    +  }
    +
    +  public ParquetSchema(OptionManager options, Collection<SchemaPath> 
selectedCols) {
    +    this.options = options;
    +    this.selectedCols = selectedCols;
    +    columnsFound = new boolean[selectedCols.size()];
    +  }
    +
    +  public void buildSchema(ParquetMetadata footer, long batchSize) throws 
Exception {
    +    this.footer = footer;
    +    columns = footer.getFileMetaData().getSchema().getColumns();
    +    groupRecordCount = footer.getBlocks().get(rowGroupIndex).getRowCount();
    +    loadParquetSchema();
    +    computeFixedPart();
    +//    rowGroupOffset = 
footer.getBlocks().get(rowGroupIndex).getColumns().get(0).getFirstDataPageOffset();
    +
    +    if (columnsToScan != 0  && allFieldsFixedLength) {
    +      recordsPerBatch = (int) Math.min(Math.min(batchSize / 
bitWidthAllFixedFields,
    +          footer.getBlocks().get(0).getColumns().get(0).getValueCount()), 
ParquetRecordReader.DEFAULT_RECORDS_TO_READ_IF_FIXED_WIDTH);
    +    }
    +    else {
    +      recordsPerBatch = 
ParquetRecordReader.DEFAULT_RECORDS_TO_READ_IF_VARIABLE_WIDTH;
    +    }
    +  }
    +
    +  private void loadParquetSchema() {
    +    // TODO - figure out how to deal with this better once we add nested 
reading, note also look where this map is used below
    +    // store a map from column name to converted types if they are non-null
    +    schemaElements = 
ParquetReaderUtility.getColNameToSchemaElementMapping(footer);
    +
    +    // loop to add up the length of the fixed width columns and build the 
schema
    +    for (ColumnDescriptor column : columns) {
    +      ParquetColumnMetadata colMd = new ParquetColumnMetadata(column);
    +      colMd.resolveDrillType(schemaElements, options);
    +      if (! fieldSelected(colMd.field)) {
    +        continue;
    +      }
    +      columnMd.add(colMd);
    --- End diff --
    
    I suggest that we rename columnMd as columnsMetadata and colMd as 
columnMetadata. It is confusing to infer that columnMd is column metadata for 
all columns. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to