sqlite/test/window2.test
dan 09590aaa1b Fix "RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING" window frame
processing.

FossilOrigin-Name: b4e9c686697a5211a3bfa47e63f0684e3d4241d8c292cffe1a967bc39ad7cd8f
2018-05-25 20:30:17 +00:00

267 lines
6.6 KiB
Plaintext

# 2018 May 19
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
####################################################
# DO NOT EDIT! THIS FILE IS AUTOMATICALLY GENERATED!
####################################################
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix window2
do_execsql_test 1.0 {
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c TEXT, d INTEGER);
INSERT INTO t1 VALUES(1, 'odd', 'one', 1);
INSERT INTO t1 VALUES(2, 'even', 'two', 2);
INSERT INTO t1 VALUES(3, 'odd', 'three', 3);
INSERT INTO t1 VALUES(4, 'even', 'four', 4);
INSERT INTO t1 VALUES(5, 'odd', 'five', 5);
INSERT INTO t1 VALUES(6, 'even', 'six', 6);
} {}
do_execsql_test 1.1 {
SELECT c, sum(d) OVER (PARTITION BY b ORDER BY c) FROM t1;
} {four 4 six 10 two 12 five 5 one 6 three 9}
do_execsql_test 1.2 {
SELECT sum(d) OVER () FROM t1;
} {21 21 21 21 21 21}
do_execsql_test 1.3 {
SELECT sum(d) OVER (PARTITION BY b) FROM t1;
} {12 12 12 9 9 9}
#==========================================================================
do_execsql_test 2.1 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN 1000 PRECEDING AND 1 FOLLOWING
) FROM t1
} {1 3 2 6 3 10 4 15 5 21 6 21}
do_execsql_test 2.2 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN 1000 PRECEDING AND 1000 FOLLOWING
) FROM t1
} {1 21 2 21 3 21 4 21 5 21 6 21}
do_execsql_test 2.3 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN 1 PRECEDING AND 1000 FOLLOWING
) FROM t1
} {1 21 2 21 3 20 4 18 5 15 6 11}
do_execsql_test 2.4 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
) FROM t1
} {1 3 2 6 3 9 4 12 5 15 6 11}
do_execsql_test 2.5 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN 1 PRECEDING AND 0 FOLLOWING
) FROM t1
} {1 1 2 3 3 5 4 7 5 9 6 11}
do_execsql_test 2.6 {
SELECT a, sum(d) OVER (
PARTITION BY b
ORDER BY d
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
) FROM t1
} {2 6 4 12 6 10 1 4 3 9 5 8}
do_execsql_test 2.7 {
SELECT a, sum(d) OVER (
PARTITION BY b
ORDER BY d
ROWS BETWEEN 0 PRECEDING AND 0 FOLLOWING
) FROM t1
} {2 2 4 4 6 6 1 1 3 3 5 5}
do_execsql_test 2.8 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING
) FROM t1
} {1 6 2 9 3 12 4 15 5 11 6 6}
do_execsql_test 2.9 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN UNBOUNDED PRECEDING AND 2 FOLLOWING
) FROM t1
} {1 6 2 10 3 15 4 21 5 21 6 21}
do_execsql_test 2.10 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING
) FROM t1
} {1 6 2 9 3 12 4 15 5 11 6 6}
do_execsql_test 2.11 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW
) FROM t1
} {1 1 2 3 3 6 4 9 5 12 6 15}
do_execsql_test 2.13 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN 2 PRECEDING AND UNBOUNDED FOLLOWING
) FROM t1
} {1 21 2 21 3 21 4 20 5 18 6 15}
do_execsql_test 2.14 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN 3 PRECEDING AND 1 PRECEDING
) FROM t1
} {1 {} 2 1 3 3 4 6 5 9 6 12}
do_execsql_test 2.15 {
SELECT a, sum(d) OVER (
PARTITION BY b
ORDER BY d
ROWS BETWEEN 1 PRECEDING AND 0 PRECEDING
) FROM t1
} {2 2 4 6 6 10 1 1 3 4 5 8}
do_execsql_test 2.16 {
SELECT a, sum(d) OVER (
PARTITION BY b
ORDER BY d
ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING
) FROM t1
} {2 {} 4 2 6 4 1 {} 3 1 5 3}
do_execsql_test 2.17 {
SELECT a, sum(d) OVER (
PARTITION BY b
ORDER BY d
ROWS BETWEEN 1 PRECEDING AND 2 PRECEDING
) FROM t1
} {2 {} 4 {} 6 {} 1 {} 3 {} 5 {}}
do_execsql_test 2.18 {
SELECT a, sum(d) OVER (
PARTITION BY b
ORDER BY d
ROWS BETWEEN UNBOUNDED PRECEDING AND 2 PRECEDING
) FROM t1
} {2 {} 4 {} 6 2 1 {} 3 {} 5 1}
do_execsql_test 2.19 {
SELECT a, sum(d) OVER (
PARTITION BY b
ORDER BY d
ROWS BETWEEN 1 FOLLOWING AND 3 FOLLOWING
) FROM t1
} {2 10 4 6 6 {} 1 8 3 5 5 {}}
do_execsql_test 2.20 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN 1 FOLLOWING AND 2 FOLLOWING
) FROM t1
} {1 5 2 7 3 9 4 11 5 6 6 {}}
do_execsql_test 2.21 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
) FROM t1
} {1 20 2 18 3 15 4 11 5 6 6 {}}
do_execsql_test 2.22 {
SELECT a, sum(d) OVER (
PARTITION BY b
ORDER BY d
ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
) FROM t1
} {2 10 4 6 6 {} 1 8 3 5 5 {}}
do_execsql_test 2.23 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
) FROM t1
} {1 21 2 20 3 18 4 15 5 11 6 6}
do_execsql_test 2.24 {
SELECT a, sum(d) OVER (
PARTITION BY a%2
ORDER BY d
ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
) FROM t1
} {2 12 4 10 6 6 1 9 3 8 5 5}
do_execsql_test 2.25 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) FROM t1
} {1 21 2 21 3 21 4 21 5 21 6 21}
do_execsql_test 2.26 {
SELECT a, sum(d) OVER (
PARTITION BY b
ORDER BY d
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) FROM t1
} {2 12 4 12 6 12 1 9 3 9 5 9}
do_execsql_test 2.27 {
SELECT a, sum(d) OVER (
ORDER BY d
ROWS BETWEEN CURRENT ROW AND CURRENT ROW
) FROM t1
} {1 1 2 2 3 3 4 4 5 5 6 6}
do_execsql_test 2.28 {
SELECT a, sum(d) OVER (
PARTITION BY b
ORDER BY d
ROWS BETWEEN CURRENT ROW AND CURRENT ROW
) FROM t1
} {2 2 4 4 6 6 1 1 3 3 5 5}
do_execsql_test 2.29 {
SELECT a, sum(d) OVER (
ORDER BY d
RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
) FROM t1
} {1 21 2 20 3 18 4 15 5 11 6 6}
do_execsql_test 2.30 {
SELECT a, sum(d) OVER (
ORDER BY b
RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
) FROM t1
} {2 21 4 21 6 21 1 9 3 9 5 9}
#==========================================================================
finish_test
#==========================================================================
finish_test