Skip to content

fix(sql): make range() inclusive (Cypher semantics; CH was silently wrong)#450

Merged
genezhang merged 1 commit into
mainfrom
fix/range-inclusive
Jul 2, 2026
Merged

fix(sql): make range() inclusive (Cypher semantics; CH was silently wrong)#450
genezhang merged 1 commit into
mainfrom
fix/range-inclusive

Conversation

@genezhang

Copy link
Copy Markdown
Owner

Problem

Cypher range(start, end [, step]) is inclusive of end, but:

  • ClickHouse range() is exclusiverange(1,5) returned [1,2,3,4] instead of [1,2,3,4,5] — silently wrong on the primary backend.
  • Databricks has no range() at all → UNRESOLVED_ROUTINE.

Fix

Dialect Before After
ClickHouse range(1, 5)[1,2,3,4] range(1, (5)+1)[1,2,3,4,5]
Databricks range(1, 5) sequence(1, 5)[1,2,3,4,5]

CH bumps the end bound by 1 (inclusive); Databricks maps to sequence() (already inclusive). Handles the 2-arg and 3-arg (step) ascending forms.

Verification

  • Live, both engines: range(1,5) = [1,2,3,4,5], range(1,5,2) = [1,3,5].
  • Golden regression fn_range; no existing test asserted the old (wrong) exclusive behavior.
  • Gate: 1504 lib + 286 integration + 0 clippy.

Found by the CH↔Databricks parity probe. Descending / negative-step ranges remain unsupported on CH range() and are out of scope here.

🤖 Generated with Claude Code

…rong)

Cypher range(start, end [, step]) is INCLUSIVE of end, but:
  - ClickHouse range() is EXCLUSIVE — range(1,5) returned [1,2,3,4] instead of
    [1,2,3,4,5] (silently wrong on the primary backend);
  - Databricks has no range() at all (UNRESOLVED_ROUTINE).

Fix: CH bumps the end bound by 1 (range(start, end+1 [, step])) to make it
inclusive; Databricks maps to sequence(), which is already inclusive. Verified
both engines: range(1,5)=[1,2,3,4,5], range(1,5,2)=[1,3,5]. Golden fn_range.

Found by the CH<->Databricks parity probe. (Descending/negative-step ranges
remain unsupported on CH range() and are out of scope here.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@genezhang genezhang force-pushed the fix/range-inclusive branch from f1ad291 to cc5d238 Compare July 2, 2026 18:30
@genezhang genezhang merged commit 7c96c02 into main Jul 2, 2026
4 checks passed
@genezhang genezhang deleted the fix/range-inclusive branch July 2, 2026 18:37
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