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


##########
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:
   Feels right to me if we're leaning into an inheritance based hierarchy, I 
refactored to that approach in 
https://github.com/apache/iceberg/pull/15410/changes/3c2e391c3df28f85110fee3112058d5d56b5a075.
   
   Part of me can't help but feeling that we've ended in an interesting place 
w.r.t inheritance here creating a dual hierarchy for RLE consumers. Personal 
preference steers me towards what we had in 
https://github.com/apache/iceberg/pull/15410/changes/4c9d7c4f02e1461a0db21320b175d70fa74eea05
 with composition (& fully vectorized read paths instead of relying on callers 
implementing those read paths themselves which they happened to already be 
doing before).
   
   Let me know what you think



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