Repository navigation
Commit 77cd027
fix: call aggregate init when there are no rows to aggregate (#641)
* fix: call aggregate init when there are no rows to aggregate
SQLite never calls xStep for an aggregate over an empty input, only
xFinal. The JavaScript state was only initialized in the step wrapper,
so finalize received undefined instead of the value returned by init:
`SELECT json_agg(x) FROM t WHERE 0` returned NULL instead of '[]', an
aggregate with `init: () => 0` and no finalize returned NULL instead of
0, and a finalize that reads properties of its state threw a TypeError.
Initialize the state in the finalize wrapper as well when it is missing.
* refactor: use a Map for aggregate state
---------
Co-authored-by: ybai08 <271969568+ybai08@users.noreply.github.com>
Co-authored-by: Ophir Lojkine <contact@ophir.dev>1 parent 4b638f7 commit 77cd027
2 files changed
Lines changed: 48 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1343 | 1343 | | |
1344 | 1344 | | |
1345 | 1345 | | |
1346 | | - | |
1347 | | - | |
1348 | | - | |
1349 | | - | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
1350 | 1353 | | |
1351 | 1354 | | |
1352 | 1355 | | |
1353 | 1356 | | |
1354 | 1357 | | |
1355 | 1358 | | |
1356 | 1359 | | |
1357 | | - | |
| 1360 | + | |
1358 | 1361 | | |
1359 | 1362 | | |
1360 | 1363 | | |
| |||
1363 | 1366 | | |
1364 | 1367 | | |
1365 | 1368 | | |
1366 | | - | |
| 1369 | + | |
1367 | 1370 | | |
1368 | | - | |
| 1371 | + | |
1369 | 1372 | | |
1370 | 1373 | | |
1371 | | - | |
| 1374 | + | |
1372 | 1375 | | |
1373 | | - | |
| 1376 | + | |
1374 | 1377 | | |
1375 | | - | |
| 1378 | + | |
1376 | 1379 | | |
1377 | 1380 | | |
1378 | 1381 | | |
| |||
1381 | 1384 | | |
1382 | 1385 | | |
1383 | 1386 | | |
1384 | | - | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
1385 | 1390 | | |
1386 | | - | |
| 1391 | + | |
1387 | 1392 | | |
1388 | 1393 | | |
1389 | 1394 | | |
1390 | 1395 | | |
1391 | | - | |
| 1396 | + | |
1392 | 1397 | | |
1393 | 1398 | | |
1394 | 1399 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
56 | 86 | | |
57 | 87 | | |
58 | 88 | | |
| |||
0 commit comments