Skip to content
Closed
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 @@ -729,6 +729,21 @@ public static ParquetFileReader open(InputFile file, ParquetReadOptions options,
return new ParquetFileReader(file, options, f);
}

/**
* Open a {@link InputFile file} with {@link ParquetMetadata footer} and {@link ParquetReadOptions options}.
*
* @param file an input file
* @param footer a {@link ParquetMetadata} footer already read from the file
* @param options parquet read options
* @param f the input stream for the file
* @return an open ParquetFileReader
* @throws IOException if there is an error while opening the file
*/
public static ParquetFileReader open(InputFile file, ParquetMetadata footer, ParquetReadOptions options, SeekableInputStream f)
throws IOException {
return new ParquetFileReader(file, footer, options, f);
}

protected SeekableInputStream f;
private final InputFile file;
private final ParquetReadOptions options;
Expand Down Expand Up @@ -930,6 +945,12 @@ public ParquetFileReader(InputFile file, ParquetReadOptions options) throws IOEx
this(file, options, file.newStream());
}

/**
* @param file Path to a parquet file
* @param options {@link ParquetReadOptions}
* @param f a {@link SeekableInputStream} for the parquet file
* @throws IOException if the file can not be opened
*/
public ParquetFileReader(InputFile file, ParquetReadOptions options, SeekableInputStream f) throws IOException {
this.converter = new ParquetMetadataConverter(options);
this.file = file;
Expand All @@ -943,6 +964,51 @@ public ParquetFileReader(InputFile file, ParquetReadOptions options, SeekableInp
f.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f.close();
// In case that reading footer throws an exception in the constructor, the new stream
// should be closed. Otherwise, there's no way to close this outside.
f.close();

Please keep its original comment

throw e;
}

this.fileMetaData = footer.getFileMetaData();
this.fileDecryptor = fileMetaData.getFileDecryptor(); // must be called before filterRowGroups!
if (null != fileDecryptor && fileDecryptor.plaintextFile()) {
this.fileDecryptor = null; // Plaintext file. No need in decryptor
}

try {
this.blocks = filterRowGroups(footer.getBlocks());
} catch (Exception e) {
// In case that filterRowGroups throws an exception in the constructor, the new stream
// should be closed. Otherwise, there's no way to close this outside.
f.close();
throw e;
}
this.blockIndexStores = listWithNulls(this.blocks.size());
this.blockRowRanges = listWithNulls(this.blocks.size());
for (ColumnDescriptor col : footer.getFileMetaData().getSchema().getColumns()) {
paths.put(ColumnPath.get(col.getPath()), col);
}

if (options.usePageChecksumVerification()) {
this.crc = new CRC32();
this.crcAllocator = ReusingByteBufferAllocator.strict(options.getAllocator());
} else {
this.crc = null;
this.crcAllocator = null;
}
}

/**
* @param file Path to a parquet file
* @param footer a {@link ParquetMetadata} footer already read from the file
* @param options {@link ParquetReadOptions}
* @param f a {@link SeekableInputStream} for the parquet file
* @throws IOException if the file can not be opened
*/
public ParquetFileReader(InputFile file, ParquetMetadata footer, ParquetReadOptions options, SeekableInputStream f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a javadoc for this new method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the corresponding static open method together

throws IOException {
this.converter = new ParquetMetadataConverter(options);
this.file = file;
this.f = f;
this.options = options;
this.footer = footer;

this.fileMetaData = footer.getFileMetaData();
this.fileDecryptor = fileMetaData.getFileDecryptor(); // must be called before filterRowGroups!
if (null != fileDecryptor && fileDecryptor.plaintextFile()) {
Expand Down
Loading