lsyldliu commented on code in PR #20442:
URL: https://github.com/apache/flink/pull/20442#discussion_r939516574


##########
flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/vector/reader/ArrayColumnReader.java:
##########
@@ -0,0 +1,464 @@
+/*
+ * 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.flink.formats.parquet.vector.reader;
+
+import org.apache.flink.formats.parquet.vector.ParquetDecimalVector;
+import org.apache.flink.table.data.TimestampData;
+import org.apache.flink.table.data.columnar.vector.VectorizedColumnBatch;
+import org.apache.flink.table.data.columnar.vector.heap.HeapArrayVector;
+import org.apache.flink.table.data.columnar.vector.heap.HeapBooleanVector;
+import org.apache.flink.table.data.columnar.vector.heap.HeapByteVector;
+import org.apache.flink.table.data.columnar.vector.heap.HeapBytesVector;
+import org.apache.flink.table.data.columnar.vector.heap.HeapDoubleVector;
+import org.apache.flink.table.data.columnar.vector.heap.HeapFloatVector;
+import org.apache.flink.table.data.columnar.vector.heap.HeapIntVector;
+import org.apache.flink.table.data.columnar.vector.heap.HeapLongVector;
+import org.apache.flink.table.data.columnar.vector.heap.HeapShortVector;
+import org.apache.flink.table.data.columnar.vector.heap.HeapTimestampVector;
+import 
org.apache.flink.table.data.columnar.vector.writable.WritableColumnVector;
+import org.apache.flink.table.types.logical.ArrayType;
+import org.apache.flink.table.types.logical.LogicalType;
+
+import org.apache.parquet.column.ColumnDescriptor;
+import org.apache.parquet.column.page.PageReader;
+import org.apache.parquet.schema.PrimitiveType;
+import org.apache.parquet.schema.Type;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/** Array {@link ColumnReader}. */
+public class ArrayColumnReader extends BaseVectorizedColumnReader {
+
+    // The value read in last time
+    private Object lastValue;
+
+    // flag to indicate if there is no data in parquet data page
+    private boolean eof = false;
+
+    // flag to indicate if it's the first time to read parquet data page with 
this instance
+    boolean isFirstRow = true;
+
+    public ArrayColumnReader(
+            ColumnDescriptor descriptor,
+            PageReader pageReader,
+            boolean isUtcTimestamp,
+            Type type,
+            LogicalType logicalType)
+            throws IOException {
+        super(descriptor, pageReader, isUtcTimestamp, type, logicalType);
+    }
+
+    @Override
+    public void readToVector(int readNumber, WritableColumnVector vector) 
throws IOException {
+        HeapArrayVector lcv = (HeapArrayVector) vector;
+        // before readBatch, initial the size of offsets & lengths as the 
default value,
+        // the actual size will be assigned in setChildrenInfo() after reading 
complete.
+        lcv.offsets = new long[VectorizedColumnBatch.DEFAULT_SIZE];
+        lcv.lengths = new long[VectorizedColumnBatch.DEFAULT_SIZE];
+
+        LogicalType elementType = ((ArrayType) logicalType).getElementType();
+
+        // read the first row in parquet data page, this will be only happened 
once for this
+        // instance
+        if (isFirstRow) {
+            if (!fetchNextValue(elementType)) {
+                return;
+            }
+            isFirstRow = false;
+        }
+
+        // Because the length of ListColumnVector.child can't be known now,
+        // the valueList will save all data for ListColumnVector temporary.
+        List<Object> valueList = new ArrayList<>();
+
+        int index = collectDataFromParquetPage(readNumber, lcv, valueList, 
elementType);
+        // Convert valueList to array for the ListColumnVector.child
+        fillColumnVector(elementType, lcv, valueList, index);
+    }
+
+    /**
+     * Reads a single value from parquet page, puts it into lastValue. Returns 
a boolean indicating
+     * if there is more values to read (true).
+     *
+     * @param type the element type of array
+     * @return boolean
+     * @throws IOException
+     */
+    private boolean fetchNextValue(LogicalType type) throws IOException {
+        int left = readPageIfNeed();
+        if (left > 0) {
+            // get the values of repetition and definitionLevel
+            readRepetitionAndDefinitionLevels();
+            // read the data if it isn't null
+            if (definitionLevel == maxDefLevel) {
+                if (isCurrentPageDictionaryEncoded) {
+                    lastValue = dataColumn.readValueDictionaryId();
+                } else {
+                    lastValue = readPrimitiveTypedRow(type);
+                }
+            } else {
+                lastValue = null;
+            }
+            return true;
+        } else {
+            eof = true;
+            return false;
+        }
+    }
+
+    private int readPageIfNeed() throws IOException {
+        // Compute the number of values we want to read in this page.
+        int leftInPage = (int) (endOfPageValueCount - valuesRead);
+        if (leftInPage == 0) {
+            // no data left in current page, load data from new page
+            readPage();
+            leftInPage = (int) (endOfPageValueCount - valuesRead);
+        }
+        return leftInPage;
+    }
+
+    // Need to be in consistent with that 
VectorizedPrimitiveColumnReader#readBatchHelper
+    // TODO Reduce the duplicated code
+    private Object readPrimitiveTypedRow(LogicalType type) {
+        switch (type.getTypeRoot()) {
+            case CHAR:
+            case VARCHAR:
+            case BINARY:
+            case VARBINARY:
+                return dataColumn.readString();
+            case BOOLEAN:
+                return dataColumn.readBoolean();
+            case TIME_WITHOUT_TIME_ZONE:
+            case DATE:
+            case INTEGER:
+                return dataColumn.readInteger();
+            case TINYINT:
+                return dataColumn.readTinyInt();
+            case SMALLINT:
+                return dataColumn.readSmallInt();
+            case BIGINT:
+                return dataColumn.readLong();
+            case FLOAT:
+                return dataColumn.readFloat();
+            case DOUBLE:
+                return dataColumn.readDouble();
+            case DECIMAL:
+                switch (descriptor.getPrimitiveType().getPrimitiveTypeName()) {
+                    case INT32:
+                        return dataColumn.readInteger();
+                    case INT64:
+                        return dataColumn.readLong();
+                    case BINARY:
+                    case FIXED_LEN_BYTE_ARRAY:
+                        return dataColumn.readString();

Review Comment:
   I've remove the unused method currently.



-- 
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-unsubscr...@flink.apache.org

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

Reply via email to