diff --git a/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java b/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java index 72c741890f..ebd8b7eff3 100644 --- a/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java +++ b/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java @@ -885,7 +885,8 @@ public SargApplier(SearchArgument sarg, this.rowIndexStride = rowIndexStride; // included will not be null, row options will fill the array with // trues if null - sargColumns = new boolean[evolution.getFileIncluded().length]; + sargColumns = new boolean[evolution.getPositionalColumns() + ? evolution.getReaderIncluded().length : evolution.getFileIncluded().length]; for (int i : filterColumns) { // filter columns may have -1 as index which could be partition // column in SARG. @@ -928,7 +929,13 @@ public boolean[] pickRowGroups(StripeInformation stripe, leafValues[pred] = exceptionAnswer[pred]; } else { if (indexes[columnIx] == null) { - throw new AssertionError("Index is not populated for " + columnIx); + // this can happen when using force positional evolution when the reader schema + // is aware of a new column which is not present in the file + if (LOG.isDebugEnabled()){ + LOG.debug("Index is not populated for {}, ignoring while evaluating sargs",columnIx); + } + leafValues[pred] = TruthValue.YES_NO_NULL; + continue; } OrcProto.RowIndexEntry entry = indexes[columnIx].getEntry(rowGroup); if (entry == null) { diff --git a/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java b/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java index d150750c58..83e43999ee 100644 --- a/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java +++ b/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java @@ -72,6 +72,7 @@ import org.apache.orc.TypeDescription; import org.apache.orc.Writer; import org.apache.orc.impl.RecordReaderImpl.Location; +import org.apache.orc.impl.RecordReaderImpl.SargApplier; import org.apache.hadoop.hive.ql.io.sarg.PredicateLeaf; import org.apache.hadoop.hive.ql.io.sarg.SearchArgument.TruthValue; import org.apache.hadoop.hive.serde2.io.DateWritable; @@ -2221,6 +2222,49 @@ public void testPickRowGroupsError() throws Exception { assertEquals(0, applier.getExceptionCount()[1]); } + @Test + public void testPositionalEvolutionAddColumnPPD() throws IOException { + Reader.Options opts = new Reader.Options(); + opts.forcePositionalEvolution(true); + + TypeDescription file = TypeDescription.fromString("struct"); + // new column added on reader side + TypeDescription read = TypeDescription.fromString("struct"); + opts.include(includeAll(read)); + + SchemaEvolution evo = new SchemaEvolution(file, read, opts); + + SearchArgument sarg = SearchArgumentFactory.newBuilder().startAnd() + .equals("y", PredicateLeaf.Type.BOOLEAN, true).end().build(); + + RecordReaderImpl.SargApplier applier = + new RecordReaderImpl.SargApplier(sarg, 1000, evo, OrcFile.WriterVersion.ORC_135, false); + + OrcProto.StripeInformation stripe = + OrcProto.StripeInformation.newBuilder().setNumberOfRows(2000).build(); + + OrcProto.RowIndex[] indexes = new OrcProto.RowIndex[3]; + indexes[1] = OrcProto.RowIndex.newBuilder() // index for original x column + .addEntry(createIndexEntry(0L, 10L)) + .addEntry(createIndexEntry(100L, 200L)) + .build(); + indexes[2] = null; // no-op, just for clarifying that new reader column doesn't have an index + + List encodings = new ArrayList<>(); + encodings.add(OrcProto.ColumnEncoding.newBuilder().setKind(OrcProto.ColumnEncoding.Kind.DIRECT).build()); + + boolean[] rows = applier.pickRowGroups(new ReaderImpl.StripeInformationImpl(stripe, 1, -1, null), + indexes, null, encodings, null, false); + assertEquals(SargApplier.READ_ALL_RGS, rows); //cannot filter for new column, return all rows + } + + private boolean[] includeAll(TypeDescription readerType) { + int numColumns = readerType.getMaximumId() + 1; + boolean[] result = new boolean[numColumns]; + Arrays.fill(result, true); + return result; + } + @Test public void testSkipDataReaderOpen() throws Exception { IOException ioe = new IOException("Don't open when there is no stripe");