Skip to content
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

GH-2948: Fix NPE when using the AvroParquetReader.Builder with LocalInputFile #2949

Merged
merged 8 commits into from
Jul 17, 2024
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