Skip to content

bug: window expression does not work with preceding compound interval #11933

@printsg

Description

@printsg

What happened?

Rolling aggregation with compound preceding interval, e.g.,1 month - 1 day, produces wrong SQL.

import ibis
from datetime import datetime

data = {
    "id": [1, 1, 1],
    "date": [
        datetime(2024, 1, 1),
        datetime(2024, 1, 10),
        datetime(2024, 1, 20),
    ],
    "value": [10.0, 20.0, 30.0]
}
t = ibis.memtable(data)

# interv = ibis.interval(months=-1) # works! 
interv = ibis.interval(months=-1, days=1) # "Out of Range Error: Invalid RANGE FOLLOWING value"

win = ibis.window(
    group_by=["id"],
    order_by=["date"],
    between=(interv, 0),
)
expr = t.mutate(
    rolling_sum=t.value.sum().over(win)
)
# ibis.to_sql(expr)
expr.execute()

SQL:

SELECT
  "t0"."id",
  "t0"."date",
  "t0"."value",
  SUM("t0"."value") OVER (
    PARTITION BY "t0"."id"
    ORDER BY "t0"."date" ASC
    RANGE BETWEEN INTERVAL '1' DAY + INTERVAL '-1' MONTH following AND TO_DAYS(CAST(0 AS INT)) following
  ) AS "rolling_sum"
FROM "ibis_pandas_memtable_u4ikv6hl3rd6tfmfnzvlek5hb4" AS "t0"

What version of ibis are you using?

11.0.0

What backend(s) are you using, if any?

DuckDB

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior inside of ibis

    Type

    No type

    Projects

    Status

    backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions