akupchinskiy opened a new issue, #7812:
URL: https://github.com/apache/datafusion-comet/issues/7812
Spark accepts a frame like `ROWS BETWEEN CURRENT ROW AND 2 PRECEDING` and
treats it as empty for every row (`count` 0, other aggregates NULL). Comet runs
it natively and returns garbage:
```sql
CREATE TABLE t (k INT, v INT) USING parquet;
INSERT INTO t VALUES (1, 10), (1, 20), (1, 30), (1, 40);
SELECT v,
COUNT(*) OVER w AS c,
SUM(v) OVER w AS s
FROM t
WINDOW w AS (PARTITION BY k ORDER BY v ROWS BETWEEN CURRENT ROW AND 2
PRECEDING);
```
Spark (Comet disabled):
| v | c | s |
|---|---|---|
| 10 | 0 | NULL |
| 20 | 0 | NULL |
| 30 | 0 | NULL |
| 40 | 0 | NULL |
Comet, release build of main at 07caef5, no error:
| v | c | s |
|---|---|---|
| 10 | 0 | NULL |
| 20 | -1 | -10 |
| 30 | -1 | -20 |
| 40 | -1 | -30 |
With `ROWS BETWEEN 2 FOLLOWING AND CURRENT ROW` instead, Spark returns the
same zeros and NULLs, and Comet fails the task with `CometNativeException:
length overflow`. Over more rows, other aggregates return wrong values (`min`,
`max`, `first_value`, `last_value`) or fail the task (`avg`, `last_value`,
`first_value`) depending on the frame.
Nobody writes this on purpose, but it is easy to get by accident: swapped
bounds, `rowsBetween(Window.currentRow, -2)`, or a parameterized window like
`rowsBetween(-n, -1)` with `n = 0`.
Cause: DataFusion's SQL planner rejects such frames, but Comet builds the
frame directly, so it reaches the sliding window code with `start > end`. In a
release build (`overflow-checks = false`) the length wraps around; a debug
build panics with "attempt to subtract with overflow" in `sliding_aggregate.rs`.
Possible fix: fall back to Spark for a frame whose lower bound lies after
the upper bound (they can only differ like this when one side is `CURRENT
ROW`), and refuse it in the native planner as well. I have a patch with tests
and can open a PR.
--
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]