yashmayya opened a new pull request, #20277:
URL: https://github.com/apache/pinot/pull/20277
#19948 made `PinotEvaluateLiteralRule` pass each literal to the function as
the Java value that the runtime uses. Some queries that worked before then gave
wrong results or failed at planning. This PR fixes them.
### 1. INT arithmetic beyond the INT range (wrong results)
Calcite gives `1000 * 60 * 60 * 100000` the type INTEGER, but Pinot
evaluates INT arithmetic as LONG. So the rule makes an INTEGER literal with the
value 360000000000. After #19948, the call around that literal got an
`Integer`, and the value wrapped to -777252864.
Example: `ts > NOW() - 1000 * 60 * 60 * 100000` became `ts > now + 9 days`
and returned no rows.
Fix: if an INT literal argument is beyond the INT range, all the INT literal
arguments of that call become LONG. They all change so that the elements of an
array keep one Java class.
### 2. Array literals (failed at planning)
- `ARRAY[1, NULL]` failed with a `NullPointerException`.
- `ARRAY[1 + 1, 99999999999999999999]` failed with a `ClassCastException`.
The rule gives the literal for `1 + 1` the type BIGINT (a `Long`), but the
DECIMAL(20, 0) literal keeps its exact `BigDecimal`.
The array constructor needs elements of one Java class, and no NULL for a
primitive array.
Fix: for such an array, the number elements keep their exact values
(`BigDecimal`), as before #19948.
### 3. CAST between TIMESTAMP and INT or FLOAT (failed at planning)
`tsCol > 86400 * 1000` and `CAST(1 + 1 AS TIMESTAMP)` failed with `Cannot
convert value from INT to TIMESTAMP`. The CAST scalar function has no
conversion between TIMESTAMP and INT or FLOAT.
Fix: for such a CAST, the rule passes a LONG (for an INT or a TIMESTAMP) or
a DOUBLE (for a FLOAT).
### Side effect
`%`, `ABS`, `GREATEST`, `LEAST`, `CASE WHEN` and comparisons on an INT value
beyond the INT range now get the full value. Before #19948 they got the wrapped
value (for example, `1000 * 60 * 60 * 100000 > 0` was false).
### Tests
New cases in `LiteralEvaluationPlans.json` (plans) and
`LiteralExpressions.json` (results). They fail without the fix. The only
exception is the `LENGTH('abc') IN (1, 2, 3)` case: it makes sure that the new
code does not read the `Sarg` literal of a SEARCH as a number.
### Not fixed here
These two cases were wrong before #19948 too. The result or operand type is
INT, so the value wraps when the plan is converted:
- `SELECT 1000 * 60 * 60 * 100000` returns -777252864.
- `longCol - 1000 * 60 * 60 * 100000` subtracts -777252864.
--
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]