Repository navigation
Conversation
paimon writes DATE values as proleptic Gregorian epoch days, but the ORC files carry no calendar marker, so ORC reads the DATE statistics of a file on the hybrid Julian/Gregorian calendar. Before the switchover the two calendars differ by several days, so the statistics of a file holding 1200-06-15 look like 1200-06-08 and a pushed-down `=`, `>=` or `IN` predicate prunes the file even though it matches. `<=` happens to keep it, which is why the query result depends on the operator. Pushdown is an optimization only, so skip it for DATE literals before 1582-10-15 and let the engine evaluate them against the rows. Refs apache#11576
Akash3121
left a comment
There was a problem hiding this comment.
LGTM, added optional nitpicks
| new PredicateBuilder(ROW_TYPE) | ||
| .in(1, Arrays.asList((int) ancient.toEpochDay(), 20000)); | ||
| assertThat(readMatching(predicate, ancient)).isEqualTo(1); | ||
| } |
There was a problem hiding this comment.
PredicateBuilder#in(int, List) rewrites literal lists of size <= 20 into an OR chain of Equal predicates, so a 2-element list exercises visitEqual + visitOr rather than OrcPredicateFunctionVisitor#visitIn (the test would still pass even without the beforeGregorianSwitchover check in visitIn).
To exercise visitIn directly, could we either pass > 20 literals to PredicateBuilder#in (e.g., via IntStream.rangeClosed(20000, 20020)) or construct a LeafPredicate with In.INSTANCE?
There was a problem hiding this comment.
Good catch, you are right: PredicateBuilder#in keeps only lists longer than 20 literals as an In leaf, so my two-element list was compiled into OR(Equal, Equal) and visitIn was never called.
The test now builds 20000..20020 (21 literals) and asserts the visitor output is an OrcFilters.In, which pins that the IN path is the one under test. A second predicate adds the ancient day to that list, asserts the whole pushdown is declined, and still expects both matching rows back from the reader.
Verified by mutation: with beforeGregorianSwitchover forced to false, this test now fails (it passed before this change).
| assertThat(readMatching(equal(ancient), ancient)).isEqualTo(1); | ||
| assertThat(readMatching(equal(recent), ancient)).isZero(); | ||
| assertThat(readMatching(equal(recent), recent)).isEqualTo(1); | ||
| } |
There was a problem hiding this comment.
Since readMatching also applies predicate.test(row) in Java after reading, these assertions would still pass even if OrcPredicateFunctionVisitor declined pushdown for all dates. Could we also assert on the visitor output around the exact switchover boundary so the threshold is pinned?
assertThat(equal(LocalDate.of(1582, 10, 14)).visit(OrcPredicateFunctionVisitor.VISITOR))
.isEmpty();
assertThat(equal(LocalDate.of(1582, 10, 15)).visit(OrcPredicateFunctionVisitor.VISITOR))
.isPresent();There was a problem hiding this comment.
Agreed, the row counts alone do not prove anything about pushdown since readMatching re-applies predicate.test(row) after the read.
Added testPushdownIsDeclinedOnlyBeforeTheSwitchover with exactly the boundary assertions you suggested: 1582-10-14 → Optional.empty(), 1582-10-15 → present. Both directions are mutation-checked now — forcing the predicate to false fails 4/4 tests, forcing it to true (declining every DATE literal, the case your first comment describes as passing silently) fails the new boundary test and the OrcFilters.In assertion.
… boundary The previous in-list case passed a two-element list, but PredicateBuilder#in rewrites lists of at most 20 literals into an OR chain of equals, so visitIn was never reached. Building the list from 20000 to 20020 keeps it above that limit, and asserting the visitor output is an OrcFilters.In pins that the IN path is the one under test. readMatching also applies predicate.test(row) after reading, so the row-count assertions hold even when pushdown is declined. Assert on the visitor output around the boundary as well: 1582-10-14 is declined, 1582-10-15 is pushed down.
Purpose
Linked issue: #11576
A pushed-down DATE filter on an ORC table drops rows that match it, but only for dates before
1582-10-15 and only for some operators.
Root cause
OrcPredicateFunctionVisitorbuilds the literal withDate.valueOf(LocalDate.ofEpochDay(...)).The problem is on the statistics side, not in the literal: paimon writes DATE values as proleptic
Gregorian epoch days, but the ORC files carry no calendar marker, so
ReaderImplfalls back tothe hybrid Julian/Gregorian calendar when it converts the DATE column statistics
(
writerUsedProlepticGregorian()is false for these files).Dumping the statistics of a file that holds
1200-06-15shows the stored day is already correct(
-281071) but is read back asHybrid AD 1200-06-08, so the file looks like it only coversearlier dates and
=,>=andINprune it.<=keeps the file, which is why the queryresult depended on the operator.
Setting
WriterOptions#setProlepticGregorian(true)does not fix it here: paimon writes datesthrough a plain
LongColumnVector, so the calendar conversion that the writer applies with thatflag would move the stored day in the other direction.
Fix
Pushdown is only an optimization, so decline it for DATE literals before 1582-10-15 and leave the
predicate to the engine, the same way the existing
signedZeroPushdownguard declines±0.0.Dates on or after the switchover still push down unchanged.
Tests
New
OrcDatePredicateTestwrites real ORC files throughOrcFileFormatand reads them back theway the engine does (push down what ORC accepts, then apply the predicate to the returned rows).
It covers
=,>=,<=,<andINon a pre-switchover date, and=on a modern date.Without the fix all three tests fail (
expected: 1 but was: 0); with it they pass.