Skip to content

fix: the range_of_ranges should check the Range end is smaller than its start #946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# PRQL Changelog

## [unreleased]

### Fixes

- `range_of_ranges` checks the Range end is smaller than its start (@shuozeli, #946)

## 0.2.6 — 2022-08-05

### Fixes
Expand Down
12 changes: 12 additions & 0 deletions prql-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,18 @@ select `first name`
employees OFFSET 4
"###);

assert_display_snapshot!((compile(r###"
from employees
take 5..5
"###)?), @r###"
SELECT
employees.*
FROM
employees
LIMIT
1 OFFSET 4
"###);

// should be one SELECT
assert_display_snapshot!((compile(r###"
from employees
Expand Down
9 changes: 8 additions & 1 deletion prql-compiler/src/sql/translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ fn range_of_ranges(ranges: Vec<Range>) -> Result<Range<i64>> {
if current
.start
.zip(current.end)
.map(|(s, e)| e <= s)
.map(|(s, e)| e < s)
.unwrap_or(false)
{
bail!("Range end is before its start.");
Expand Down Expand Up @@ -936,6 +936,7 @@ mod test {
let range2 = Range::from_ints(Some(5), Some(6));
let range3 = Range::from_ints(Some(5), None);
let range4 = Range::from_ints(None, Some(8));
let range5 = Range::from_ints(Some(5), Some(5));

assert!(range_of_ranges(vec![range1.clone()])?.end.is_some());

Expand Down Expand Up @@ -990,6 +991,12 @@ mod test {
end: 8
"###);

assert_yaml_snapshot!(range_of_ranges(vec![range5])?, @r###"
---
start: 5
end: 5
"###);

Ok(())
}

Expand Down