yashmayya opened a new pull request, #19788: URL: https://github.com/apache/pinot/pull/19788
## Problem The multi-stage engine folds `datetime +/- INTERVAL` literals through the `plus` / `minus` scalar functions and passes the raw Calcite interval value. Calcite stores a day-time interval as milliseconds, but a year-month interval as a number of **months**. So `INTERVAL '1' MONTH` is added as 1 ms. The result is silently wrong: | Query | Before | After | |---|---|---| | `TIMESTAMP '2019-01-01 00:00:00' + INTERVAL '1' MONTH` | `2019-01-01 00:00:00` | `2019-02-01 00:00:00` | | `TIMESTAMP '2019-03-31 00:00:00' - INTERVAL '1' MONTH` | `2019-03-30 23:59:59` | `2019-02-28 00:00:00` | | `WHERE ts > TIMESTAMP '2019-03-01 00:00:00' - INTERVAL '1' MONTH` | `> 2019-02-28 23:59:59` | `> 2019-02-01 00:00:00` | | `DATE '2019-01-01' + INTERVAL '1' DAY` | `ClassCastException` | `2019-01-02` | | `TIMESTAMP '...' + INTERVAL '1' MONTH * 2` | `AssertionError` (adds 2 ms without `-ea`) | +2 months | Day-time intervals (`DAY`, `HOUR`, ...) were already correct and do not change. ## Fix `PinotEvaluateLiteralRule` now evaluates `DATETIME_PLUS` / `MINUS_DATE` itself, with the same semantics as Calcite: - Year-month interval: add months with the same calendar arithmetic as `TIMESTAMPADD(MONTH, ...)`, so `2019-01-31 + INTERVAL '1' MONTH` is `2019-02-28`. - Day-time interval: add milliseconds, as before. - `DATE` result: add only the whole days of a day-time interval, and build a `DATE` literal. Calls that return an interval (for example `INTERVAL '1' MONTH * 2`) now fold to a correct interval literal. A fractional number of months (`INTERVAL '1' MONTH / 2`) fails with a clear error. Not in scope: `ts_col + INTERVAL ...` with a column operand still fails at planning (`Unsupported ColumnDataType: OBJECT`) for all interval units, as before. ## Tests Added cases to `LiteralEvaluationPlans.json` for YEAR, MONTH, YEAR TO MONTH, DAY, HOUR, DAY TO SECOND, end of month, negative intervals, WHERE clauses, DATE results and multiplied intervals. 16 of them fail without the fix. -- 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]
