Fix a problem with using json1 window functions with an EXCLUDE clause.

FossilOrigin-Name: 4a1978814da41608a16f6953bd575c97d587a34bd80b7ac0e619d62bfdc903d2
This commit is contained in:
dan 2019-09-13 20:42:46 +00:00
parent e087a7c35b
commit 51a75aaa76
4 changed files with 99 additions and 20 deletions

View File

@ -1,5 +1,5 @@
C Fix\sthe\swindowB\stest\smodule\sso\sthat\sit\sworks\seven\sif\sSQLite\sis\sbuilt\swithout\nJSON\ssupport.
D 2019-09-13T18:59:04.975
C Fix\sa\sproblem\swith\susing\sjson1\swindow\sfunctions\swith\san\sEXCLUDE\sclause.
D 2019-09-13T20:42:46.328
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -615,7 +615,7 @@ F src/where.c 9685d5988b79b93ebbe46941fbdb60d14861bb0fe3f9126117ef1753acc69b64
F src/whereInt.h 2c6bae136a7c0be6ff75dc36950d1968c67d005c8e51d7a9d77cb996bb4843d9
F src/wherecode.c 535c8e228478fd971b9a5b6cb6773995b0fbf7020d5989508a5094ce5b8cd95b
F src/whereexpr.c b3bbae199e7acd8d0fa822c9a29cbb822ef2b3d84d68de55a3d60b013f5d5da4
F src/window.c a35ad309132c639d075344a7c12f3133a8a738da238a35d8338f5034bd94c0a0
F src/window.c 2a10191a3ec7dd3422f8c77dac423d0e55019dee9efe319613ebd0f02b98991e
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/affinity2.test da465d3d490ab24ef64f7715b5953343a4967762b9350b29eb1462879ff3fb9e
F test/affinity3.test 6a101af2fc945ce2912f6fe54dd646018551710d
@ -1719,7 +1719,7 @@ F test/window8.tcl f2711aa3571e4e6b0dad98db8d95fd6cb8d9db0c92bbdf535f153b07606a1
F test/window8.test c4331b27a6f66d69fa8f8bab10cc731db1a81d293ae108a68f7c3487fa94e65b
F test/window9.test 20a6b590be718b6bc98a5356d4396d6cdf19329c547da084fa225b92d68e1693
F test/windowA.test 6d63dc1260daa17141a55007600581778523a8b420629f1282d2acfc36af23be
F test/windowB.test 3f0ae24a7860abaae9f092589f275a87787804b6d98ad6f23a0bc87fb4491d43
F test/windowB.test fae072a311cea62715007b482afd40b1124fef56dcc9988bffb85b29ccabb5dd
F test/windowerr.tcl f5acd6fbc210d7b5546c0e879d157888455cd4a17a1d3f28f07c1c8a387019e0
F test/windowerr.test a8b752402109c15aa1c5efe1b93ccb0ce1ef84fa964ae1cd6684dd0b3cc1819b
F test/windowfault.test a90b397837209f15e54afa62e8be39b2759a0101fae04e05a08bcc50e243a452
@ -1843,7 +1843,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 ba2ebc3a348decc5cedaf14960e30e7ae26a26824cfa198727f2499162142ef3
R bae0d8d6f0a49acfd1c53d207a1b5d08
U drh
Z 2837255703db522fd15af08765e39ee9
P 807975c76b36347f02aa0ce9661d608adbffe1f7e77c15f8da677e47e1187153
R 19b6534ebeb3a6a9bfaaa41ce75a9354
U dan
Z e45766b9d1c40d7379299659b41fb108

View File

@ -1 +1 @@
807975c76b36347f02aa0ce9661d608adbffe1f7e77c15f8da677e47e1187153
4a1978814da41608a16f6953bd575c97d587a34bd80b7ac0e619d62bfdc903d2

View File

@ -1481,8 +1481,8 @@ static void windowAggStep(
int addrIf = 0;
if( pWin->pFilter ){
int regTmp;
assert( nArg==0 || nArg==pWin->pOwner->x.pList->nExpr );
assert( nArg || pWin->pOwner->x.pList==0 );
assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
regTmp = sqlite3GetTempReg(pParse);
sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
@ -1490,9 +1490,19 @@ static void windowAggStep(
sqlite3ReleaseTempReg(pParse, regTmp);
}
if( pWin->bExprArgs ){
int iStart = sqlite3VdbeCurrentAddr(v);
VdbeOp *pOp, *pEnd;
nArg = pWin->pOwner->x.pList->nExpr;
regArg = sqlite3GetTempRange(pParse, nArg);
sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
pEnd = sqlite3VdbeGetOp(v, -1);
for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){
if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){
pOp->p1 = csr;
}
}
}
if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
CollSeq *pColl;

View File

@ -80,25 +80,94 @@ foreach {tn win} {
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 3.0 {
CREATE TABLE testjson(id INTEGER PRIMARY KEY, j TEXT);
INSERT INTO testjson VALUES(1, '{"a":1}');
INSERT INTO testjson VALUES(2, '{"b":2}');
}
ifcapable json1 {
reset_db
do_execsql_test 3.0 {
CREATE TABLE testjson(id INTEGER PRIMARY KEY, j TEXT);
INSERT INTO testjson VALUES(1, '{"a":1}');
INSERT INTO testjson VALUES(2, '{"b":2}');
INSERT INTO testjson VALUES(3, '{"c":3}');
INSERT INTO testjson VALUES(4, '{"d":4}');
}
do_execsql_test 3.1 {
SELECT json_group_array(json(j)) FROM testjson;
} {
{[{"a":1},{"b":2}]}
{[{"a":1},{"b":2},{"c":3},{"d":4}]}
}
do_execsql_test 3.2 {
SELECT json_group_array(json(j)) OVER (ORDER BY id) FROM testjson;
} {
{[{"a":1}]}
{[{"a":1},{"b":2}]}
{[{"a":1},{"b":2},{"c":3}]}
{[{"a":1},{"b":2},{"c":3},{"d":4}]}
}
do_execsql_test 3.3 {
SELECT json_group_array(json(j)) OVER (
ORDER BY id RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES
) FROM testjson;
} {
{[{"a":1}]}
{[{"a":1},{"b":2}]}
{[{"a":1},{"b":2},{"c":3}]}
{[{"a":1},{"b":2},{"c":3},{"d":4}]}
}
do_execsql_test 3.4 {
SELECT json_group_array(json(j)) OVER (
ORDER BY id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
) FROM testjson;
} {
{[{"a":1},{"b":2}]}
{[{"a":1},{"b":2},{"c":3}]}
{[{"b":2},{"c":3},{"d":4}]}
{[{"c":3},{"d":4}]}
}
do_execsql_test 3.5 {
SELECT json_group_array(json(j)) OVER (
ORDER BY id ROWS BETWEEN 2 PRECEDING AND 1 PRECEDING
) FROM testjson;
} {
{[]}
{[{"a":1}]}
{[{"a":1},{"b":2}]}
{[{"b":2},{"c":3}]}
}
if 0 {
do_execsql_test 3.5 {
SELECT json_group_array(json(j)) OVER (
ORDER BY id ROWS BETWEEN 1 FOLLOWING AND 2 FOLLOWING
) FROM testjson;
} {
{[]}
{[{"a":1}]}
{[{"a":1},{"b":2}]}
{[{"b":2},{"c":3}]}
}
explain_i {
SELECT json_group_array(json(j)) FILTER (WHERE id!=2) OVER (
ORDER BY id ROWS BETWEEN 2 PRECEDING AND 1 PRECEDING
) FROM testjson;
}
do_execsql_test 3.7 {
PRAGMA vdbe_trace = 1;
SELECT json_group_array(json(j)) FILTER (WHERE id!=2) OVER (
ORDER BY id ROWS BETWEEN 2 PRECEDING AND 1 PRECEDING
) FROM testjson;
} {
{[]}
{[{"a":1}]}
{[{"a":1}]}
{[{"c":3}]}
}
}
}