Describe the bug
Currently, date_part's preimage rewrite builds a NULL bound for an out-of-range January 1, so the comparison is NULL on every row.
To Reproduce
CREATE VIEW t AS SELECT * FROM (VALUES
('2020-06-01T12:00:00'::timestamp),
('1995-06-01T12:00:00'::timestamp)) s(ts);
SELECT count(*) FROM t WHERE EXTRACT(YEAR FROM ts) < 9999;
-- 0, should be 2
SELECT count(*) FROM t WHERE EXTRACT(YEAR FROM ts) >= 1000 OR EXTRACT(YEAR FROM ts) = 2020;
-- 1, should be 2, so a wrong non-zero count is reachable too
SELECT CASE WHEN EXTRACT(YEAR FROM ts) < 9999 THEN 'ok' ELSE 'BAD' END FROM t;
-- BAD BAD, so it is not confined to WHERE
SELECT EXTRACT(YEAR FROM ts), EXTRACT(YEAR FROM ts) < 9999 FROM t;
-- 2020 and 1995, both NULL
SELECT count(*) FROM t WHERE EXTRACT(YEAR FROM ts) <= 2262;
-- 0, since <= and > take January 1 of the next year as the bound
SELECT count(*) FROM t WHERE EXTRACT(YEAR FROM ts) >= 1678;
-- 2, so a bound inside 1678..2261 is unaffected
SELECT count(*) FROM (SELECT arrow_cast(ts,'Timestamp(Microsecond, None)') AS ts FROM t)
WHERE EXTRACT(YEAR FROM ts) < 9999;
-- 2, so only the nanosecond unit's narrower range reaches it
Expected behavior
Each count returns 2 and the CASE returns ok ok. The years the projection prints are the ones the comparison should test.
Additional context
date_to_scalar returns Some(TimestampNanosecond(None, tz)), so the NULL passes the guard.
America/Lima reaches it at 1990 and 1994, where Peru began DST at midnight on January 1.
datafusion-cli 55.0.0
Describe the bug
Currently,
date_part's preimage rewrite builds a NULL bound for an out-of-range January 1, so the comparison is NULL on every row.To Reproduce
Expected behavior
Each count returns 2 and the
CASEreturnsok ok. The years the projection prints are the ones the comparison should test.Additional context
date_to_scalarreturnsSome(TimestampNanosecond(None, tz)), so the NULL passes the guard.America/Limareaches it at 1990 and 1994, where Peru began DST at midnight on January 1.datafusion-cli 55.0.0