Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1935,8 +1935,6 @@ public ColumnIndex readColumnIndex(ColumnChunkMetaData column) throws IOExceptio
if (ref == null) {
return null;
}
f.seek(ref.getOffset());

BlockCipher.Decryptor columnIndexDecryptor = null;
byte[] columnIndexAAD = null;
if (null != fileDecryptor && !fileDecryptor.plaintextFile()) {
Expand All @@ -1952,7 +1950,8 @@ public ColumnIndex readColumnIndex(ColumnChunkMetaData column) throws IOExceptio
}
}
return ParquetMetadataConverter.fromParquetColumnIndex(
column.getPrimitiveType(), Util.readColumnIndex(f, columnIndexDecryptor, columnIndexAAD));
column.getPrimitiveType(),
Util.readColumnIndex(openIndexStream(ref, columnIndexDecryptor), columnIndexDecryptor, columnIndexAAD));
}

/**
Expand All @@ -1967,8 +1966,6 @@ public OffsetIndex readOffsetIndex(ColumnChunkMetaData column) throws IOExceptio
if (ref == null) {
return null;
}
f.seek(ref.getOffset());

BlockCipher.Decryptor offsetIndexDecryptor = null;
byte[] offsetIndexAAD = null;
if (null != fileDecryptor && !fileDecryptor.plaintextFile()) {
Expand All @@ -1984,7 +1981,20 @@ public OffsetIndex readOffsetIndex(ColumnChunkMetaData column) throws IOExceptio
}
}
return ParquetMetadataConverter.fromParquetOffsetIndex(
Util.readOffsetIndex(f, offsetIndexDecryptor, offsetIndexAAD));
Util.readOffsetIndex(openIndexStream(ref, offsetIndexDecryptor), offsetIndexDecryptor, offsetIndexAAD));
}

private InputStream openIndexStream(IndexReference ref, BlockCipher.Decryptor decryptor) throws IOException {
f.seek(ref.getOffset());
int length = ref.getLength();
// Decryptors already read the serialized index into a buffer.
if (decryptor != null || length <= 0 || length > options.getMaxAllocationSize()) {
return f;
}
// Thrift makes many small reads. Fetch the serialized index in one range.
byte[] index = new byte[length];
f.readFully(index);
return new ByteArrayInputStream(index);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
import static org.apache.parquet.hadoop.ParquetFileWriter.Mode.OVERWRITE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
Expand All @@ -32,7 +39,9 @@
import org.apache.parquet.filter2.columnindex.RowRanges;
import org.apache.parquet.hadoop.example.ExampleParquetWriter;
import org.apache.parquet.hadoop.metadata.BlockMetaData;
import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
import org.apache.parquet.hadoop.util.HadoopInputFile;
import org.apache.parquet.io.SeekableInputStream;
import org.apache.parquet.schema.MessageType;
import org.apache.parquet.schema.MessageTypeParser;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -77,6 +86,30 @@ private ParquetFileReader openReader() throws IOException {
return ParquetFileReader.open(HadoopInputFile.fromPath(file, conf), options);
}

@Test
void readsPageIndexesWithoutSingleByteReads() throws IOException {
Configuration conf = new Configuration();
HadoopInputFile input = HadoopInputFile.fromPath(file, conf);
SeekableInputStream stream = spy(input.newStream());
try (ParquetFileReader reader =
ParquetFileReader.open(input, HadoopReadOptions.builder(conf).build(), stream)) {
ColumnChunkMetaData column =
reader.getRowGroups().get(0).getColumns().get(0);
clearInvocations(stream);

int pages = reader.readOffsetIndex(column).getPageCount();
assertThat(pages).isGreaterThan(1);
assertThat(stream.getPos())
.isEqualTo(column.getOffsetIndexReference().getOffset()
+ column.getOffsetIndexReference().getLength());
assertThat(reader.readColumnIndex(column).getNullPages()).hasSize(pages);
assertThat(stream.getPos())
.isEqualTo(column.getColumnIndexReference().getOffset()
+ column.getColumnIndexReference().getLength());
verify(stream, never()).read(any(byte[].class), anyInt(), eq(1));
}
}

@Test
public void getRowRangesWithoutFilterCoversAllRows() throws IOException {
try (ParquetFileReader reader = openReader()) {
Expand Down