From 4688930466fb9256e590e178ea600e7de1e23f4d Mon Sep 17 00:00:00 2001 From: Alex Levenson Date: Wed, 15 Jul 2015 20:31:19 -0700 Subject: [PATCH 1/2] Fix ArrayIndexOutOfBounds in checkDeltaByteArrayProblem --- .../java/org/apache/parquet/hadoop/ParquetRecordReader.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetRecordReader.java b/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetRecordReader.java index 0a31f9caaf..1558fc03bb 100644 --- a/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetRecordReader.java +++ b/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetRecordReader.java @@ -193,7 +193,9 @@ private void initializeInternalReader(ParquetInputSplit split, Configuration con } } - checkDeltaByteArrayProblem(footer.getFileMetaData(), configuration, filteredBlocks.get(0)); + if (!filteredBlocks.isEmpty()) { + checkDeltaByteArrayProblem(footer.getFileMetaData(), configuration, filteredBlocks.get(0)); + } MessageType fileSchema = footer.getFileMetaData().getSchema(); internalReader.initialize( From ce1f81e74ba992d488764d94765e3b3c472a718b Mon Sep 17 00:00:00 2001 From: Alex Levenson Date: Thu, 16 Jul 2015 16:11:12 -0700 Subject: [PATCH 2/2] Add tests --- .../hadoop/example/TestInputOutputFormat.java | 71 ++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/example/TestInputOutputFormat.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/example/TestInputOutputFormat.java index 80c43810b0..987554e7c5 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/example/TestInputOutputFormat.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/example/TestInputOutputFormat.java @@ -28,8 +28,12 @@ import java.io.FileReader; import java.io.IOException; import java.lang.reflect.Method; +import java.nio.charset.Charset; +import java.nio.file.Files; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; @@ -44,6 +48,8 @@ import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; +import org.apache.parquet.Strings; +import org.apache.parquet.filter2.predicate.FilterApi; import org.junit.Before; import org.junit.Test; @@ -139,8 +145,6 @@ protected void setup(org.apache.hadoop.mapreduce.Mapper.Context context) throws java.io.IOException, InterruptedException { Group group = factory.newGroup() .append("line", (int) key.get()) @@ -238,6 +242,69 @@ public void testReadWriteTaskSideMD() throws IOException, ClassNotFoundException testReadWrite(CompressionCodecName.UNCOMPRESSED, new HashMap() {{ put("parquet.task.side.metadata", "true"); }}); } + /** + * Uses a filter that drops all records to test handling of tasks (mappers) that need to do no work at all + */ + @Test + public void testReadWriteTaskSideMDAggressiveFilter() throws IOException, ClassNotFoundException, InterruptedException { + Configuration conf = new Configuration(); + + // this filter predicate should trigger row group filtering that drops all row-groups + ParquetInputFormat.setFilterPredicate(conf, FilterApi.eq(FilterApi.intColumn("line"), -1000)); + final String fpString = conf.get(ParquetInputFormat.FILTER_PREDICATE); + + runMapReduceJob(CompressionCodecName.UNCOMPRESSED, new HashMap() {{ + put("parquet.task.side.metadata", "true"); + put(ParquetInputFormat.FILTER_PREDICATE, fpString); + }}); + + List lines = Files.readAllLines(new File(outputPath.toString(), "part-m-00000").toPath(), Charset.forName("UTF-8")); + assertTrue(lines.isEmpty()); + } + + @Test + public void testReadWriteFilter() throws IOException, ClassNotFoundException, InterruptedException { + Configuration conf = new Configuration(); + + // this filter predicate should keep some records but not all (first 500 characters) + // "line" is actually position in the file... + ParquetInputFormat.setFilterPredicate(conf, FilterApi.lt(FilterApi.intColumn("line"), 500)); + final String fpString = conf.get(ParquetInputFormat.FILTER_PREDICATE); + + runMapReduceJob(CompressionCodecName.UNCOMPRESSED, new HashMap() {{ + put("parquet.task.side.metadata", "true"); + put(ParquetInputFormat.FILTER_PREDICATE, fpString); + }}); + + List expected = Files.readAllLines(new File(inputPath.toString()).toPath(), Charset.forName("UTF-8")); + + // grab the lines that contain the first 500 characters (including the rest of the line past 500 characters) + int size = 0; + Iterator iter = expected.iterator(); + while(iter.hasNext()) { + String next = iter.next(); + + if (size < 500) { + size += next.length(); + continue; + } + + iter.remove(); + } + + // put the output back into it's original format (remove the character counts / tabs) + List found = Files.readAllLines(new File(outputPath.toString(), "part-m-00000").toPath(), Charset.forName("UTF-8")); + StringBuilder sbFound = new StringBuilder(); + for (String line : found) { + sbFound.append(line.split("\t", -1)[1]); + sbFound.append("\n"); + } + + sbFound.deleteCharAt(sbFound.length() - 1); + + assertEquals(Strings.join(expected, "\n"), sbFound.toString()); + } + @Test public void testProjection() throws Exception{ readSchema=partialSchema;