You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "Copilot (via GitHub)" <gi...@apache.org> on 2026/03/26 01:45:08 UTC

Re: [PR] Add V6 forward index format with delta-encoded chunk headers [pinot]

Copilot commented on code in PR #17966:
URL: https://github.com/apache/pinot/pull/17966#discussion_r2992002292


##########
pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/creator/VarByteChunkV5Test.java:
##########
@@ -144,87 +78,31 @@ public void validateCompressionRatioIncrease()
       inputData.add(mvRow);
     }
 
-    for (int i = 0; i < _dirs.length; i++) {
-      _dirs[i] = new File(new File(FileUtils.getTempDirectory(), UUID.randomUUID().toString()), "VarByteChunkV5Test");
-      FileUtils.forceMkdir(_dirs[i]);
-    }
-
-    // Generate MV fixed byte raw fwd index with explicit length
-    int rawIndexVersionV4 = 4;
-    File explicitLengthFwdIndexFile = new File(FileUtils.getTempDirectory(), Integer.toString(rawIndexVersionV4));
+    // Generate MV fixed byte raw fwd index with explicit length (V4)
+    File explicitLengthFwdIndexFile = new File(FileUtils.getTempDirectory(), "v5test_v4");
     FileUtils.deleteQuietly(explicitLengthFwdIndexFile);
     try (MultiValueFixedByteRawIndexCreator creator = new MultiValueFixedByteRawIndexCreator(explicitLengthFwdIndexFile,
-        ChunkCompressionType.ZSTANDARD, numDocs, FieldSpec.DataType.LONG, numElements, true, rawIndexVersionV4)) {
+        ChunkCompressionType.ZSTANDARD, numDocs, FieldSpec.DataType.LONG, numElements, true, 4)) {
       for (long[] mvRow : inputData) {

Review Comment:
   `validateCompressionRatioIncrease()` is computing `numElements` by adding `mvRow.length` and then incrementing it again inside the element loop (`j++, numElements++`), which double-counts. Also, `MultiValueFixedByteRawIndexCreator`'s constructor parameter here is `maxNumberOfMultiValueElements`, but the test passes `numElements` (total elements across all rows) instead of the per-row maximum (`maxMVRowSize`). This can hugely overestimate row size, skew chunk sizing, and make the compression ratio assertion less meaningful. Track a separate value counter for filling data, and pass `maxMVRowSize` into the creator.



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/forward/VarByteChunkForwardIndexReaderV6.java:
##########
@@ -0,0 +1,96 @@
+/**
+ * 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.pinot.segment.local.segment.index.readers.forward;
+
+import java.nio.ByteBuffer;
+import org.apache.pinot.segment.local.io.writer.impl.VarByteChunkForwardIndexWriterV6;
+import org.apache.pinot.segment.spi.compression.ChunkCompressionType;
+import org.apache.pinot.segment.spi.compression.ChunkDecompressor;
+import org.apache.pinot.segment.spi.memory.PinotDataBuffer;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+/**
+ * Reader for the V6 forward index format, extending V5 (which extends V4).
+ *
+ * <p>When compressed, V6 stores individual entry sizes in the chunk header instead of cumulative
+ * offsets (V4). After decompression, sizes are converted to cumulative offsets in a single forward
+ * pass, then V4's standard random-access read logic is reused unchanged.
+ *
+ * <p>When uncompressed (PASS_THROUGH), V6 writes V4 offsets directly, so V4's standard
+ * uncompressed context is reused with no delta decoding overhead.
+ *
+ * <p>MV fixed-byte deserialization (without length prefix) is inherited from V5.
+ *
+ * @see VarByteChunkForwardIndexWriterV6
+ */
+public class VarByteChunkForwardIndexReaderV6 extends VarByteChunkForwardIndexReaderV5 {
+
+  public VarByteChunkForwardIndexReaderV6(PinotDataBuffer dataBuffer, FieldSpec.DataType storedType,
+      boolean isSingleValue) {
+    super(dataBuffer, storedType, isSingleValue);
+  }
+
+  @Override
+  public int getVersion() {
+    return VarByteChunkForwardIndexWriterV6.VERSION;
+  }
+
+  @Override
+  public ReaderContext createContext() {
+    if (_chunkCompressionType == ChunkCompressionType.PASS_THROUGH) {
+      // No compression — V6 writes V4 offsets directly, so reuse V4's uncompressed context
+      return new UncompressedReaderContext(_chunks, _metadata, _chunksStartOffset);

Review Comment:
   In the PASS_THROUGH path, this instantiates `UncompressedReaderContext(_chunks, _metadata, ...)`, which only works because `UncompressedReaderContext` currently swaps its args when calling `super(...)`. Once the context ctor is corrected to use `(metadata, chunks)` consistently, this call site should also be updated to pass `(_metadata, _chunks, _chunksStartOffset)` to avoid subtle regressions.
   ```suggestion
         return new UncompressedReaderContext(_metadata, _chunks, _chunksStartOffset);
   ```



##########
pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/creator/VarByteChunkV6Test.java:
##########
@@ -0,0 +1,104 @@
+/**
+ * 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.pinot.segment.local.segment.index.creator;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import org.apache.commons.io.FileUtils;
+import org.apache.pinot.segment.local.io.writer.impl.VarByteChunkForwardIndexWriterV6;
+import org.apache.pinot.segment.local.io.writer.impl.VarByteChunkWriter;
+import org.apache.pinot.segment.local.segment.creator.impl.fwd.MultiValueFixedByteRawIndexCreator;
+import org.apache.pinot.segment.local.segment.index.readers.forward.VarByteChunkForwardIndexReaderV4;
+import org.apache.pinot.segment.local.segment.index.readers.forward.VarByteChunkForwardIndexReaderV6;
+import org.apache.pinot.segment.spi.compression.ChunkCompressionType;
+import org.apache.pinot.segment.spi.memory.PinotDataBuffer;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for V6 forward index format. Inherits all write/read tests from {@link VarByteChunkV5Test}
+ * and adds a compression ratio validation test for delta-encoded chunk headers.
+ */
+public class VarByteChunkV6Test extends VarByteChunkV5Test {
+  private static final Random RANDOM = new Random();
+
+  @Override
+  protected String getTestDirName() {
+    return "VarByteChunkV6Test";
+  }
+
+  @Override
+  protected VarByteChunkWriter createWriter(File file, ChunkCompressionType compressionType, int chunkSize)
+      throws IOException {
+    return new VarByteChunkForwardIndexWriterV6(file, compressionType, chunkSize);
+  }
+
+  @Override
+  protected VarByteChunkForwardIndexReaderV4 createReader(PinotDataBuffer buffer, FieldSpec.DataType dataType,
+      boolean isSingleValue) {
+    return new VarByteChunkForwardIndexReaderV6(buffer, dataType, isSingleValue);
+  }
+
+  @Test
+  public void validateCompressionRatioIncrease()
+      throws IOException {
+    int numDocs = 1000000;
+    int maxMVRowSize = 0;
+    int valueCounter = 0;
+    List<long[]> inputData = new ArrayList<>(numDocs);
+    for (int i = 0; i < numDocs; i++) {
+      long[] mvRow = new long[Math.abs((int) Math.floor(RANDOM.nextGaussian()))];

Review Comment:
   The MV row length is derived from `Math.abs((int) Math.floor(RANDOM.nextGaussian()))`, which is unbounded and can very rarely produce extremely large values (or hit the `Math.abs(Integer.MIN_VALUE)` overflow case), leading to `NegativeArraySizeException`/OOM and flaky CI. Consider using a bounded distribution (e.g., clamp to a small max) and avoid `Math.abs(int)` on potentially `Integer.MIN_VALUE` values (e.g., handle negatives explicitly).
   ```suggestion
         int mvRowSize = RANDOM.nextInt(16);
         long[] mvRow = new long[mvRowSize];
   ```



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org