wgtmac commented on code in PR #9772:
URL: https://github.com/apache/iceberg/pull/9772#discussion_r1527197363
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedParquetDefinitionLevelReader.java:
##########
@@ -47,35 +46,45 @@ public VectorizedParquetDefinitionLevelReader(
super(bitWidth, maxDefLevel, readLength, setArrowValidityVector);
}
- abstract class NumericBaseReader {
+ abstract class BaseReader {
Review Comment:
I have merged `NumericBaseReader` into `BaseReader` to eliminate the
duplicate code.
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedPageIterator.java:
##########
@@ -95,7 +94,9 @@ protected void initDataReader(Encoding dataEncoding,
ByteBufferInputStream in, i
throw new ParquetDecodingException("could not read page in col " +
desc, e);
}
} else {
- if (dataEncoding != Encoding.PLAIN) {
+ if (dataEncoding == Encoding.PLAIN) {
+ valuesReader = new VectorizedPlainValuesReader();
+ } else {
Review Comment:
More VectorizedValuesReader implementations will be added here for different
encodings.
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedValuesReader.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.io.api.Binary;
+
+/** Interface for value decoding that supports vectorized (aka batched)
decoding. */
+interface VectorizedValuesReader {
Review Comment:
This is the new package-private vectorized reader for a single page. All v2
encodings will be added by implementing this interface and selected readXXX()
methods.
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedPageIterator.java:
##########
@@ -46,7 +45,7 @@ public VectorizedPageIterator(
this.setArrowValidityVector = setValidityVector;
}
- private ValuesAsBytesReader plainValuesReader = null;
+ private VectorizedValuesReader valuesReader = null;
Review Comment:
I have replaced plainValuesReader with generic values reader to support
different encodings.
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedParquetDefinitionLevelReader.java:
##########
@@ -150,280 +159,195 @@ public void nextDictEncodedBatch(
}
protected abstract void nextVal(
- FieldVector vector, int idx, ValuesAsBytesReader valuesReader, Mode
mode);
+ FieldVector vector, int idx, VectorizedValuesReader valuesReader, int
typeWidth);
protected abstract void nextDictEncodedVal(
FieldVector vector,
int idx,
- VectorizedDictionaryEncodedParquetValuesReader
dictionaryEncodedValuesReader,
+ VectorizedDictionaryEncodedParquetValuesReader reader,
+ int numValuesToRead,
Dictionary dict,
- Mode mode,
+ NullabilityHolder nullabilityHolder,
+ int typeWidth,
+ Mode mode);
+
+ protected void nextValues(
Review Comment:
This method is where we utilize the vectorized reading method from
VectorizedValuesReader. You can see
LongReader/IntegerReader/FloatReader/DoubleReader have overridden this method.
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedParquetDefinitionLevelReader.java:
##########
@@ -150,280 +159,195 @@ public void nextDictEncodedBatch(
}
protected abstract void nextVal(
- FieldVector vector, int idx, ValuesAsBytesReader valuesReader, Mode
mode);
+ FieldVector vector, int idx, VectorizedValuesReader valuesReader, int
typeWidth);
protected abstract void nextDictEncodedVal(
FieldVector vector,
int idx,
- VectorizedDictionaryEncodedParquetValuesReader
dictionaryEncodedValuesReader,
+ VectorizedDictionaryEncodedParquetValuesReader reader,
+ int numValuesToRead,
Dictionary dict,
- Mode mode,
+ NullabilityHolder nullabilityHolder,
+ int typeWidth,
+ Mode mode);
+
+ protected void nextValues(
+ FieldVector vector,
+ int bufferIdx,
int numValues,
- NullabilityHolder holder,
- int typeWidth);
+ VectorizedValuesReader valuesReader,
+ int typeWidth) {
+ for (int i = 0; i < numValues; i++) {
+ nextVal(vector, bufferIdx + i, valuesReader, typeWidth);
+ }
+ }
+
+ // Used only for fixed-length binary types
+ @SuppressWarnings("checkstyle:VisibilityModifier")
+ protected byte[] byteArray;
}
- class LongReader extends NumericBaseReader {
+ class LongReader extends BaseReader {
@Override
protected void nextVal(
- FieldVector vector, int idx, ValuesAsBytesReader valuesReader, Mode
mode) {
- vector.getDataBuffer().setLong(idx, valuesReader.readLong());
+ FieldVector vector, int idx, VectorizedValuesReader valuesReader, int
typeWidth) {
+ vector.getDataBuffer().setLong((long) idx * typeWidth,
valuesReader.readLong());
}
@Override
protected void nextDictEncodedVal(
FieldVector vector,
int idx,
- VectorizedDictionaryEncodedParquetValuesReader
dictionaryEncodedValuesReader,
+ VectorizedDictionaryEncodedParquetValuesReader reader,
+ int numValuesToRead,
Dictionary dict,
- Mode mode,
- int numValues,
- NullabilityHolder holder,
- int typeWidth) {
+ NullabilityHolder nullabilityHolder,
+ int typeWidth,
+ Mode mode) {
if (Mode.RLE.equals(mode)) {
- dictionaryEncodedValuesReader
+ reader
.longDictEncodedReader()
- .nextBatch(vector, idx, numValues, dict, holder, typeWidth);
+ .nextBatch(vector, idx, numValuesToRead, dict, nullabilityHolder,
typeWidth);
} else if (Mode.PACKED.equals(mode)) {
vector
.getDataBuffer()
- .setLong(
- (long) idx * typeWidth,
-
dict.decodeToLong(dictionaryEncodedValuesReader.readInteger()));
+ .setLong((long) idx * typeWidth,
dict.decodeToLong(reader.readInteger()));
}
}
+
+ @Override
+ protected void nextValues(
+ FieldVector vector,
+ int bufferIdx,
+ int numValues,
+ VectorizedValuesReader valuesReader,
+ int typeWidth) {
+ valuesReader.readLongs(numValues, vector, bufferIdx);
Review Comment:
For example, `LongReader` overrides nextValues to use
`VectorizedValuesReader.readLongs()` method for vectorized reading.
--
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]