Skip to content

with-orderBy: ORDER BY flows to downstream collect + overflow-safe temporal ordering (+10 TCK)#91

Merged
dylanbstorey merged 1 commit into
mainfrom
i0049-with-orderby
Jun 3, 2026
Merged

with-orderBy: ORDER BY flows to downstream collect + overflow-safe temporal ordering (+10 TCK)#91
dylanbstorey merged 1 commit into
mainfrom
i0049-with-orderby

Conversation

@dylanbstorey

Copy link
Copy Markdown
Contributor

Summary

Closes the entire WithOrderBy1 [45] cluster — "Sort order should be consistent with comparisons where comparisons are defined" — across all 10 type examples (booleans, integers, floats, string, lists, dates, localtimes, times, localdatetimes, datetimes).

Two root causes

  1. WITH … ORDER BY <input-var> WITH collect(x) ignored the ORDER BY.
    An ORDER BY on a non-aggregating WITH was only pushed into the WITH's CTE body when it referenced a dropped input variable. For an ORDER BY over a kept input variable it stayed on the outer SELECT, which a downstream aggregating WITH (collect) never observed — so collect aggregated in UNWIND order. Now, when every ORDER BY identifier is a live input variable and the WITH has no LIMIT/SKIP, the ORDER BY is also emitted inside the CTE body so the downstream aggregate sees sorted input (SQLite preserves an ordered subquery's order through json_group_array). The outer ORDER BY is still emitted for final-output ordering.

  2. Temporal </> overflowed int64 for far-future years.
    gql_order_cmp_func's temporal path compared parse_temporal_ns() values, where epoch_seconds * 1e9 overflows int64 around year ~2262 — so year-9999 datetimes compared as the smallest value, making < disagree with the ORDER BY key. New cmp_temporal_strings() compares (epoch_seconds, sub_second_ns) componentwise (no overflow across the full Cypher year range).

Verification

  • Rigorous full TCK pass-set diff: zero regressions, +10 (3776 → 3786)
  • Unit: 944/944
  • Functional: clean

Windows CI is a known flake and is allowed to fail.

🤖 Generated with Claude Code

…mporal ordering (+10 TCK)

WithOrderBy1 [45] all 10 type examples: a non-aggregating WITH's ORDER BY
over a kept input variable is now also pushed into the CTE body so a
downstream aggregating WITH (collect) sees sorted rows; and the temporal
< / > comparator uses an overflow-safe (seconds, ns) comparison so
year-9999 datetimes no longer wrap int64 epoch-ns and sort smallest.

Verified: rigorous full TCK pass-set diff zero regressions, 3776 to 3786;
unit 944/944; functional clean.
@dylanbstorey dylanbstorey merged commit 1b3dd61 into main Jun 3, 2026
16 of 17 checks passed
@dylanbstorey dylanbstorey deleted the i0049-with-orderby branch June 3, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant