Skip to content

Commit

Permalink
fix: the range_of_ranges should check the Range end is smaller than i…
Browse files Browse the repository at this point in the history
…ts start (#946)
  • Loading branch information
Shuozeli authored Sep 2, 2022
1 parent 9ba8374 commit d2fd17f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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

0 comments on commit d2fd17f

Please sign in to comment.