fix(sql): make range() inclusive (Cypher semantics; CH was silently wrong)#450
Merged
Conversation
…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>
f1ad291 to
cc5d238
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Cypher
range(start, end [, step])is inclusive ofend, but:range()is exclusive →range(1,5)returned[1,2,3,4]instead of[1,2,3,4,5]— silently wrong on the primary backend.range()at all →UNRESOLVED_ROUTINE.Fix
range(1, 5)→[1,2,3,4]❌range(1, (5)+1)→[1,2,3,4,5]✅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
range(1,5)=[1,2,3,4,5],range(1,5,2)=[1,3,5].fn_range; no existing test asserted the old (wrong) exclusive behavior.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