Skip to content

Commit

Permalink
GH-2948: Fix NPE when using the AvroParquetReader.Builder with LocalI…
Browse files Browse the repository at this point in the history
…nputFile (#2949)
  • Loading branch information
joyCurry30 authored and Fokko committed Aug 15, 2024
1 parent af4307b commit c88a3f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
Expand Down Expand Up @@ -59,10 +60,13 @@
import org.apache.parquet.conf.HadoopParquetConfiguration;
import org.apache.parquet.conf.ParquetConfiguration;
import org.apache.parquet.conf.PlainParquetConfiguration;
import org.apache.parquet.example.data.Group;
import org.apache.parquet.hadoop.ParquetReader;
import org.apache.parquet.hadoop.ParquetWriter;
import org.apache.parquet.hadoop.api.WriteSupport;
import org.apache.parquet.hadoop.example.GroupReadSupport;
import org.apache.parquet.hadoop.util.HadoopCodecs;
import org.apache.parquet.io.InputFile;
import org.apache.parquet.io.LocalInputFile;
import org.apache.parquet.io.LocalOutputFile;
import org.apache.parquet.io.api.Binary;
Expand Down Expand Up @@ -919,6 +923,24 @@ public void testParsesDataModelFromConf() throws Exception {
Assert.assertEquals("Content should match", expected, records);
}

@Test
public void testConstructor() throws IOException {
String testFile =
URI.create(Resources.getResource("strings-2.parquet").getFile()).getRawPath();
InputFile inputFile = new LocalInputFile(Paths.get(testFile));
ParquetReader<Group> reader =
AvroParquetReader.<Group>builder(inputFile).build();
assertNotNull(reader);

reader = AvroParquetReader.<Group>builder(inputFile, new HadoopParquetConfiguration(new Configuration()))
.build();
assertNotNull(reader);

reader = AvroParquetReader.builder(new GroupReadSupport(), new Path(testFile))
.build();
assertNotNull(reader);
}

private File createTempFile() throws IOException {
File tmp = File.createTempFile(getClass().getSimpleName(), ".tmp");
tmp.deleteOnExit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,11 @@ protected Builder(InputFile file) {
this.path = null;
if (file instanceof HadoopInputFile) {
HadoopInputFile hadoopFile = (HadoopInputFile) file;
this.conf = hadoopFile.getConfiguration();
this.configuration = new HadoopParquetConfiguration(this.conf);
optionsBuilder = HadoopReadOptions.builder(this.conf, hadoopFile.getPath());
this.configuration = new HadoopParquetConfiguration(hadoopFile.getConfiguration());
} else {
optionsBuilder = ParquetReadOptions.builder(new HadoopParquetConfiguration());
this.configuration = new HadoopParquetConfiguration();
}
optionsBuilder = HadoopReadOptions.builder(this.configuration);
}

protected Builder(InputFile file, ParquetConfiguration conf) {
Expand Down

0 comments on commit c88a3f8

Please sign in to comment.