JingsongLi commented on a change in pull request #13479:
URL: https://github.com/apache/flink/pull/13479#discussion_r503081381



##########
File path: 
flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/ParquetColumnarRowInputFormat.java
##########
@@ -0,0 +1,189 @@
+/*
+ * 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;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.connector.file.src.util.Pool;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.formats.parquet.utils.SerializableConfiguration;
+import org.apache.flink.formats.parquet.vector.ColumnBatchFactory;
+import org.apache.flink.table.data.ColumnarRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.vector.ColumnVector;
+import org.apache.flink.table.data.vector.VectorizedColumnBatch;
+import org.apache.flink.table.data.vector.writable.WritableColumnVector;
+import org.apache.flink.table.filesystem.ColumnarRowIterator;
+import org.apache.flink.table.filesystem.PartitionValueConverter;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.utils.PartitionPathUtils;
+
+import org.apache.hadoop.conf.Configuration;
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static 
org.apache.flink.formats.parquet.vector.ParquetSplitReaderUtil.createVectorFromConstant;
+
+/**
+ * A {@link ParquetVectorizedInputFormat} to provide {@link RowData} iterator.
+ * Using {@link ColumnarRowData} to provide a row view of column batch.
+ */
+public class ParquetColumnarRowInputFormat extends 
ParquetVectorizedInputFormat<RowData> {
+
+       private static final long serialVersionUID = 1L;
+
+       private final RowType producedType;
+
+       /**
+        * Constructor to create parquet format without other fields.
+        */
+       public ParquetColumnarRowInputFormat(
+                       Configuration hadoopConfig,
+                       String[] projectedFields,
+                       LogicalType[] projectedTypes,
+                       int batchSize,
+                       boolean isUtcTimestamp,
+                       boolean isCaseSensitive) {
+               this(
+                               hadoopConfig,
+                               projectedFields,
+                               projectedTypes,
+                               RowType.of(projectedTypes, projectedFields),
+                               ColumnBatchFactory.DEFAULT,
+                               batchSize,
+                               isUtcTimestamp,
+                               isCaseSensitive);
+       }
+
+       /**
+        * Constructor to create parquet format with other fields created by 
{@link ColumnBatchFactory}.
+        */
+       public ParquetColumnarRowInputFormat(
+                       Configuration hadoopConfig,
+                       String[] projectedFields,
+                       LogicalType[] projectedTypes,
+                       RowType producedType,
+                       ColumnBatchFactory batchFactory,
+                       int batchSize,
+                       boolean isUtcTimestamp,
+                       boolean isCaseSensitive) {
+               super(
+                               new SerializableConfiguration(hadoopConfig),
+                               projectedFields,
+                               projectedTypes,
+                               batchFactory,
+                               batchSize,
+                               isUtcTimestamp,
+                               isCaseSensitive);
+               this.producedType = producedType;
+       }
+
+       @Override
+       protected ParquetReaderBatch<RowData> createReaderBatch(
+                       WritableColumnVector[] writableVectors,
+                       VectorizedColumnBatch columnarBatch,
+                       Pool.Recycler<ParquetReaderBatch<RowData>> recycler) {
+               return new ColumnarRowReaderBatch(writableVectors, 
columnarBatch, recycler);
+       }
+
+       @Override
+       public TypeInformation<RowData> getProducedType() {
+               return InternalTypeInfo.of(producedType);
+       }
+
+       private static class ColumnarRowReaderBatch extends 
ParquetReaderBatch<RowData> {
+
+               private final ColumnarRowIterator result;
+
+               private ColumnarRowReaderBatch(
+                               WritableColumnVector[] writableVectors,
+                               VectorizedColumnBatch columnarBatch,
+                               Pool.Recycler<ParquetReaderBatch<RowData>> 
recycler) {
+                       super(writableVectors, columnarBatch, recycler);
+                       this.result = new ColumnarRowIterator(new 
ColumnarRowData(columnarBatch), this::recycle);
+               }
+
+               @Override
+               public RecordIterator<RowData> convertAndGetIterator(long 
rowsReturned) {
+                       result.set(columnarBatch.getNumRows(), rowsReturned);
+                       return result;
+               }
+       }
+
+       /**
+        * Create a partitioned {@link ParquetColumnarRowInputFormat}, the 
partition columns can be
+        * generated by {@link Path}.
+        */
+       public static ParquetColumnarRowInputFormat createPartitionedFormat(
+                       Configuration hadoopConfig,
+                       RowType tableType,
+                       List<String> partitionKeys,
+                       String defaultPartValue,
+                       int[] selectedFields,
+                       PartitionValueConverter valueConverter,

Review comment:
       This can be improved when it takes a Split in the create/restore method, 
not just the path and position. Then we can get partition directly.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to