sqlmath 2026.6.30 → 2026.8.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +9 -9
- package/_sqlmath.napi6_darwin_arm64.node +0 -0
- package/_sqlmath.napi6_darwin_x64.node +0 -0
- package/_sqlmath.napi6_linux_x64.node +0 -0
- package/_sqlmath.napi6_win32_x64.node +0 -0
- package/_sqlmath.shell_darwin_arm64 +0 -0
- package/_sqlmath.shell_darwin_x64 +0 -0
- package/_sqlmath.shell_linux_x64 +0 -0
- package/_sqlmath.shell_win32_x64.exe +0 -0
- package/jslint.mjs +2061 -1802
- package/package.json +1 -1
- package/sqlmath/lib_lightgbm_darwin_arm64.dylib +0 -0
- package/sqlmath/lib_lightgbm_darwin_x64.dylib +0 -0
- package/sqlmath/lib_lightgbm_linux_x64.so +0 -0
- package/sqlmath/lib_lightgbm_win32_x64.dll +0 -0
- package/sqlmath.mjs +27 -25
- package/sqlmath_wasm.js +1 -1
- package/sqlmath_wasm.wasm +0 -0
- package/test.mjs +341 -37
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/sqlmath.mjs
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
/*
|
|
24
24
|
sh one-liner:
|
|
25
|
+
npm_config_mode_test_save=1 npm run test && git diff
|
|
25
26
|
sh jslint_ci.sh shCiBuildWasm
|
|
26
27
|
sh jslint_ci.sh shSqlmathUpdate
|
|
27
28
|
*/
|
|
@@ -30,7 +31,26 @@ sh jslint_ci.sh shSqlmathUpdate
|
|
|
30
31
|
/*global FinalizationRegistry*/
|
|
31
32
|
"use strict";
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
// init debugInline
|
|
35
|
+
const debugInline = (function () {
|
|
36
|
+
let consoleError = Object;
|
|
37
|
+
function debug(...argList) {
|
|
38
|
+
|
|
39
|
+
// This function will print <argList> to stderr and then return <argList>[0].
|
|
40
|
+
|
|
41
|
+
consoleError("\n\ndebugInline");
|
|
42
|
+
consoleError(...argList);
|
|
43
|
+
consoleError("\n");
|
|
44
|
+
if (consoleError === Object) {
|
|
45
|
+
consoleError = console.error;
|
|
46
|
+
}
|
|
47
|
+
return argList[0];
|
|
48
|
+
}
|
|
49
|
+
return debug;
|
|
50
|
+
}());
|
|
51
|
+
debugInline(); // coverage-hack
|
|
52
|
+
|
|
53
|
+
const JSBATON_ARGC = 8; //jslint-ignore-line
|
|
34
54
|
const JSBATON_OFFSET_ALL = 256;
|
|
35
55
|
const JSBATON_OFFSET_ARGV = 128;
|
|
36
56
|
const JSBATON_OFFSET_BUFV = 192;
|
|
@@ -89,10 +109,11 @@ const SQLITE_OPEN_TRANSIENT_DB = 0x00000400; /* VFS only */
|
|
|
89
109
|
const SQLITE_OPEN_URI = 0x00000040; /* Ok for sqlite3_open_v2() */
|
|
90
110
|
const SQLITE_OPEN_WAL = 0x00080000; /* VFS only */
|
|
91
111
|
|
|
92
|
-
|
|
112
|
+
const DB_EXEC_PROFILE_DICT = {}; //jslint-ignore-line
|
|
113
|
+
const DB_STATE = {};
|
|
114
|
+
const version = "v2026.8.31";
|
|
93
115
|
let DB_EXEC_PROFILE_MODE;
|
|
94
116
|
let DB_EXEC_PROFILE_SQL_LENGTH;
|
|
95
|
-
let DB_STATE = {};
|
|
96
117
|
let IS_BROWSER;
|
|
97
118
|
let SQLMATH_EXE;
|
|
98
119
|
let SQLMATH_NODE;
|
|
@@ -100,24 +121,6 @@ let cModule;
|
|
|
100
121
|
let cModulePath;
|
|
101
122
|
let consoleError = console.error;
|
|
102
123
|
let dbFinalizationRegistry;
|
|
103
|
-
// init debugInline
|
|
104
|
-
let debugInline = (function () {
|
|
105
|
-
let __consoleError = function () {
|
|
106
|
-
return;
|
|
107
|
-
};
|
|
108
|
-
function debug(...argList) {
|
|
109
|
-
|
|
110
|
-
// This function will print <argList> to stderr and then return <argList>[0].
|
|
111
|
-
|
|
112
|
-
__consoleError("\n\ndebugInline");
|
|
113
|
-
__consoleError(...argList);
|
|
114
|
-
__consoleError("\n");
|
|
115
|
-
return argList[0];
|
|
116
|
-
}
|
|
117
|
-
debug(); // Coverage-hack.
|
|
118
|
-
__consoleError = console.error; //jslint-ignore-line
|
|
119
|
-
return debug;
|
|
120
|
-
}());
|
|
121
124
|
let moduleChildProcess;
|
|
122
125
|
let moduleChildProcessSpawn;
|
|
123
126
|
let moduleCrypto;
|
|
@@ -133,7 +136,6 @@ let {
|
|
|
133
136
|
let sqlMessageDict = {}; // dict of web-worker-callbacks
|
|
134
137
|
let sqlMessageId = 0;
|
|
135
138
|
let sqlWorker;
|
|
136
|
-
let version = "v2026.6.30";
|
|
137
139
|
|
|
138
140
|
async function assertErrorThrownAsync(asyncFunc, regexp) {
|
|
139
141
|
|
|
@@ -1785,11 +1787,11 @@ async function moduleFsInit() {
|
|
|
1785
1787
|
);
|
|
1786
1788
|
}
|
|
1787
1789
|
|
|
1788
|
-
function noop(
|
|
1790
|
+
function noop(value) {
|
|
1789
1791
|
|
|
1790
|
-
// This function will do nothing except return <
|
|
1792
|
+
// This function will do nothing except return <value>.
|
|
1791
1793
|
|
|
1792
|
-
return
|
|
1794
|
+
return value;
|
|
1793
1795
|
}
|
|
1794
1796
|
|
|
1795
1797
|
function objectDeepCopyWithKeysSorted(obj) {
|
package/sqlmath_wasm.js
CHANGED
package/sqlmath_wasm.wasm
CHANGED
|
Binary file
|
package/test.mjs
CHANGED
|
@@ -20,11 +20,6 @@
|
|
|
20
20
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
// SOFTWARE.
|
|
22
22
|
|
|
23
|
-
/*
|
|
24
|
-
* example usage:
|
|
25
|
-
npm_config_mode_test_save2=1 npm test
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
23
|
/*jslint beta, node*/
|
|
29
24
|
import moduleChildProcess from "child_process";
|
|
30
25
|
import modulePath from "path";
|
|
@@ -199,7 +194,7 @@ jstestDescribe((
|
|
|
199
194
|
), function test_dbBind() {
|
|
200
195
|
jstestIt((
|
|
201
196
|
"test db-bind handling-behavior"
|
|
202
|
-
), async function
|
|
197
|
+
), async function () {
|
|
203
198
|
let db;
|
|
204
199
|
async function test_dbBind_exec(ii, valIn, valExpect) {
|
|
205
200
|
await Promise.all([
|
|
@@ -2155,15 +2150,13 @@ DROP TABLE IF EXISTS __tmp1;
|
|
|
2155
2150
|
CREATE TEMP TABLE __tmp1 (val REAL);
|
|
2156
2151
|
SELECT
|
|
2157
2152
|
1 AS id,
|
|
2158
|
-
MEDIAN2(val) AS mdn,
|
|
2159
|
-
QUANTILE(val, 0.5) AS qnt,
|
|
2160
2153
|
STDEV(val) AS std
|
|
2161
2154
|
FROM __tmp1;
|
|
2162
2155
|
`)
|
|
2163
2156
|
});
|
|
2164
2157
|
assertJsonEqual(
|
|
2165
2158
|
valActual,
|
|
2166
|
-
[{id: 1,
|
|
2159
|
+
[{id: 1, std: null}]
|
|
2167
2160
|
);
|
|
2168
2161
|
}());
|
|
2169
2162
|
await Promise.all([
|
|
@@ -2226,20 +2219,12 @@ SELECT
|
|
|
2226
2219
|
]) {
|
|
2227
2220
|
let avg = 0;
|
|
2228
2221
|
let data2;
|
|
2229
|
-
let valExpectMdn;
|
|
2230
2222
|
let valExpectStd = 0;
|
|
2231
2223
|
data2 = data.map(function (elem) {
|
|
2232
2224
|
return Number(elem);
|
|
2233
2225
|
}).filter(function (elem) {
|
|
2234
2226
|
return Number.isFinite(elem);
|
|
2235
2227
|
}).sort();
|
|
2236
|
-
valExpectMdn = (
|
|
2237
|
-
data2.length % 2 === 0
|
|
2238
|
-
? 0.5 * (
|
|
2239
|
-
data2[0.5 * data2.length - 1] + data2[0.5 * data2.length]
|
|
2240
|
-
)
|
|
2241
|
-
: data2[0.5 * (data2.length - 1)]
|
|
2242
|
-
);
|
|
2243
2228
|
data2.forEach(function (elem) {
|
|
2244
2229
|
avg += elem;
|
|
2245
2230
|
});
|
|
@@ -2267,12 +2252,8 @@ SELECT
|
|
|
2267
2252
|
},
|
|
2268
2253
|
db,
|
|
2269
2254
|
sql: (`
|
|
2270
|
-
-- test null-case handling-behavior
|
|
2271
|
-
SELECT QUANTILE(value, ${qq}) AS qnt FROM JSON_EACH($tmp1) WHERE 0;
|
|
2272
2255
|
-- test last-row handling-behavior
|
|
2273
2256
|
SELECT
|
|
2274
|
-
MEDIAN2(value) AS mdn,
|
|
2275
|
-
QUANTILE(value, ${qq}) AS qnt,
|
|
2276
2257
|
ROUND(stdev(value), 8) AS std
|
|
2277
2258
|
FROM JSON_EACH($tmp1);
|
|
2278
2259
|
`)
|
|
@@ -2280,8 +2261,6 @@ SELECT
|
|
|
2280
2261
|
assertJsonEqual(
|
|
2281
2262
|
valActual,
|
|
2282
2263
|
{
|
|
2283
|
-
mdn: valExpectMdn,
|
|
2284
|
-
qnt: valExpect ?? null,
|
|
2285
2264
|
std: valExpectStd
|
|
2286
2265
|
},
|
|
2287
2266
|
{
|
|
@@ -2289,7 +2268,6 @@ SELECT
|
|
|
2289
2268
|
qq,
|
|
2290
2269
|
valActual,
|
|
2291
2270
|
valExpect,
|
|
2292
|
-
valExpectMdn,
|
|
2293
2271
|
valExpectStd
|
|
2294
2272
|
}
|
|
2295
2273
|
);
|
|
@@ -3269,7 +3247,7 @@ SELECT
|
|
|
3269
3247
|
"id2": 3,
|
|
3270
3248
|
"laa": -4.5,
|
|
3271
3249
|
"lbb": 2.5,
|
|
3272
|
-
"lee": 0.
|
|
3250
|
+
"lee": 0.70710678,
|
|
3273
3251
|
"lxy": 0.94491118,
|
|
3274
3252
|
"lyy": 3,
|
|
3275
3253
|
"mee": 1.52752523,
|
|
@@ -3289,7 +3267,7 @@ SELECT
|
|
|
3289
3267
|
"id2": 4,
|
|
3290
3268
|
"laa": -3,
|
|
3291
3269
|
"lbb": 1.81818182,
|
|
3292
|
-
"lee": 0.
|
|
3270
|
+
"lee": 0.67419986,
|
|
3293
3271
|
"lxy": 0.95346259,
|
|
3294
3272
|
"lyy": 4.27272727,
|
|
3295
3273
|
"mee": 1.82574186,
|
|
@@ -3309,7 +3287,7 @@ SELECT
|
|
|
3309
3287
|
"id2": 5,
|
|
3310
3288
|
"laa": -2.29411765,
|
|
3311
3289
|
"lbb": 1.52941176,
|
|
3312
|
-
"lee": 0.
|
|
3290
|
+
"lee": 0.65678958,
|
|
3313
3291
|
"lxy": 0.96164474,
|
|
3314
3292
|
"lyy": 5.35294118,
|
|
3315
3293
|
"mee": 2.07364414,
|
|
@@ -3329,7 +3307,7 @@ SELECT
|
|
|
3329
3307
|
"id2": 6,
|
|
3330
3308
|
"laa": -2.54385965,
|
|
3331
3309
|
"lbb": 1.63157895,
|
|
3332
|
-
"lee": 0.
|
|
3310
|
+
"lee": 0.62126074,
|
|
3333
3311
|
"lxy": 0.97080629,
|
|
3334
3312
|
"lyy": 5.61403509,
|
|
3335
3313
|
"mee": 2.31660671,
|
|
@@ -3349,7 +3327,7 @@ SELECT
|
|
|
3349
3327
|
"id2": 7,
|
|
3350
3328
|
"laa": -2.65,
|
|
3351
3329
|
"lbb": 1.675,
|
|
3352
|
-
"lee": 0.
|
|
3330
|
+
"lee": 0.57445626,
|
|
3353
3331
|
"lxy": 0.9752227,
|
|
3354
3332
|
"lyy": 5.725,
|
|
3355
3333
|
"mee": 2.37045304,
|
|
@@ -3369,7 +3347,7 @@ SELECT
|
|
|
3369
3347
|
"id2": 8,
|
|
3370
3348
|
"laa": -2.5,
|
|
3371
3349
|
"lbb": 1.625,
|
|
3372
|
-
"lee": 0.
|
|
3350
|
+
"lee": 0.54006172,
|
|
3373
3351
|
"lxy": 0.97991187,
|
|
3374
3352
|
"lyy": 7.25,
|
|
3375
3353
|
"mee": 2.50713268,
|
|
@@ -3389,7 +3367,7 @@ SELECT
|
|
|
3389
3367
|
"id2": 9,
|
|
3390
3368
|
"laa": 0.75,
|
|
3391
3369
|
"lbb": 0.85,
|
|
3392
|
-
"lee":
|
|
3370
|
+
"lee": 1.08781126,
|
|
3393
3371
|
"lxy": 0.89597867,
|
|
3394
3372
|
"lyy": 9.25,
|
|
3395
3373
|
"mee": 2.26778684,
|
|
@@ -3409,7 +3387,7 @@ SELECT
|
|
|
3409
3387
|
"id2": 10,
|
|
3410
3388
|
"laa": 2.75,
|
|
3411
3389
|
"lbb": 0.55,
|
|
3412
|
-
"lee": 0.
|
|
3390
|
+
"lee": 0.99163165,
|
|
3413
3391
|
"lxy": 0.81989159,
|
|
3414
3392
|
"lyy": 3.85,
|
|
3415
3393
|
"mee": 1.60356745,
|
|
@@ -3451,6 +3429,15 @@ SELECT WIN_SINEFIT2(1, 2, 3) FROM (SELECT 1);
|
|
|
3451
3429
|
`)
|
|
3452
3430
|
});
|
|
3453
3431
|
}, "wrong number of arguments");
|
|
3432
|
+
// test win_sinefit2-modeSnr-bitmask-overflow handling-behavior
|
|
3433
|
+
await assertErrorThrownAsync(function () {
|
|
3434
|
+
return dbExecAsync({
|
|
3435
|
+
db,
|
|
3436
|
+
sql: (`
|
|
3437
|
+
SELECT WIN_SINEFIT2(1, 2${", 3, 4".repeat(31)}) FROM (SELECT 1);
|
|
3438
|
+
`)
|
|
3439
|
+
});
|
|
3440
|
+
}, "too many columns");
|
|
3454
3441
|
// test win_sinefit2-null-case handling-behavior
|
|
3455
3442
|
valActual = await dbExecAndReturnLastTable({
|
|
3456
3443
|
db,
|
|
@@ -3465,6 +3452,323 @@ SELECT DOUBLEARRAY_JSONTO(WIN_SINEFIT2(1, 2, 3, 4)) FROM __tmp1;
|
|
|
3465
3452
|
});
|
|
3466
3453
|
assertJsonEqual(valActual, [null]);
|
|
3467
3454
|
}()),
|
|
3455
|
+
(async function () {
|
|
3456
|
+
let valActual;
|
|
3457
|
+
let valSine = JSON.stringify(Array.from({
|
|
3458
|
+
length: 64
|
|
3459
|
+
}, function (ignore, ii) {
|
|
3460
|
+
return [ii + 1, Math.sin(0.5 * (ii + 1)) + 0.1 * ii];
|
|
3461
|
+
}));
|
|
3462
|
+
// test win_sinefit2-modeSnr-bitmask handling-behavior
|
|
3463
|
+
// Mask 0b110 is inverted on purpose - column 0 must NOT be
|
|
3464
|
+
// sine-fit. A build that re-hardcodes column 0, or that
|
|
3465
|
+
// treats modeSnr as an all-or-nothing flag, fails here.
|
|
3466
|
+
valActual = await dbExecAndReturnLastTable({
|
|
3467
|
+
bindList: {
|
|
3468
|
+
valSine
|
|
3469
|
+
},
|
|
3470
|
+
db,
|
|
3471
|
+
sql: (`
|
|
3472
|
+
SELECT
|
|
3473
|
+
SINEFIT_EXTRACT(__wsf, 0, 'sww', 0) = 0 AS sww0_off,
|
|
3474
|
+
SINEFIT_EXTRACT(__wsf, 1, 'sww', 0) > 0 AS sww1_on,
|
|
3475
|
+
SINEFIT_EXTRACT(__wsf, 2, 'sww', 0) > 0 AS sww2_on,
|
|
3476
|
+
SINEFIT_EXTRACT(__wsf, 0, 'rrb', 0) IS NOT NULL AS lnr0_on
|
|
3477
|
+
FROM (
|
|
3478
|
+
SELECT
|
|
3479
|
+
key,
|
|
3480
|
+
WIN_SINEFIT2(
|
|
3481
|
+
6, NULL,
|
|
3482
|
+
value->>0, value->>1,
|
|
3483
|
+
value->>0, value->>1,
|
|
3484
|
+
value->>0, value->>1
|
|
3485
|
+
) OVER (
|
|
3486
|
+
ORDER BY key ASC
|
|
3487
|
+
ROWS BETWEEN 31 PRECEDING AND 0 FOLLOWING
|
|
3488
|
+
) AS __wsf
|
|
3489
|
+
FROM JSON_EACH($valSine)
|
|
3490
|
+
)
|
|
3491
|
+
WHERE key = 63;
|
|
3492
|
+
`)
|
|
3493
|
+
});
|
|
3494
|
+
valActual = valActual.map(function (elem) {
|
|
3495
|
+
return [
|
|
3496
|
+
elem.sww0_off,
|
|
3497
|
+
elem.sww1_on,
|
|
3498
|
+
elem.sww2_on,
|
|
3499
|
+
elem.lnr0_on
|
|
3500
|
+
];
|
|
3501
|
+
});
|
|
3502
|
+
assertJsonEqual(valActual, [[1, 1, 1, 1]]);
|
|
3503
|
+
}()),
|
|
3504
|
+
(async function () {
|
|
3505
|
+
let valActual;
|
|
3506
|
+
let valSine = JSON.stringify(Array.from({
|
|
3507
|
+
length: 64
|
|
3508
|
+
}, function (ignore, ii) {
|
|
3509
|
+
return [ii + 1, Math.sin(0.5 * (ii + 1)) + 0.1 * ii];
|
|
3510
|
+
}));
|
|
3511
|
+
// test sinefit_extract-dof handling-behavior
|
|
3512
|
+
// lee divides by nnn-2 (laa, lbb) and see by nnn-5 (those
|
|
3513
|
+
// plus saa, spp, sww). Pin the divisors by comparing a
|
|
3514
|
+
// 32-row window against an 8-row one - the ratio of the
|
|
3515
|
+
// two is free of the unknown residual sum-of-squares only
|
|
3516
|
+
// if we instead check the small-window NULL boundaries,
|
|
3517
|
+
// which is what this does: lee goes NULL at nnn <= 2 and
|
|
3518
|
+
// see at nnn <= 5, and both are finite one row later.
|
|
3519
|
+
valActual = await dbExecAndReturnLastTable({
|
|
3520
|
+
bindList: {
|
|
3521
|
+
valSine
|
|
3522
|
+
},
|
|
3523
|
+
db,
|
|
3524
|
+
sql: (`
|
|
3525
|
+
SELECT
|
|
3526
|
+
SINEFIT_EXTRACT(__wsf02, 0, 'lee', 0) IS NULL AS lee_null_at_2,
|
|
3527
|
+
SINEFIT_EXTRACT(__wsf03, 0, 'lee', 0) > 0 AS lee_ok_at_3,
|
|
3528
|
+
SINEFIT_EXTRACT(__wsf05, 0, 'see', 0) IS NULL AS see_null_at_5,
|
|
3529
|
+
SINEFIT_EXTRACT(__wsf06, 0, 'see', 0) >= 0 AS see_ok_at_6
|
|
3530
|
+
FROM (
|
|
3531
|
+
SELECT
|
|
3532
|
+
key,
|
|
3533
|
+
WIN_SINEFIT2(1, NULL, value->>0, value->>1) OVER (
|
|
3534
|
+
ORDER BY key ASC ROWS BETWEEN 1 PRECEDING AND 0 FOLLOWING
|
|
3535
|
+
) AS __wsf02,
|
|
3536
|
+
WIN_SINEFIT2(1, NULL, value->>0, value->>1) OVER (
|
|
3537
|
+
ORDER BY key ASC ROWS BETWEEN 2 PRECEDING AND 0 FOLLOWING
|
|
3538
|
+
) AS __wsf03,
|
|
3539
|
+
WIN_SINEFIT2(1, NULL, value->>0, value->>1) OVER (
|
|
3540
|
+
ORDER BY key ASC ROWS BETWEEN 4 PRECEDING AND 0 FOLLOWING
|
|
3541
|
+
) AS __wsf05,
|
|
3542
|
+
WIN_SINEFIT2(1, NULL, value->>0, value->>1) OVER (
|
|
3543
|
+
ORDER BY key ASC ROWS BETWEEN 5 PRECEDING AND 0 FOLLOWING
|
|
3544
|
+
) AS __wsf06
|
|
3545
|
+
FROM JSON_EACH($valSine)
|
|
3546
|
+
)
|
|
3547
|
+
WHERE key = 63;
|
|
3548
|
+
`)
|
|
3549
|
+
});
|
|
3550
|
+
valActual = valActual.map(function (elem) {
|
|
3551
|
+
return [
|
|
3552
|
+
elem.lee_null_at_2,
|
|
3553
|
+
elem.lee_ok_at_3,
|
|
3554
|
+
elem.see_null_at_5,
|
|
3555
|
+
elem.see_ok_at_6
|
|
3556
|
+
];
|
|
3557
|
+
});
|
|
3558
|
+
assertJsonEqual(valActual, [[1, 1, 1, 1]]);
|
|
3559
|
+
}()),
|
|
3560
|
+
// test win_sinefit2-empty-frame handling-behavior
|
|
3561
|
+
(async function () {
|
|
3562
|
+
// WIN_SINEFIT_N = 23 doubles = 184 bytes per column
|
|
3563
|
+
const nhead = 23 * 8;
|
|
3564
|
+
// Frame "5 PRECEDING AND 3 PRECEDING" is empty for rows 1-3, so
|
|
3565
|
+
// sqlite calls xValue before the first xStep. Regression-test that
|
|
3566
|
+
// xValue does not allocate an aggregate-context with nhead=0, which
|
|
3567
|
+
// would pin nhead=0 for the life of the aggregate and alias
|
|
3568
|
+
// doublewinHead() onto doublewinBody(). ncol=2 additionally
|
|
3569
|
+
// overflows the 304-byte nhead=0 allocation, needing 2*184+48 = 416
|
|
3570
|
+
// bytes of head.
|
|
3571
|
+
assertJsonEqual(
|
|
3572
|
+
noop(
|
|
3573
|
+
await dbExecAsync({
|
|
3574
|
+
db,
|
|
3575
|
+
sql: (`
|
|
3576
|
+
CREATE TABLE testWinSinefit2Emptyframe AS
|
|
3577
|
+
SELECT 1 AS xx, 1 AS yy
|
|
3578
|
+
--
|
|
3579
|
+
UNION ALL VALUES
|
|
3580
|
+
(2, 2),
|
|
3581
|
+
(3, 3),
|
|
3582
|
+
(4, 4),
|
|
3583
|
+
(5, 5),
|
|
3584
|
+
(6, 6),
|
|
3585
|
+
(7, 7),
|
|
3586
|
+
(8, 8);
|
|
3587
|
+
|
|
3588
|
+
-- empty-window-frame
|
|
3589
|
+
SELECT
|
|
3590
|
+
LENGTH(WIN_SINEFIT2(0, NULL, xx, yy) OVER (
|
|
3591
|
+
ORDER BY xx
|
|
3592
|
+
ROWS BETWEEN 5 PRECEDING AND 3 PRECEDING
|
|
3593
|
+
)) AS nhead
|
|
3594
|
+
FROM testWinSinefit2Emptyframe;
|
|
3595
|
+
|
|
3596
|
+
-- empty-window-frame multi-column
|
|
3597
|
+
SELECT
|
|
3598
|
+
LENGTH(WIN_SINEFIT2(0, NULL, xx, yy, xx, yy * 2) OVER (
|
|
3599
|
+
ORDER BY xx
|
|
3600
|
+
ROWS BETWEEN 5 PRECEDING AND 3 PRECEDING
|
|
3601
|
+
)) AS nhead
|
|
3602
|
+
FROM testWinSinefit2Emptyframe;
|
|
3603
|
+
-- non-empty-window-frame control
|
|
3604
|
+
SELECT
|
|
3605
|
+
LENGTH(WIN_SINEFIT2(0, NULL, xx, yy) OVER (
|
|
3606
|
+
ORDER BY xx
|
|
3607
|
+
ROWS BETWEEN 5 PRECEDING AND CURRENT ROW
|
|
3608
|
+
)) AS nhead
|
|
3609
|
+
FROM testWinSinefit2Emptyframe;
|
|
3610
|
+
|
|
3611
|
+
-- sinefit-object is well-formed
|
|
3612
|
+
-- row 8 frame = rows 3-5, so nnn = 3
|
|
3613
|
+
WITH tmp1 AS (
|
|
3614
|
+
SELECT
|
|
3615
|
+
xx,
|
|
3616
|
+
win_sinefit2(0, NULL, xx, yy, xx, yy * 2) OVER (
|
|
3617
|
+
ORDER BY xx
|
|
3618
|
+
ROWS BETWEEN 5 PRECEDING AND 3 PRECEDING
|
|
3619
|
+
) AS wsf
|
|
3620
|
+
FROM testWinSinefit2Emptyframe
|
|
3621
|
+
)
|
|
3622
|
+
SELECT
|
|
3623
|
+
SINEFIT_EXTRACT(wsf, 0, 'nnn', 0) AS nnn0,
|
|
3624
|
+
SINEFIT_EXTRACT(wsf, 1, 'nnn', 0) AS nnn1,
|
|
3625
|
+
SINEFIT_EXTRACT(wsf, 0, 'lbb', 0) AS lbb0,
|
|
3626
|
+
SINEFIT_EXTRACT(wsf, 1, 'lbb', 0) AS lbb1
|
|
3627
|
+
FROM tmp1
|
|
3628
|
+
WHERE xx = 8;
|
|
3629
|
+
-- empty-table xFinal
|
|
3630
|
+
SELECT LENGTH(WIN_SINEFIT2(0, NULL, xx, yy)) AS nhead
|
|
3631
|
+
FROM testWinSinefit2Emptyframe
|
|
3632
|
+
WHERE 0;
|
|
3633
|
+
`)
|
|
3634
|
+
})
|
|
3635
|
+
),
|
|
3636
|
+
[
|
|
3637
|
+
[
|
|
3638
|
+
{nhead: 0},
|
|
3639
|
+
{nhead: 0},
|
|
3640
|
+
{nhead: 0},
|
|
3641
|
+
{nhead},
|
|
3642
|
+
{nhead},
|
|
3643
|
+
{nhead},
|
|
3644
|
+
{nhead},
|
|
3645
|
+
{nhead}
|
|
3646
|
+
],
|
|
3647
|
+
[
|
|
3648
|
+
{nhead: 0},
|
|
3649
|
+
{nhead: 0},
|
|
3650
|
+
{nhead: 0},
|
|
3651
|
+
{nhead: 2 * nhead},
|
|
3652
|
+
{nhead: 2 * nhead},
|
|
3653
|
+
{nhead: 2 * nhead},
|
|
3654
|
+
{nhead: 2 * nhead},
|
|
3655
|
+
{nhead: 2 * nhead}
|
|
3656
|
+
],
|
|
3657
|
+
[
|
|
3658
|
+
{nhead},
|
|
3659
|
+
{nhead},
|
|
3660
|
+
{nhead},
|
|
3661
|
+
{nhead},
|
|
3662
|
+
{nhead},
|
|
3663
|
+
{nhead},
|
|
3664
|
+
{nhead},
|
|
3665
|
+
{nhead}
|
|
3666
|
+
],
|
|
3667
|
+
[
|
|
3668
|
+
{lbb0: 1, lbb1: 2, nnn0: 3, nnn1: 3}
|
|
3669
|
+
],
|
|
3670
|
+
[
|
|
3671
|
+
{nhead: 0}
|
|
3672
|
+
]
|
|
3673
|
+
]
|
|
3674
|
+
);
|
|
3675
|
+
}()),
|
|
3676
|
+
// test sinefit_refitlast malformed-blob handling-behavior
|
|
3677
|
+
(async function () {
|
|
3678
|
+
// WinSinefit field-offsets, in bytes
|
|
3679
|
+
let offsetNnn = 5 * 8;
|
|
3680
|
+
let offsetWbb = 16 * 8;
|
|
3681
|
+
function blobMalformed(nnn, wbb) {
|
|
3682
|
+
// ncol=1 header = WIN_SINEFIT_N * 8 = 184 bytes
|
|
3683
|
+
let buf = new ArrayBuffer(184);
|
|
3684
|
+
let dv = new DataView(buf);
|
|
3685
|
+
dv.setFloat64(offsetNnn, nnn, true);
|
|
3686
|
+
dv.setFloat64(offsetWbb, wbb, true);
|
|
3687
|
+
return new Uint8Array(buf);
|
|
3688
|
+
}
|
|
3689
|
+
// test malformed-nnn handling-behavior
|
|
3690
|
+
await Promise.all([
|
|
3691
|
+
0 / 0, // nan
|
|
3692
|
+
1 / 0, // inf
|
|
3693
|
+
-1 / 0, // -inf
|
|
3694
|
+
1e300, // overflows (int)
|
|
3695
|
+
-1, // negative
|
|
3696
|
+
0, // empty
|
|
3697
|
+
1.5 // non-integral
|
|
3698
|
+
].map(function (nnn) {
|
|
3699
|
+
return assertErrorThrownAsync(function () {
|
|
3700
|
+
return dbExecAsync({
|
|
3701
|
+
bindList: [blobMalformed(nnn, 0)],
|
|
3702
|
+
db,
|
|
3703
|
+
sql: "SELECT sinefit_refitlast(?1, 0, 0)"
|
|
3704
|
+
});
|
|
3705
|
+
}, "sinefit_refitlast");
|
|
3706
|
+
}));
|
|
3707
|
+
// test malformed-wbb handling-behavior
|
|
3708
|
+
// nnn=1 implies nbody = 3, so any wbb but 0 is invalid.
|
|
3709
|
+
await Promise.all([
|
|
3710
|
+
0 / 0, 1 / 0, 1e300, -1, 1, 2, 3, 1.5
|
|
3711
|
+
].map(function (wbb) {
|
|
3712
|
+
return assertErrorThrownAsync(function () {
|
|
3713
|
+
return dbExecAsync({
|
|
3714
|
+
bindList: [blobMalformed(1, wbb)],
|
|
3715
|
+
db,
|
|
3716
|
+
sql: "SELECT sinefit_refitlast(?1, 0, 0)"
|
|
3717
|
+
});
|
|
3718
|
+
}, "sinefit_refitlast");
|
|
3719
|
+
}));
|
|
3720
|
+
// test truncated-blob handling-behavior
|
|
3721
|
+
await assertErrorThrownAsync(function () {
|
|
3722
|
+
return dbExecAsync({
|
|
3723
|
+
bindList: [new Uint8Array(100)],
|
|
3724
|
+
db,
|
|
3725
|
+
sql: "SELECT sinefit_refitlast(?1, 0, 0)"
|
|
3726
|
+
});
|
|
3727
|
+
}, "sinefit_refitlast");
|
|
3728
|
+
// test wrong-argc handling-behavior
|
|
3729
|
+
await assertErrorThrownAsync(function () {
|
|
3730
|
+
return dbExecAsync({
|
|
3731
|
+
bindList: [blobMalformed(1, 0)],
|
|
3732
|
+
db,
|
|
3733
|
+
sql: "SELECT sinefit_refitlast(?1, 0)"
|
|
3734
|
+
});
|
|
3735
|
+
}, "sinefit_refitlast");
|
|
3736
|
+
}()),
|
|
3737
|
+
// test sinefit_extract non-blob 1st-argument handling-behavior
|
|
3738
|
+
(async function () {
|
|
3739
|
+
await Promise.all([
|
|
3740
|
+
"'hello'",
|
|
3741
|
+
"123",
|
|
3742
|
+
"1.5",
|
|
3743
|
+
"NULL",
|
|
3744
|
+
"zeroblob(0)"
|
|
3745
|
+
].map(function (arg) {
|
|
3746
|
+
return assertErrorThrownAsync(function () {
|
|
3747
|
+
return dbExecAsync({
|
|
3748
|
+
db,
|
|
3749
|
+
sql: `SELECT sinefit_extract(${arg}, 0, 'nnn', 0)`
|
|
3750
|
+
});
|
|
3751
|
+
}, "sinefit_extract");
|
|
3752
|
+
}));
|
|
3753
|
+
}()),
|
|
3754
|
+
// test win_sinefit2-aggregate-normal handling-behavior
|
|
3755
|
+
(async function () {
|
|
3756
|
+
// test non-blob 1st-argument handling-behavior
|
|
3757
|
+
await Promise.all([
|
|
3758
|
+
"'hello'",
|
|
3759
|
+
"123",
|
|
3760
|
+
"1.5",
|
|
3761
|
+
"NULL",
|
|
3762
|
+
"zeroblob(0)"
|
|
3763
|
+
].map(function (arg) {
|
|
3764
|
+
return assertErrorThrownAsync(function () {
|
|
3765
|
+
return dbExecAsync({
|
|
3766
|
+
db,
|
|
3767
|
+
sql: `SELECT sinefit_extract(${arg}, 0, 'nnn', 0)`
|
|
3768
|
+
});
|
|
3769
|
+
}, "sinefit_extract");
|
|
3770
|
+
}));
|
|
3771
|
+
}()),
|
|
3468
3772
|
// test win_sinefit2-aggregate-normal handling-behavior
|
|
3469
3773
|
(async function () {
|
|
3470
3774
|
let valActual;
|
|
@@ -3494,7 +3798,7 @@ SELECT
|
|
|
3494
3798
|
"gyy": 0.19611614,
|
|
3495
3799
|
"laa": 0.77941176,
|
|
3496
3800
|
"lbb": 0.84558824,
|
|
3497
|
-
"lee": 1.
|
|
3801
|
+
"lee": 1.56536502,
|
|
3498
3802
|
"lxy": 0.81541829,
|
|
3499
3803
|
"lyy": 2.47058824,
|
|
3500
3804
|
"mee": 2.54950976,
|
|
@@ -3520,7 +3824,7 @@ SELECT
|
|
|
3520
3824
|
"gyy": -1.02062073,
|
|
3521
3825
|
"laa": -0.82025678,
|
|
3522
3826
|
"lbb": 0.14621969,
|
|
3523
|
-
"lee": 2.
|
|
3827
|
+
"lee": 2.74202904,
|
|
3524
3828
|
"lxy": 0.865665,
|
|
3525
3829
|
"lyy": 6.63694722,
|
|
3526
3830
|
"mee": 4.89897949,
|
|
@@ -3566,7 +3870,7 @@ SELECT
|
|
|
3566
3870
|
"id2": id3,
|
|
3567
3871
|
"laa": 5.25,
|
|
3568
3872
|
"lbb": -0.275,
|
|
3569
|
-
"lee": 2.
|
|
3873
|
+
"lee": 2.88241797,
|
|
3570
3874
|
"lxy": -0.23918696,
|
|
3571
3875
|
"lyy": 2.5,
|
|
3572
3876
|
"mee": 2.74837614,
|
|
@@ -3586,7 +3890,7 @@ SELECT
|
|
|
3586
3890
|
"id2": id4,
|
|
3587
3891
|
"laa": 7.25,
|
|
3588
3892
|
"lbb": -0.575,
|
|
3589
|
-
"lee":
|
|
3893
|
+
"lee": 2.26016224,
|
|
3590
3894
|
"lxy": -0.5490214,
|
|
3591
3895
|
"lyy": 6.1,
|
|
3592
3896
|
"mee": 2.50356888,
|
|
@@ -3918,7 +4222,7 @@ SELECT
|
|
|
3918
4222
|
FROM __sinefit_csv
|
|
3919
4223
|
JOIN (
|
|
3920
4224
|
SELECT
|
|
3921
|
-
|
|
4225
|
+
MEDIAN(rr) AS rr_avg,
|
|
3922
4226
|
STDEV(rr) AS rr_err
|
|
3923
4227
|
FROM __sinefit_csv
|
|
3924
4228
|
)
|