pingxin403 opened a new pull request, #19328:
URL: https://github.com/apache/iceberg/pull/19328

   Fixes #19322
   
   ## What
   
   Binding a literal converts it with `Literal.to(type)`, and the 
timestamp-to-date conversions floor the value (`DateTimeUtil.microsToDays`, 
`nanosToDays`), while the bound predicate kept the original operator. `d < 
TIMESTAMP '2023-01-05 12:00:00'` therefore became `d < DATE '2023-01-05'` and 
stopped matching that day — a row `d = 2023-01-05` is before noon but no longer 
before the floored predicate. Nanoseconds bound to microseconds had the same 
problem.
   
   `bindLiteralOperation` now adjusts the operator when the conversion loses 
precision:
   
   | original | bound |
   |---|---|
   | `<`, `<=` | `<=` on the floored day |
   | `>` | `>=` on the floored day |
   | `>=` | `>` on the floored day |
   | `=` | always false (no date equals a time inside the day) |
   | `!=` | always true |
   
   Precision loss is detected from the literal's own type (`Literals.typeIdOf`, 
a new package-private accessor, since a timestamp and a nanosecond timestamp 
are both stored as a `long`): a timestamp loses precision unless it is exactly 
midnight, a nanosecond timestamp unless it is a whole microsecond (and a whole 
day when bound to `date`). Midnight timestamps and exact microsecond values 
keep their operator, so correct predicates are unaffected.
   
   `IN` lists skip such values for the same reason — no date is equal to a time 
inside the day — and keep the existing empty-set and single-value handling.
   
   ## Tests
   
   `TestTimestampToDateBinding` covers `<` (becomes `<=` and its literal is the 
floored day), `>=` (becomes `>`), `<`/`<=`/`>` that need no adjustment, 
`=`/`!=` (always false/true), a midnight timestamp (keeps `<`), and a 
nanosecond timestamp bound to `timestamp` (becomes `<=` with the floored 
microsecond value).
   
   Negative check: deleting the adjustment block makes four of the six tests 
fail. The whole `org.apache.iceberg.expressions` package passes: 604 tests, 0 
failures.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to