-
Notifications
You must be signed in to change notification settings - Fork 1.6k
GH-3141: Add constructor to ParquetFileReader to allow passing in parquet footer #3165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
69b63ca
3d82937
f1b9b01
56197e3
cce9f1f
0e88c9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||||||
|
|
@@ -930,19 +945,70 @@ 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; | ||||||||||
| this.f = f; | ||||||||||
| this.options = options; | ||||||||||
| try { | ||||||||||
| this.footer = readFooter(file, options, f, converter); | ||||||||||
| } catch (Exception e) { | ||||||||||
| } catch (IOException e) { | ||||||||||
| // 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(); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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) | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a javadoc for this new method?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the corresponding |
||||||||||
| 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()) { | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was not intentional. thanks for catching it.