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

Enabling avroParquet to read Int96 as bytes #12484

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.hadoop.fs.Path;
import org.apache.parquet.avro.AvroParquetReader;
import org.apache.parquet.avro.AvroParquetWriter;
import org.apache.parquet.avro.AvroReadSupport;
import org.apache.parquet.avro.AvroSchemaConverter;
import org.apache.parquet.format.converter.ParquetMetadataConverter;
import org.apache.parquet.hadoop.ParquetFileReader;
Expand Down Expand Up @@ -100,6 +101,8 @@ public static Configuration getParquetHadoopConfiguration() {
// in case that user's hadoop conf overwrite this item
Configuration conf = new Configuration();
conf.set("fs.defaultFS", DEFAULT_FS);
// To read Int96 as bytes.
conf.set(AvroReadSupport.READ_INT96_AS_FIXED, "true");
conf.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
return conf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,28 @@ public void testFileMetadataParsing()
@Test
public void testComparison()
throws IOException {
testComparison(_dataFile, SAMPLE_RECORDS_SIZE);
testComparison(new File(getClass().getClassLoader().getResource("users.parquet").getFile()), 1);
testComparison(new File(getClass().getClassLoader().getResource("test-comparison.gz.parquet").getFile()), 363667);
testComparison(new File(getClass().getClassLoader().getResource("test-comparison.snappy.parquet").getFile()), 2870);
testComparison(new File(getClass().getClassLoader().getResource("baseballStats.snappy.parquet").getFile()), 97889);
testComparison(new File(getClass().getClassLoader().getResource("baseballStats.zstd.parquet").getFile()), 97889);
testComparison(new File(getClass().getClassLoader().getResource("githubEvents.snappy.parquet").getFile()), 10000);
testComparison(new File(getClass().getClassLoader().getResource("starbucksStores.snappy.parquet").getFile()), 6443);
testComparison(new File(getClass().getClassLoader().getResource("airlineStats.snappy.parquet").getFile()), 19492);
testComparison(new File(getClass().getClassLoader().getResource("githubActivities.gz.parquet").getFile()), 2000);
testComparison(_dataFile, SAMPLE_RECORDS_SIZE, false);
testComparison(new File(getClass().getClassLoader().getResource("users.parquet").getFile()), 1, false);
testComparison(new File(getClass().getClassLoader().getResource("test-comparison.gz.parquet").getFile()), 363667,
false);
testComparison(new File(getClass().getClassLoader().getResource("test-comparison.snappy.parquet").getFile()), 2870,
false);
testComparison(new File(getClass().getClassLoader().getResource("baseballStats.snappy.parquet").getFile()), 97889,
false);
testComparison(new File(getClass().getClassLoader().getResource("baseballStats.zstd.parquet").getFile()), 97889,
false);
testComparison(new File(getClass().getClassLoader().getResource("githubEvents.snappy.parquet").getFile()), 10000,
false);
testComparison(new File(getClass().getClassLoader().getResource("starbucksStores.snappy.parquet").getFile()), 6443,
false);
testComparison(new File(getClass().getClassLoader().getResource("airlineStats.snappy.parquet").getFile()), 19492,
false);
testComparison(new File(getClass().getClassLoader().getResource("githubActivities.gz.parquet").getFile()), 2000,
false);
testComparison(new File(getClass().getClassLoader().getResource("int96AvroParquet.parquet").getFile()), 1, true);
}

private void testComparison(File dataFile, int totalRecords)
private void testComparison(File dataFile, int totalRecords, boolean skipIndividualRecordComparison)
throws IOException {
final ParquetRecordReader avroRecordReader = new ParquetRecordReader();
ParquetRecordReaderConfig avroRecordReaderConfig = new ParquetRecordReaderConfig();
Expand All @@ -150,14 +159,14 @@ private void testComparison(File dataFile, int totalRecords)
Assert.assertTrue(avroRecordReader.useAvroParquetRecordReader());
Assert.assertFalse(nativeRecordReader.useAvroParquetRecordReader());

testComparison(avroRecordReader, nativeRecordReader, totalRecords);
testComparison(avroRecordReader, nativeRecordReader, totalRecords, skipIndividualRecordComparison);
avroRecordReader.rewind();
nativeRecordReader.rewind();
testComparison(avroRecordReader, nativeRecordReader, totalRecords);
testComparison(avroRecordReader, nativeRecordReader, totalRecords, skipIndividualRecordComparison);
}

private void testComparison(ParquetRecordReader avroRecordReader, ParquetRecordReader nativeRecordReader,
int totalRecords)
int totalRecords, boolean skipIndividualRecordComparison)
throws IOException {
GenericRow avroReuse = new GenericRow();
GenericRow nativeReuse = new GenericRow();
Expand All @@ -166,8 +175,10 @@ private void testComparison(ParquetRecordReader avroRecordReader, ParquetRecordR
Assert.assertTrue(nativeRecordReader.hasNext());
final GenericRow avroReaderRow = avroRecordReader.next(avroReuse);
final GenericRow nativeReaderRow = nativeRecordReader.next(nativeReuse);
Assert.assertEquals(nativeReaderRow.toString(), avroReaderRow.toString());
Assert.assertTrue(avroReaderRow.equals(nativeReaderRow));
if (!skipIndividualRecordComparison) {
Assert.assertEquals(nativeReaderRow.toString(), avroReaderRow.toString());
Assert.assertTrue(avroReaderRow.equals(nativeReaderRow));
}
recordsRead++;
}
Assert.assertFalse(nativeRecordReader.hasNext());
Expand Down
Binary file not shown.
Loading