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

ORC-1146: Float category missing check if the statistic sum is a finite value #1078

Merged
merged 1 commit into from
Apr 5, 2022
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
3 changes: 2 additions & 1 deletion java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ static TruthValue evaluatePredicateProto(OrcProto.ColumnStatistics statsProto,
" include ORC-517. Writer version: {}",
predicate.getColumnName(), writerVersion);
return TruthValue.YES_NO_NULL;
} else if (category == TypeDescription.Category.DOUBLE) {
} else if (category == TypeDescription.Category.DOUBLE
|| category == TypeDescription.Category.FLOAT) {
DoubleColumnStatistics dstas = (DoubleColumnStatistics) cs;
if (!Double.isFinite(dstas.getSum())) {
LOG.debug("Not using predication pushdown on {} because stats contain NaN values",
Expand Down
31 changes: 30 additions & 1 deletion java/core/src/test/org/apache/orc/TestVectorOrcFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -4070,7 +4070,8 @@ public void testPredicatePushdownForComplex() throws Exception {
@Test
public void testPredicatePushdownWithNan() throws Exception {
TypeDescription schema = TypeDescription.createStruct()
.addField("double1", TypeDescription.createDouble());
.addField("double1", TypeDescription.createDouble())
.addField("float1", TypeDescription.createFloat());

Writer writer = OrcFile.createWriter(testFilePath,
OrcFile.writerOptions(conf)
Expand All @@ -4084,14 +4085,18 @@ public void testPredicatePushdownWithNan() throws Exception {
batch.ensureSize(3500);
batch.size = 3500;
batch.cols[0].noNulls = true;
batch.cols[1].noNulls = true;

DoubleColumnVector dbcol = ((DoubleColumnVector) batch.cols[0]);
DoubleColumnVector fcol = ((DoubleColumnVector) batch.cols[1]);

// first row NaN (resulting to min/max and sum columnStats of stride to be NaN)
// NaN in the middle of a stride causes Sum of last stride to be NaN
dbcol.vector[0] = Double.NaN;
fcol.vector[0] = Double.NaN;
for (int i=1; i < 3500; ++i) {
dbcol.vector[i] = i == 3200 ? Double.NaN : i;
fcol.vector[i] = i == 3200 ? Double.NaN : i;
}
writer.addRowBatch(batch);
writer.close();
Expand All @@ -4101,6 +4106,7 @@ public void testPredicatePushdownWithNan() throws Exception {
assertEquals(3500, reader.getNumberOfRows());

// Only the first stride matches the predicate, just need to make sure NaN stats are ignored
// Test double category push down
SearchArgument sarg = SearchArgumentFactory.newBuilder()
.startAnd()
.lessThan("double1", PredicateLeaf.Type.FLOAT, 100d)
Expand All @@ -4122,6 +4128,29 @@ public void testPredicatePushdownWithNan() throws Exception {

rows.nextBatch(batch);
assertEquals(0, batch.size);

// Test float category push down
sarg = SearchArgumentFactory.newBuilder()
.startAnd()
.lessThan("float1", PredicateLeaf.Type.FLOAT, 100d)
.end()
.build();

rows = reader.rows(reader.options()
.range(0L, Long.MAX_VALUE)
.searchArgument(sarg, new String[]{"float1"}));
batch = reader.getSchema().createRowBatch(3500);

rows.nextBatch(batch);
// First stride should be read as NaN sum is ignored
assertEquals(1000, batch.size);

rows.nextBatch(batch);
// Last stride should be read as NaN sum is ignored
assertEquals(500, batch.size);

rows.nextBatch(batch);
assertEquals(0, batch.size);
}

/**
Expand Down