jbewing commented on code in PR #15410:
URL: https://github.com/apache/iceberg/pull/15410#discussion_r2957466778


##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedRleBooleanValuesReader.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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 java.io.IOException;
+import java.nio.ByteBuffer;
+import org.apache.arrow.vector.BitVector;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.bytes.BytesUtils;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.column.values.bitpacking.BytePacker;
+import org.apache.parquet.column.values.bitpacking.Packer;
+import org.apache.parquet.io.ParquetDecodingException;
+
+/**
+ * A {@link VectorizedValuesReader} for RLE-encoded boolean data pages.
+ *
+ * @see <a
+ *     
href="https://parquet.apache.org/docs/file-format/data-pages/encodings/#run-length-encoding--bit-packing-hybrid-rle--3";>
+ *     Parquet format encodings: RLE</a>
+ */
+public class VectorizedRleBooleanValuesReader extends ValuesReader
+    implements VectorizedValuesReader {
+
+  private enum Mode {
+    RLE,
+    PACKED
+  }
+
+  private static final int BIT_WIDTH = 1;
+  private static final BytePacker PACKER = 
Packer.LITTLE_ENDIAN.newBytePacker(BIT_WIDTH);
+
+  private ByteBufferInputStream inputStream;
+  private Mode mode;
+  private int currentCount;
+  private int currentValue;
+  private int[] packedValuesBuffer = new int[16];
+  private int packedValuesBufferIdx = 0;
+
+  @Override
+  public void initFromPage(int valueCount, ByteBufferInputStream in) throws 
IOException {
+    int length = BytesUtils.readIntLittleEndian(in);
+    this.inputStream = in.sliceStream(length);
+    this.currentCount = 0;
+  }
+
+  @Override
+  public boolean readBoolean() {
+    return nextValue() != 0;
+  }
+
+  @Override
+  public void readBooleans(int total, FieldVector vec, int rowId) {
+    BitVector bitVector = (BitVector) vec;
+    for (int i = 0; i < total; i++) {
+      bitVector.setSafe(rowId + i, readBoolean() ? 1 : 0);
+    }
+  }
+
+  private int nextValue() {
+    if (currentCount == 0) {
+      readNextGroup();
+    }
+
+    currentCount--;
+    switch (mode) {
+      case RLE:
+        return currentValue;
+      case PACKED:
+        return packedValuesBuffer[packedValuesBufferIdx++];

Review Comment:
   Yes, we need to support both as the RLE encoding uses a combination of run 
length encoding & bit-packing. You can read up on the full RLE spec which is 
linked in some previous PR comments & the PR description here to get more 
context on the particulars of the RLE encoding: 
https://parquet.apache.org/docs/file-format/data-pages/encodings/#RLE



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

Reply via email to