Skip to content

Commit d3c593a

Browse files
authored
Merge 'fix: default generate_series STOP to SQLite Default (4294967295) when omitted' from Damian Melia
### Issue generate_series with only a START argument (e.g. generate_series(1) or generate_series WHERE start = 5) returned no rows. Per SQLite, omitted STOP should default to 4294967295, and the series should run from START to 4294967295 with STEP 1. In the virtual table's filter method, when STOP was absent, it stayed -1, triggering ResultCode::EOF and producing an empty series. ### Fix When STOP is not provided as a constraint (idx_num & 2 == 0), set stop = 4294967295 (u32::MAX) in the filter method. The existing stop == -1 check remains for explicitly provided invalid values. ### Testing Added `testing/runner/tests/generate_series.sqltest` with tests for: - Single-arg default stop (function call and WHERE form) - Two-arg and three-arg forms (regression) - Explicit STOP = -1 (empty series preserved) #3393 Used to query codebase for patterns surrounding the use of constants in functions as well as generating the testcases based off my description of what to test for. Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com> Closes #5472
2 parents 3abf371 + 70e825c commit d3c593a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

core/series.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ impl VTabCursor for GenerateSeriesCursor {
170170
let mut start = -1;
171171
let mut stop = -1;
172172
let mut step = 1;
173+
// SQLite default for stop when it is omitted
174+
const DEFAULT_STOP_OMITTED: i64 = u32::MAX as i64;
173175

174176
if let Some((_, idx_num)) = idx_info {
175177
let mut arg_idx = 0;
@@ -181,6 +183,8 @@ impl VTabCursor for GenerateSeriesCursor {
181183
if idx_num & 2 != 0 {
182184
stop = extract_arg_integer!(args, arg_idx, i64::MAX);
183185
arg_idx += 1;
186+
} else {
187+
stop = DEFAULT_STOP_OMITTED;
184188
}
185189
if idx_num & 4 != 0 {
186190
step = args
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@database :memory:
2+
3+
test generate-series-single-arg-default-stop {
4+
SELECT count(*), max(value) FROM generate_series(4294967290);
5+
}
6+
expect {
7+
6|4294967295
8+
}
9+
10+
test generate-series-single-arg-via-where {
11+
SELECT count(*), max(value) FROM generate_series WHERE start = 4294967290;
12+
}
13+
expect {
14+
6|4294967295
15+
}
16+
17+
test generate-series-two-args {
18+
SELECT * FROM generate_series(1, 5);
19+
}
20+
expect {
21+
1
22+
2
23+
3
24+
4
25+
5
26+
}
27+
28+
test generate-series-three-args {
29+
SELECT * FROM generate_series(1, 10, 3);
30+
}
31+
expect {
32+
1
33+
4
34+
7
35+
10
36+
}
37+
38+
test generate-series-explicit-negative-stop {
39+
SELECT count(*) FROM generate_series(1, -1);
40+
}
41+
expect {
42+
0
43+
}

0 commit comments

Comments
 (0)