3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
16 set testprefix windowfault
18 ifcapable !windowfunc {
24 CREATE TABLE t1(a, b, c, d);
25 INSERT INTO t1 VALUES(1, 2, 3, 4);
26 INSERT INTO t1 VALUES(5, 6, 7, 8);
27 INSERT INTO t1 VALUES(9, 10, 11, 12);
29 faultsim_save_and_close
31 do_faultsim_test 1 -start 1 -faults oom-* -prep {
32 faultsim_restore_and_reopen
35 SELECT row_number() OVER win,
37 dense_rank() OVER win,
39 first_value(d) OVER win,
40 last_value(d) OVER win,
41 nth_value(d,2) OVER win,
47 WINDOW win AS (ORDER BY a)
50 faultsim_test_result {0 {1 1 1 1 4 4 {} 8 {} 4 4 2 2 2 1 4 8 8 12 4 8 4 3 3 3 2 4 12 8 {} 8 12 4}}
53 do_faultsim_test 1.1 -faults oom-t* -prep {
54 faultsim_restore_and_reopen
57 SELECT row_number() OVER win,
61 WINDOW win AS (PARTITION BY c<7 ORDER BY a)
64 faultsim_test_result {0 {1 1 1 2 2 2 1 1 1}}
67 do_faultsim_test 1.2 -faults oom-t* -prep {
68 faultsim_restore_and_reopen
72 OVER ( RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW )
76 faultsim_test_result {0 {1 2 3}}
79 do_faultsim_test 2 -start 1 -faults oom-* -prep {
80 faultsim_restore_and_reopen
83 SELECT round(percent_rank() OVER win, 2),
84 round(cume_dist() OVER win, 2)
86 WINDOW win AS (ORDER BY a)
89 faultsim_test_result {0 {0.0 0.33 0.5 0.67 1.0 1.0}}
92 do_faultsim_test 3 -faults oom-* -prep {
93 faultsim_restore_and_reopen
96 SELECT min(d) OVER win, max(d) OVER win
98 WINDOW win AS (ORDER BY a RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)
101 faultsim_test_result {0 {4 12 8 12 12 12}}
104 do_faultsim_test 4 -faults oom-* -prep {
105 faultsim_restore_and_reopen
109 SELECT min(d) OVER w, max(d) OVER w
111 WINDOW w AS (ORDER BY a RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING);
115 faultsim_test_result {0 {4 12 8 12 12 12}}
118 do_faultsim_test 5 -start 1 -faults oom-* -prep {
119 faultsim_restore_and_reopen
122 SELECT last_value(a) OVER win1,
123 last_value(a) OVER win2
125 WINDOW win1 AS (ORDER BY a ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING),
129 faultsim_test_result {0 {5 1 9 5 9 9}}
132 do_faultsim_test 6 -faults oom-* -prep {
133 faultsim_restore_and_reopen
136 SELECT percent_rank() OVER (), cume_dist() OVER () FROM t1
139 faultsim_test_result {0 {0.0 1.0 0.0 1.0 0.0 1.0}}
142 do_faultsim_test 7 -faults oom-* -prep {
143 faultsim_restore_and_reopen
146 SELECT percent_rank() OVER (), cume_dist() OVER () FROM t1
149 faultsim_test_result {0 {0.0 1.0 0.0 1.0 0.0 1.0}}
152 do_faultsim_test 8 -faults oom-t* -prep {
153 faultsim_restore_and_reopen
156 SELECT a, sum(b) OVER win1 FROM t1
157 WINDOW win1 AS (PARTITION BY a ),
158 win2 AS (PARTITION BY b )
162 faultsim_test_result {0 {1 2 5 6 9 10}}