Skip to content

Window functions fail when ORDER BY uses a TIME column #24514

Description

@fornwall

Describe the bug

Window functions whose leading ORDER BY key is Time32 or Time64 fail during type coercion, even when no frame clause is specified.

An ORDER BY window defaults to RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW. These free bounds only need to compare order-key values, and time values are orderable.

To Reproduce

Run:

cargo run --quiet -p datafusion-cli -- -q -c \
  "SELECT x, COUNT(*) OVER (ORDER BY x) FROM (VALUES (arrow_cast('01:00:00', 'Time64(Microsecond)')), (arrow_cast('02:00:00', 'Time64(Microsecond)')), (arrow_cast('02:00:00', 'Time64(Microsecond)'))) AS t(x) ORDER BY x;"

It fails with an internal error:

Error: type_coercion
caused by
Internal error: Cannot run range queries on datatype: Time64(Microsecond).

Expected behavior

The query should succeed and treat equal time values as peers:

01:00:00 1
02:00:00 3
02:00:00 3

Free RANGE frames whose bounds are only UNBOUNDED or CURRENT ROW should support time order keys. Finite offsets such as INTERVAL '1' HOUR PRECEDING should remain unsupported because time/interval arithmetic wraps around the 24-hour clock, but they should produce a planning error rather than an internal error.

Additional context

The same problem affects Time32(Second), Time32(Millisecond), Time64(Microsecond), Time64(Nanosecond), and dictionary-wrapped time values. This is analogous to the binary order-key issue fixed in #24357.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions