Skip to content
Closed
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
11 changes: 9 additions & 2 deletions java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
44 changes: 44 additions & 0 deletions java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<x:int>");
// new column added on reader side
TypeDescription read = TypeDescription.fromString("struct<x:int,y:boolean>");
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<OrcProto.ColumnEncoding> 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");
Expand Down