diff --git ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java index 0876bf7..0df82b9 100644 --- ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java +++ ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java @@ -2191,7 +2191,7 @@ static TruthValue evaluatePredicateRange(PredicateLeaf predicate, Object minValu if (sarg == null || rowIndexStride == 0) { return null; } - readRowIndex(); + readRowIndex(currentStripe); long rowsInStripe = stripes.get(currentStripe).getNumberOfRows(); int groupsInStripe = (int) ((rowsInStripe + rowIndexStride - 1) / rowIndexStride); @@ -2785,8 +2785,18 @@ private int findStripe(long rowNumber) { throw new IllegalArgumentException("Seek after the end of reader range"); } - private void readRowIndex() throws IOException { - long offset = stripes.get(currentStripe).getOffset(); + OrcProto.RowIndex[] readRowIndex(int stripeIndex) throws IOException { + long offset = stripes.get(stripeIndex).getOffset(); + OrcProto.StripeFooter stripeFooter; + OrcProto.RowIndex[] indexes; + // if this is the current stripe, use the cached objects. + if (stripeIndex == currentStripe) { + stripeFooter = this.stripeFooter; + indexes = this.indexes; + } else { + stripeFooter = readStripeFooter(stripes.get(stripeIndex)); + indexes = new OrcProto.RowIndex[this.indexes.length]; + } for(OrcProto.Stream stream: stripeFooter.getStreamsList()) { if (stream.getKind() == OrcProto.Stream.Kind.ROW_INDEX) { int col = stream.getColumn(); @@ -2801,6 +2811,7 @@ private void readRowIndex() throws IOException { } offset += stream.getLength(); } + return indexes; } private void seekToRowEntry(int rowEntry) throws IOException { @@ -2832,7 +2843,7 @@ public void seekToRow(long rowNumber) throws IOException { currentStripe = rightStripe; readStripe(); } - readRowIndex(); + readRowIndex(currentStripe); // if we aren't to the right row yet, advanance in the stripe. advanceToNextRow(rowNumber); diff --git ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcFile.java ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcFile.java index 9247bc3..03fc705 100644 --- ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcFile.java +++ ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcFile.java @@ -601,6 +601,23 @@ public void testStripeLevelStats() throws Exception { assertEquals(14988, ((StringColumnStatistics)ss1.getColumnStatistics()[2]).getSum()); assertEquals(15000, ((StringColumnStatistics)ss2.getColumnStatistics()[2]).getSum()); assertEquals(5012, ((StringColumnStatistics)ss3.getColumnStatistics()[2]).getSum()); + + RecordReaderImpl recordReader = (RecordReaderImpl) reader.rows(null); + OrcProto.RowIndex[] index = recordReader.readRowIndex(0); + assertEquals(3, index.length); + List items = index[1].getEntryList(); + assertEquals(1, items.size()); + assertEquals(3, items.get(0).getPositionsCount()); + assertEquals(0, items.get(0).getPositions(0)); + assertEquals(0, items.get(0).getPositions(1)); + assertEquals(0, items.get(0).getPositions(2)); + assertEquals(1, + items.get(0).getStatistics().getIntStatistics().getMinimum()); + index = recordReader.readRowIndex(1); + assertEquals(3, index.length); + items = index[1].getEntryList(); + assertEquals(2, + items.get(0).getStatistics().getIntStatistics().getMaximum()); } @Test