Yaoxuan Wu created FLINK-41750:
----------------------------------

             Summary: ORC filter push-down drops rows with a DATE before 
1582-10-15 (OrcFilters converts the literal with java.sql.Date)
                 Key: FLINK-41750
                 URL: https://issues.apache.org/jira/browse/FLINK-41750
             Project: Flink
          Issue Type: Bug
          Components: Formats (JSON, Avro, Parquet, ORC, SequenceFile)
            Reporter: Yaoxuan Wu
             Fix For: 2.3.0


A filter on a DATE column that is pushed into an ORC filesystem source drops 
rows whose date is before 1582-10-15. No error is raised; the rows are silently 
missing.

{code:sql}
CREATE TABLE t (k INT, d DATE) WITH ('connector' = 'filesystem', 'path' = 
'file:///tmp/t', 'format' = 'orc');
INSERT INTO t VALUES (1, DATE '0763-07-15');

SELECT k FROM t WHERE d = DATE '0763-07-15';                          -- no 
rows, expected 1
SELECT k FROM t WHERE d IN (DATE '0763-07-15', DATE '2000-01-01');    -- no 
rows, expected 1
SELECT k FROM t WHERE d >= DATE '0763-07-15';                         -- no 
rows, expected 1
SELECT k FROM t WHERE d <= DATE '0763-07-15';                         -- 1
{code}

With 'format' = 'json' all four queries return the row. TIMESTAMP columns are 
not affected. If the file also contains later dates, it is not skipped, so the 
result depends on how the rows are split into files (for example one file per 
partition).

Reproduced in batch mode on 2.0.1, 2.2.1, 2.3.0 and master (2.4-SNAPSHOT).

Cause: OrcFilters#toOrcObject converts the DATE literal with 
java.sql.Date.valueOf(LocalDate). java.sql.Date uses the hybrid 
Julian/Gregorian calendar, while the ORC file stores proleptic Gregorian days. 
Before 1582-10-15 the two calendars differ, so the SearchArgument compares the 
column statistics with a different day (0763-07-15 becomes 0763-07-19 in 
proleptic days). The stripe holding the value is skipped for =, IN and >=.

A possible fix is to build the literal from the epoch day 
(localDate.toEpochDay()) instead of the calendar fields, or to not push down 
DATE predicates whose literal is before 1582-10-15. Iceberg's ORC filter 
conversion had the same problem (apache/iceberg#14214).




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to