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 @@ -230,11 +230,12 @@ protected Builder(InputFile file) {
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());
} else {
this.conf = new Configuration();
optionsBuilder = ParquetReadOptions.builder(new HadoopParquetConfiguration());
Fokko marked this conversation as resolved.
Show resolved Hide resolved
}
this.configuration = new HadoopParquetConfiguration(this.conf);
}

protected Builder(InputFile file, ParquetConfiguration conf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
@RunWith(Parameterized.class)
public class TestParquetReader {

private static final Path FILE_V1 = createTempFile();
private static final Path FILE_V2 = createTempFile();
public static final Path FILE_V1 = createTempFile();
joyCurry30 marked this conversation as resolved.
Show resolved Hide resolved
public static final Path FILE_V2 = createTempFile();
private static final Path STATIC_FILE_WITHOUT_COL_INDEXES =
createPathFromCP("/test-file-with-no-column-indexes-1.parquet");
private static final List<PhoneBookWriter.User> DATA = Collections.unmodifiableList(makeUsers(1000));
Expand Down
Loading