From c244a97931b4a00df201c3d7ac107356d8217055 Mon Sep 17 00:00:00 2001 From: Shivam Malhotra Date: Mon, 20 Nov 2023 17:36:50 -0600 Subject: [PATCH] Added comments to explain offset field better --- .../parquet/base/ColumnPageReaderImpl.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/extensions/parquet/base/src/main/java/io/deephaven/parquet/base/ColumnPageReaderImpl.java b/extensions/parquet/base/src/main/java/io/deephaven/parquet/base/ColumnPageReaderImpl.java index c57acbb4964..d9c864900ea 100644 --- a/extensions/parquet/base/src/main/java/io/deephaven/parquet/base/ColumnPageReaderImpl.java +++ b/extensions/parquet/base/src/main/java/io/deephaven/parquet/base/ColumnPageReaderImpl.java @@ -54,11 +54,19 @@ public class ColumnPageReaderImpl implements ColumnPageReader { private final Path filePath; private final List fieldTypes; + /** + * Stores the offset from where the next byte should be read. Can be the offset of page header if + * {@link #pageHeader} is {@code null}, else will be the offset of data. + */ private long offset; private PageHeader pageHeader; private int numValues; private int rowCount = -1; + /** + * @param offset The offset for page header if supplied {@code pageHeader} is {@code null}. Else, the offset of data + * in the page. + */ ColumnPageReaderImpl(SeekableChannelsProvider channelsProvider, CompressorAdapter compressorAdapter, Supplier dictionarySupplier, @@ -108,9 +116,17 @@ public IntBuffer readKeyValues(IntBuffer keyDest, int nullPlaceholder) throws IO } } + /** + * If {@link #pageHeader} is {@code null}, read it from the file and increment the {@link #offset} and file position + * by the length of page header. This method assumes that file position is set to {@link #offset} before calling. + * This method also read the number of values in the page from the header. + */ private synchronized void ensurePageHeader(SeekableByteChannel file) throws IOException { if (pageHeader == null) { - offset = file.position(); + if (file.position() != offset) { + throw new IllegalStateException("File position = " + file.position() + " not equal to expected offset =" + + offset); + } int maxHeader = START_HEADER; boolean success; do {