Skip to content

Commit 73a4430

Browse files
authored
PARQUET-3031: Support to transfer input stream when building ParquetFileReader (#3030)
1 parent 42cf31c commit 73a4430

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileReader.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,20 @@ public static ParquetFileReader open(InputFile file, ParquetReadOptions options)
710710
return new ParquetFileReader(file, options);
711711
}
712712

713+
/**
714+
* Open a {@link InputFile file} with {@link ParquetReadOptions options}.
715+
*
716+
* @param file an input file
717+
* @param options parquet read options
718+
* @param f the input stream for the file
719+
* @return an open ParquetFileReader
720+
* @throws IOException if there is an error while opening the file
721+
*/
722+
public static ParquetFileReader open(InputFile file, ParquetReadOptions options, SeekableInputStream f)
723+
throws IOException {
724+
return new ParquetFileReader(file, options, f);
725+
}
726+
713727
protected final SeekableInputStream f;
714728
private final InputFile file;
715729
private final ParquetReadOptions options;
@@ -863,9 +877,23 @@ public ParquetFileReader(Configuration conf, Path file, ParquetMetadata footer)
863877
*/
864878
public ParquetFileReader(Configuration conf, Path file, ParquetMetadata footer, ParquetReadOptions options)
865879
throws IOException {
880+
this(conf, file, footer, options, HadoopInputFile.fromPath(file, conf).newStream());
881+
}
882+
883+
/**
884+
* @param conf the Hadoop Configuration
885+
* @param file Path to a parquet file
886+
* @param footer a {@link ParquetMetadata} footer already read from the file
887+
* @param options {@link ParquetReadOptions}
888+
* @param f a {@link SeekableInputStream} for the parquet file
889+
* @throws IOException if the file can not be opened
890+
*/
891+
public ParquetFileReader(
892+
Configuration conf, Path file, ParquetMetadata footer, ParquetReadOptions options, SeekableInputStream f)
893+
throws IOException {
866894
this.converter = new ParquetMetadataConverter(conf);
867895
this.file = HadoopInputFile.fromPath(file, conf);
868-
this.f = this.file.newStream();
896+
this.f = f;
869897
this.fileMetaData = footer.getFileMetaData();
870898
this.fileDecryptor = fileMetaData.getFileDecryptor();
871899
this.options = options;
@@ -894,9 +922,13 @@ public ParquetFileReader(Configuration conf, Path file, ParquetMetadata footer,
894922
}
895923

896924
public ParquetFileReader(InputFile file, ParquetReadOptions options) throws IOException {
925+
this(file, options, file.newStream());
926+
}
927+
928+
public ParquetFileReader(InputFile file, ParquetReadOptions options, SeekableInputStream f) throws IOException {
897929
this.converter = new ParquetMetadataConverter(options);
898930
this.file = file;
899-
this.f = file.newStream();
931+
this.f = f;
900932
this.options = options;
901933
try {
902934
this.footer = readFooter(file, options, f, converter);

0 commit comments

Comments
 (0)