vinooganesh commented on code in PR #3397:
URL: https://github.com/apache/parquet-java/pull/3397#discussion_r3567845033


##########
parquet-column/src/main/java/org/apache/parquet/column/values/alp/AlpValuesReaderForFloat.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.parquet.column.values.alp;
+
+import static org.apache.parquet.column.values.alp.AlpConstants.*;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import org.apache.parquet.column.values.bitpacking.BytePacker;
+import org.apache.parquet.column.values.bitpacking.Packer;
+import org.apache.parquet.io.ParquetDecodingException;
+
+/**
+ * ALP values reader for FLOAT type with lazy per-vector decoding.
+ *
+ * <p>Reads ALP-encoded float values from the interleaved page layout.
+ * Each vector is decoded on first access using BytePacker-based unpacking.
+ */
+public class AlpValuesReaderForFloat extends AlpValuesReader {
+
+  private float[] decodedValues;
+  private int[] deltasBuffer;
+  private int[] excPositionsBuffer;
+  private final int[] unpackPadBuf = new int[8];
+  private byte[] unpackByteBuf;
+
+  public AlpValuesReaderForFloat() {
+    super();
+  }
+
+  @Override
+  protected void allocateDecodedBuffer(int capacity) {
+    this.decodedValues = new float[capacity];
+    this.deltasBuffer = new int[capacity];
+    this.excPositionsBuffer = new int[capacity];
+    this.unpackByteBuf = new byte[Integer.SIZE]; // max bit width for int = 32 
bytes
+  }
+

Review Comment:
   Applied the same changes to the float reader: bounds check, vectorNumber 
naming, typed getters, and the BytesUtils helpers.



##########
parquet-column/src/main/java/org/apache/parquet/column/values/alp/AlpValuesReaderForDouble.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.parquet.column.values.alp;
+
+import static org.apache.parquet.column.values.alp.AlpConstants.*;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import org.apache.parquet.column.values.bitpacking.BytePackerForLong;
+import org.apache.parquet.column.values.bitpacking.Packer;
+import org.apache.parquet.io.ParquetDecodingException;
+
+/**
+ * ALP values reader for DOUBLE type with lazy per-vector decoding.
+ *
+ * <p>Reads ALP-encoded double values from the interleaved page layout.
+ * Each vector is decoded on first access using BytePackerForLong-based 
unpacking.
+ */
+public class AlpValuesReaderForDouble extends AlpValuesReader {
+
+  private double[] decodedValues;
+  private long[] deltasBuffer;
+  private int[] excPositionsBuffer;
+  private final long[] unpackPadBuf = new long[8];
+  private byte[] unpackByteBuf;
+
+  public AlpValuesReaderForDouble() {
+    super();
+  }
+
+  @Override
+  protected void allocateDecodedBuffer(int capacity) {
+    this.decodedValues = new double[capacity];
+    this.deltasBuffer = new long[capacity];
+    this.excPositionsBuffer = new int[capacity];
+    this.unpackByteBuf = new byte[Long.SIZE]; // max bit width for long = 64 
bytes
+  }
+
+  @Override
+  public double readDouble() {
+    if (currentIndex >= totalCount) {
+      throw new ParquetDecodingException("ALP double data was already 
exhausted.");
+    }
+    ensureVectorDecoded();
+    int indexInVector = currentIndex % vectorSize;
+    currentIndex++;
+    return decodedValues[indexInVector];
+  }
+
+  @Override
+  protected void decodeVector(int vectorIdx) {
+    int vectorLen = getVectorLength(vectorIdx);
+    int pos = getVectorDataPosition(vectorIdx);
+
+    int exponent = vectorsData.get(pos) & 0xFF;
+    int factor = vectorsData.get(pos + 1) & 0xFF;
+    int numExceptions = getShortLE(vectorsData, pos + 2) & 0xFFFF;
+    pos += ALP_INFO_SIZE;
+
+    if (exponent > DOUBLE_MAX_EXPONENT) {
+      throw new ParquetDecodingException(
+          "Invalid ALP double exponent " + exponent + " in vector " + 
vectorIdx + ", max is " + DOUBLE_MAX_EXPONENT);
+    }
+    if (factor > exponent) {
+      throw new ParquetDecodingException(
+          "Invalid ALP double factor " + factor + " > exponent " + exponent + 
" in vector " + vectorIdx);
+    }
+    if (numExceptions > vectorLen) {
+      throw new ParquetDecodingException(
+          "Invalid ALP numExceptions " + numExceptions + " > vectorLen " + 
vectorLen + " in vector " + vectorIdx);
+    }
+
+    long frameOfReference = getLongLE(vectorsData, pos);
+    int bitWidth = vectorsData.get(pos + 8) & 0xFF;
+    pos += DOUBLE_FOR_INFO_SIZE;
+
+    if (bitWidth > 0) {

Review Comment:
   Added the bitWidth > 64 bounds check in the double reader.



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