Skip to content
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
10 changes: 6 additions & 4 deletions java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,19 +480,20 @@ static TruthValue evaluatePredicateProto(OrcProto.ColumnStatistics statsProto,
OrcFile.WriterVersion writerVersion,
TypeDescription type) {
return evaluatePredicateProto(statsProto, predicate, kind, encoding, bloomFilter,
writerVersion, type, false);
writerVersion, type, true, false);
}

/**
* Evaluate a predicate with respect to the statistics from the column
* that is referenced in the predicate.
* Includes option to specify if timestamp column stats values
* should be in UTC.
* should be in UTC and if the file writer used proleptic Gregorian calendar.
* @param statsProto the statistics for the column mentioned in the predicate
* @param predicate the leaf predicate we need to evaluation
* @param bloomFilter the bloom filter
* @param writerVersion the version of software that wrote the file
* @param type what is the kind of this column
* @param writerUsedProlepticGregorian file written using the proleptic Gregorian calendar
* @param useUTCTimestamp
* @return the set of truth values that may be returned for the given
* predicate.
Expand All @@ -505,8 +506,9 @@ static TruthValue evaluatePredicateProto(OrcProto.ColumnStatistics statsProto,
OrcProto.BloomFilter bloomFilter,
OrcFile.WriterVersion writerVersion,
TypeDescription type,
boolean writerUsedProlepticGregorian,
boolean useUTCTimestamp) {
ColumnStatistics cs = ColumnStatisticsImpl.deserialize(null, statsProto);
ColumnStatistics cs = ColumnStatisticsImpl.deserialize(null, statsProto, writerUsedProlepticGregorian, true);
ValueRange range = getValueRange(cs, predicate, useUTCTimestamp);

// files written before ORC-135 stores timestamp wrt to local timezone causing issues with PPD.
Expand Down Expand Up @@ -1031,7 +1033,7 @@ public boolean[] pickRowGroups(StripeInformation stripe,
predicate, bfk, encodings.get(columnIx), bf,
writerVersion, evolution.getFileSchema().
findSubtype(columnIx),
useUTCTimestamp);
writerUsedProlepticGregorian, useUTCTimestamp);
} catch (Exception e) {
exceptionCount[pred] += 1;
if (e instanceof SargCastException) {
Expand Down
54 changes: 52 additions & 2 deletions java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,22 @@ static TruthValue evaluateTimestamp(OrcProto.ColumnStatistics stats,
return RecordReaderImpl.evaluatePredicateProto(stats, predicate, null,
encoding, null,
include135 ? OrcFile.WriterVersion.ORC_135: OrcFile.WriterVersion.ORC_101,
TypeDescription.createTimestamp(), useUTCTimestamp);
TypeDescription.createTimestamp(), true, useUTCTimestamp);
}

static TruthValue evaluateTimestampWithWriterCalendar(OrcProto.ColumnStatistics stats,
PredicateLeaf predicate,
boolean include135,
boolean writerUsedProlepticGregorian,
boolean useUTCTimestamp) {
OrcProto.ColumnEncoding encoding =
OrcProto.ColumnEncoding.newBuilder()
.setKind(OrcProto.ColumnEncoding.Kind.DIRECT)
.build();
return RecordReaderImpl.evaluatePredicateProto(stats, predicate, null,
encoding, null,
include135 ? OrcFile.WriterVersion.ORC_135: OrcFile.WriterVersion.ORC_101,
TypeDescription.createTimestamp(), writerUsedProlepticGregorian, useUTCTimestamp);
}

static TruthValue evaluateTimestampBloomfilter(OrcProto.ColumnStatistics stats,
Expand All @@ -616,7 +631,7 @@ static TruthValue evaluateTimestampBloomfilter(OrcProto.ColumnStatistics stats,
BloomFilterIO.serialize(builder, bloom);
return RecordReaderImpl.evaluatePredicateProto(stats, predicate, kind,
encoding.build(), builder.build(), version,
TypeDescription.createTimestamp(), useUTCTimestamp);
TypeDescription.createTimestamp(), true, useUTCTimestamp);
}

@Test
Expand Down Expand Up @@ -895,6 +910,41 @@ public void testPredEvalWithDecimalStats() throws Exception {
evaluateInteger(createDecimalStats("10.0", "100.0"), pred));
}

@Test
public void testPredEvalTimestampStatsDiffWriter() {
// Proleptic - NoUTC
PredicateLeaf pred = createPredicateLeaf(
PredicateLeaf.Operator.NULL_SAFE_EQUALS, PredicateLeaf.Type.TIMESTAMP, "x",
Timestamp.valueOf("1017-01-01 00:00:00"), null);
assertEquals(TruthValue.YES_NO,
evaluateTimestampWithWriterCalendar(createTimestampStats("1017-01-01 00:00:00", "1017-01-01 00:00:00"),
pred, true, true, false));

// NoProleptic - NoUTC -> 1016-12-26 00:00:00.0
long predTime = DateUtils.convertTimeToProleptic(Timestamp.valueOf("1017-01-01 00:00:00").getTime(), false);
PredicateLeaf pred2 = createPredicateLeaf(
PredicateLeaf.Operator.NULL_SAFE_EQUALS, PredicateLeaf.Type.TIMESTAMP, "x", new Timestamp(predTime), null);
assertEquals(TruthValue.YES_NO,
evaluateTimestampWithWriterCalendar(createTimestampStats("1017-01-01 00:00:00", "1017-01-01 00:00:00"),
pred2, true, false, false));

// NoProleptic - UTC -> 1016-12-25 16:00:00.0
predTime = DateUtils.convertTimeToProleptic(getUtcTimestamp("1017-01-01 00:00:00"), true);
PredicateLeaf pred3 = createPredicateLeaf(
PredicateLeaf.Operator.NULL_SAFE_EQUALS, PredicateLeaf.Type.TIMESTAMP, "x", new Timestamp(predTime), null);
assertEquals(TruthValue.YES_NO,
evaluateTimestampWithWriterCalendar(createTimestampStats("1017-01-01 00:00:00", "1017-01-01 00:00:00"),
pred3, true, false, true));

// Proleptic - UTC -> 1016-12-31 16:00:00.0
predTime = getUtcTimestamp("1017-01-01 00:00:00");
PredicateLeaf pred4 = createPredicateLeaf(PredicateLeaf.Operator.NULL_SAFE_EQUALS,
PredicateLeaf.Type.TIMESTAMP, "x", new Timestamp(predTime), null);
assertEquals(TruthValue.YES_NO,
evaluateTimestampWithWriterCalendar(createTimestampStats("1017-01-01 00:00:00", "1017-01-01 00:00:00"),
pred4, true, true, true));
}

@Test
public void testPredEvalWithTimestampStats() throws Exception {
PredicateLeaf pred = createPredicateLeaf(
Expand Down