Add support for window function cume_dist(). Improve tests for percent_rank().
FossilOrigin-Name: 76543f7dd3a2310f6e81a1bae17db9bb5d2cf10c1b87ed3f8394b3e75576078b
This commit is contained in:
parent
dfa552f45b
commit
f1abe3680e
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Add\ssupport\sfor\swindow\sfunctions\srow_number(),\srank(),\sdense_rank()\sand\npercent_rank().
|
||||
D 2018-06-02T21:04:28.694
|
||||
C Add\ssupport\sfor\swindow\sfunction\scume_dist().\sImprove\stests\sfor\spercent_rank().
|
||||
D 2018-06-04T08:22:09.586
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F Makefile.in bfc40f350586923e0419d2ea4b559c37ec10ee4b6e210e08c14401f8e340f0da
|
||||
@ -582,7 +582,7 @@ F src/where.c 60ec752fcbe9f9e0271ac60548d159a540a1ee47a4f9fedc85e88a3d0e392dd1
|
||||
F src/whereInt.h cbae2bcd37cfebdb7812a8b188cdb19634ced2b9346470d1c270556b0c33ea53
|
||||
F src/wherecode.c 728c7f70731430ccdac807a79969873e1af6968bf1c4745dff3f9dd35f636cc8
|
||||
F src/whereexpr.c e90b2e76dcabc81edff56633bf281bc01d93b71e0c81482dc06925ce39f5844a
|
||||
F src/window.c 014c6c7ae0242f16ba9453d2c9272753b8d20af08d4f1c6d040a6f87dbc55055
|
||||
F src/window.c 0a6bc6bd759c0a2a2dc033f02837d8bf9d0851cb03b98a59f86b09e0c1443b85
|
||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||
F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
|
||||
F test/affinity3.test 6a101af2fc945ce2912f6fe54dd646018551710d
|
||||
@ -1148,7 +1148,7 @@ F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b
|
||||
F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442
|
||||
F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff
|
||||
F test/permutations.test 10793f1de89a226fa22dde9ba9398de22571fee1bfb53a935a11be4aa014704f
|
||||
F test/pg_common.tcl 022a99098d284c64265b96573ef038ddb4c4c566ac587f50527f8a5e86c86ed0
|
||||
F test/pg_common.tcl 2562ad568cfaed67002f6cd9d1de3bc9d38eac99bb09acae3cdf92f8877f1a45
|
||||
F test/pragma.test 7c8cfc328a1717a95663cf8edb06c52ddfeaf97bb0aee69ae7457132e8d39e7d
|
||||
F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f
|
||||
F test/pragma3.test 14c12bc5352b1e100e0b6b44f371053a81ccf8ed
|
||||
@ -1618,8 +1618,8 @@ F test/win32nolock.test ac4f08811a562e45a5755e661f45ca85892bdbbc
|
||||
F test/window1.test 5705337783d220b47f6fb4432264543b7557a05be8013d772f57d71f2fded271
|
||||
F test/window2.tcl 0983de5eade5eeda49469244799d5331bfe3199fca3f6c6d2a836aa08f4fba1b
|
||||
F test/window2.test 79747b2edde4ad424e0752b27529aedc86e91f3d8d88846fa17ff0cb67f65086
|
||||
F test/window3.tcl 27a34216e6e9b94307faa146285ef97e23bec57e05787064e17669fb8e276b29
|
||||
F test/window3.test d8975dfd7a3ac4d67f18c9d288ff7c46f6d0461fff4290414fcbd62027e8ac03
|
||||
F test/window3.tcl 1c8da1cfaa1297bbd1bb888ad8616c743e2e8b821d2ba148f949ff019fc258df
|
||||
F test/window3.test 25340bf9b61a35396f6e2e0913faea549b3172c0190279fec8a39779a234a741
|
||||
F test/with1.test 58475190cd8caaeebea8cfeb2a264ec97a0c492b8ffe9ad20cefbb23df462f96
|
||||
F test/with2.test e0030e2f0267a910d6c0e4f46f2dfe941c1cc0d4f659ba69b3597728e7e8f1ab
|
||||
F test/with3.test 5e8ce2c585170bbbc0544e2a01a4941fa0be173ba5265e5c92eb588cd99a232d
|
||||
@ -1736,7 +1736,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P b5b18f661341d8d450147e62d321791c706f16c0550bcd98eec3e0220c039189
|
||||
R 936d5c4f2319457074a03c8e7558fedb
|
||||
P 91c1cb7a217d0991a08256269f6c55ef185c25362d57b36bfbd2d85dab38e58f
|
||||
R d9cb5cee11e623ce77b17cfe98f4c40b
|
||||
U dan
|
||||
Z 37caf2da8db60907c2ea55a56e1b5065
|
||||
Z 45e866351077245724084f5b2a722161
|
||||
|
@ -1 +1 @@
|
||||
91c1cb7a217d0991a08256269f6c55ef185c25362d57b36bfbd2d85dab38e58f
|
||||
76543f7dd3a2310f6e81a1bae17db9bb5d2cf10c1b87ed3f8394b3e75576078b
|
34
src/window.c
34
src/window.c
@ -149,6 +149,37 @@ static void percent_rankValueFunc(sqlite3_context *pCtx){
|
||||
}
|
||||
}
|
||||
|
||||
static void cume_distStepFunc(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
sqlite3_value **apArg
|
||||
){
|
||||
struct CallCount *p;
|
||||
assert( nArg==1 );
|
||||
|
||||
p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
|
||||
if( p ){
|
||||
if( p->nTotal==0 ){
|
||||
p->nTotal = sqlite3_value_int64(apArg[0]);
|
||||
}
|
||||
p->nStep++;
|
||||
}
|
||||
}
|
||||
static void cume_distInverseFunc(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
sqlite3_value **apArg
|
||||
){
|
||||
}
|
||||
static void cume_distValueFunc(sqlite3_context *pCtx){
|
||||
struct CallCount *p;
|
||||
p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
|
||||
if( p ){
|
||||
double r = (double)(p->nStep) / (double)(p->nTotal);
|
||||
sqlite3_result_double(pCtx, r);
|
||||
}
|
||||
}
|
||||
|
||||
static void nth_valueStepFunc(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
@ -179,6 +210,7 @@ void sqlite3WindowFunctions(void){
|
||||
WINDOWFUNC(dense_rank, 0, 0),
|
||||
WINDOWFUNC(rank, 0, 0),
|
||||
WINDOWFUNC(percent_rank, 0, SQLITE_FUNC_WINDOW_SIZE),
|
||||
WINDOWFUNC(cume_dist, 0, SQLITE_FUNC_WINDOW_SIZE),
|
||||
WINDOWFUNC(nth_value, 2, 0),
|
||||
};
|
||||
sqlite3InsertBuiltinFuncs(aWindowFuncs, ArraySize(aWindowFuncs));
|
||||
@ -197,7 +229,7 @@ void sqlite3WindowUpdate(Parse *pParse, Window *pWin, FuncDef *pFunc){
|
||||
}
|
||||
|
||||
if( pFunc->xSFunc==dense_rankStepFunc || pFunc->xSFunc==rankStepFunc
|
||||
|| pFunc->xSFunc==percent_rankStepFunc
|
||||
|| pFunc->xSFunc==percent_rankStepFunc || pFunc->xSFunc==cume_distStepFunc
|
||||
){
|
||||
sqlite3ExprDelete(db, pWin->pStart);
|
||||
sqlite3ExprDelete(db, pWin->pEnd);
|
||||
|
@ -66,6 +66,25 @@ proc execsql_test {tn sql} {
|
||||
puts $::fd ""
|
||||
}
|
||||
|
||||
# Same as [execsql_test], except coerce all results to floating point values
|
||||
# with two decimal points.
|
||||
#
|
||||
proc execsql_float_test {tn sql} {
|
||||
set F "%.2f"
|
||||
set res [execsql $sql]
|
||||
set res2 [list]
|
||||
foreach r $res { lappend res2 [format $F $r] }
|
||||
|
||||
puts $::fd "do_test $tn {"
|
||||
puts $::fd " set myres {}"
|
||||
puts $::fd " foreach r \[db eval {[string trim $sql]}\] {"
|
||||
puts $::fd " lappend myres \[format $F \[set r\]\]"
|
||||
puts $::fd " }"
|
||||
puts $::fd " set myres"
|
||||
puts $::fd "} {$res2}"
|
||||
puts $::fd ""
|
||||
}
|
||||
|
||||
proc start_test {name date} {
|
||||
set dir [file dirname $::argv0]
|
||||
set output [file join $dir $name.test]
|
||||
|
@ -129,36 +129,43 @@ foreach {tn window} {
|
||||
FROM t2
|
||||
"
|
||||
|
||||
execsql_test 1.$tn.7.1 "
|
||||
SELECT CAST( round( 100 *
|
||||
percent_rank() OVER ( ORDER BY a $window )
|
||||
) AS integer) FROM t2"
|
||||
|
||||
#execsql_test 1.$tn.7.2 "
|
||||
#SELECT CAST( round( 100 *
|
||||
#percent_rank() OVER ( PARTITION BY b%10 ORDER BY a $window )
|
||||
#) AS integer) FROM t2"
|
||||
|
||||
execsql_test 1.$tn.7.3 "
|
||||
SELECT CAST( round( 100 *
|
||||
percent_rank() OVER ( ORDER BY b $window )
|
||||
) AS integer) FROM t2"
|
||||
|
||||
#execsql_test 1.$tn.7.4 "
|
||||
#SELECT CAST( round( 100 *
|
||||
#percent_rank() OVER ( PARTITION BY b%10 ORDER BY b $window )
|
||||
#) AS integer) FROM t2"
|
||||
|
||||
execsql_test 1.$tn.7.5 "
|
||||
SELECT CAST( round( 100 *
|
||||
percent_rank() OVER ( ORDER BY b%10 $window )
|
||||
) AS integer) FROM t2"
|
||||
|
||||
execsql_test 1.$tn.7.6 "
|
||||
SELECT CAST( round( 100 *
|
||||
percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 $window )
|
||||
) AS integer) FROM t2"
|
||||
execsql_float_test 1.$tn.7.1 "
|
||||
SELECT percent_rank() OVER ( ORDER BY a $window ) FROM t2
|
||||
"
|
||||
execsql_float_test 1.$tn.7.2 "
|
||||
SELECT percent_rank() OVER ( PARTITION BY b%10 ORDER BY a $window ) FROM t2
|
||||
"
|
||||
execsql_float_test 1.$tn.7.3 "
|
||||
SELECT percent_rank() OVER ( ORDER BY b $window ) FROM t2
|
||||
"
|
||||
execsql_float_test 1.$tn.7.4 "
|
||||
SELECT percent_rank() OVER ( PARTITION BY b%10 ORDER BY b $window ) FROM t2
|
||||
"
|
||||
execsql_float_test 1.$tn.7.5 "
|
||||
SELECT percent_rank() OVER ( ORDER BY b%10 $window ) FROM t2
|
||||
"
|
||||
execsql_float_test 1.$tn.7.6 "
|
||||
SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 $window ) FROM t2
|
||||
"
|
||||
|
||||
execsql_float_test 1.$tn.8.1 "
|
||||
SELECT cume_dist() OVER ( ORDER BY a $window ) FROM t2
|
||||
"
|
||||
execsql_float_test 1.$tn.8.2 "
|
||||
SELECT cume_dist() OVER ( PARTITION BY b%10 ORDER BY a $window ) FROM t2
|
||||
"
|
||||
execsql_float_test 1.$tn.8.3 "
|
||||
SELECT cume_dist() OVER ( ORDER BY b $window ) FROM t2
|
||||
"
|
||||
execsql_float_test 1.$tn.8.4 "
|
||||
SELECT cume_dist() OVER ( PARTITION BY b%10 ORDER BY b $window ) FROM t2
|
||||
"
|
||||
execsql_float_test 1.$tn.8.5 "
|
||||
SELECT cume_dist() OVER ( ORDER BY b%10 $window ) FROM t2
|
||||
"
|
||||
execsql_float_test 1.$tn.8.6 "
|
||||
SELECT cume_dist() OVER ( PARTITION BY b%2 ORDER BY b%10 $window ) FROM t2
|
||||
"
|
||||
|
||||
}
|
||||
|
||||
|
1224
test/window3.test
1224
test/window3.test
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user