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-1147: Use isNaN instead of isFinite to determine the contain NaN values #1080

Closed
wants to merge 2 commits into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -696,7 +696,7 @@ static TruthValue evaluatePredicateProto(OrcProto.ColumnStatistics statsProto,
} else if (category == TypeDescription.Category.DOUBLE
|| category == TypeDescription.Category.FLOAT) {
DoubleColumnStatistics dstas = (DoubleColumnStatistics) cs;
if (!Double.isFinite(dstas.getSum())) {
if (Double.isNaN(dstas.getSum())) {
LOG.debug("Not using predication pushdown on {} because stats contain NaN values",
predicate.getColumnName());
return dstas.hasNull() ? TruthValue.YES_NO_NULL : TruthValue.YES_NO;
Expand Down
90 changes: 90 additions & 0 deletions java/core/src/test/org/apache/orc/TestVectorOrcFile.java
Expand Up @@ -4384,6 +4384,96 @@ public void testPredicatePushdownWithNan(Version fileFormat) throws Exception {
assertEquals(0, batch.size);
}

@ParameterizedTest
@MethodSource("data")
public void testPredicatePushdownWithSumOverflow(Version fileFormat) throws Exception {
TypeDescription schema = TypeDescription.createStruct()
.addField("double1", TypeDescription.createDouble())
.addField("float1", TypeDescription.createFloat());

Writer writer = OrcFile.createWriter(testFilePath,
OrcFile.writerOptions(conf)
.setSchema(schema)
.stripeSize(400000L)
.compress(CompressionKind.NONE)
.bufferSize(500)
.rowIndexStride(1000)
.version(fileFormat));
VectorizedRowBatch batch = schema.createRowBatch();
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]);

double largeNumber = Double.MAX_VALUE / 2 + Double.MAX_VALUE / 4;

// Here we are writing 3500 rows of data, with stripeSize set to 400000
// and rowIndexStride set to 1000, so 1 stripe will be written,
// indexed in 4 strides.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the details.

// Two large values are written in the first and fourth strides,
// causing the statistical sum to overflow, sum is not a finite value,
// but this does not prevent pushing down (range comparisons work fine)
fcol.vector[0] = dbcol.vector[0] = largeNumber;
fcol.vector[1] = dbcol.vector[1] = largeNumber;
for (int i=2; i < 3500; ++i) {
if (i >= 3200 && i<= 3201) {
fcol.vector[i] = dbcol.vector[i] = largeNumber;
} else {
dbcol.vector[i] = i;
fcol.vector[i] = i;
}
}
writer.addRowBatch(batch);
writer.close();

Reader reader = OrcFile.createReader(testFilePath,
OrcFile.readerOptions(conf).filesystem(fs));
assertEquals(3500, reader.getNumberOfRows());

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

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

rows.nextBatch(batch);
// First stride should be read
assertEquals(1000, batch.size);

rows.nextBatch(batch);
// Last stride should not be read, even if sum is not finite
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
dongjoon-hyun marked this conversation as resolved.
Show resolved Hide resolved
assertEquals(1000, batch.size);

rows.nextBatch(batch);
// Last stride should not be read, even if sum is not finite
assertEquals(0, batch.size);
}

/**
* Test predicate pushdown on nulls, with different combinations of
* values and nulls.
Expand Down