alasql 4.2.3 → 4.2.5
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/README.md +6 -5
- package/build.sh +1 -7
- package/dist/alasql-worker.js +2 -2
- package/dist/alasql.d.ts +93 -0
- package/dist/alasql.fs.js +191 -329
- package/dist/alasql.js +191 -329
- package/dist/alasql.min.js +48 -48
- package/package.json +5 -4
- package/types/alasql.d.ts +93 -0
- package/Untitled-1.js +0 -1
package/dist/alasql.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v4.2.
|
|
1
|
+
//! AlaSQL v4.2.4 build: develop-25518d61 | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 4.2.
|
|
4
|
+
@version 4.2.4
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2023 Andrey Gershun & Mathias Wulff
|
|
@@ -141,8 +141,8 @@ var alasql = function(sql, params, cb, scope) {
|
|
|
141
141
|
Current version of alasql
|
|
142
142
|
@constant {string}
|
|
143
143
|
*/
|
|
144
|
-
alasql.version = '4.2.
|
|
145
|
-
alasql.build = 'develop-
|
|
144
|
+
alasql.version = '4.2.4';
|
|
145
|
+
alasql.build = 'develop-25518d61';
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
Debug flag
|
|
@@ -5291,7 +5291,7 @@ yy.Statements = class Statements {
|
|
|
5291
5291
|
const res = statements.map(st => st(params));
|
|
5292
5292
|
if (cb) cb(res);
|
|
5293
5293
|
return res;
|
|
5294
|
-
|
|
5294
|
+
};
|
|
5295
5295
|
}
|
|
5296
5296
|
};
|
|
5297
5297
|
/* global alasql */
|
|
@@ -6630,7 +6630,11 @@ function queryfn3(query) {
|
|
|
6630
6630
|
|
|
6631
6631
|
for (const key in query.groupColumns) {
|
|
6632
6632
|
// ony remove columns where the alias is also not a column in the result
|
|
6633
|
-
if (
|
|
6633
|
+
if (
|
|
6634
|
+
query.groupColumns[key] !== key &&
|
|
6635
|
+
d[query.groupColumns[key]] &&
|
|
6636
|
+
!query.groupColumns[query.groupColumns[key]]
|
|
6637
|
+
) {
|
|
6634
6638
|
delete d[query.groupColumns[key]];
|
|
6635
6639
|
}
|
|
6636
6640
|
}
|
|
@@ -10223,14 +10227,6 @@ yy.Over = class Over {
|
|
|
10223
10227
|
return s;
|
|
10224
10228
|
}
|
|
10225
10229
|
};
|
|
10226
|
-
/*
|
|
10227
|
-
//
|
|
10228
|
-
// Expressions for Alasql.js
|
|
10229
|
-
// Date: 03.11.2014
|
|
10230
|
-
// (c) 2014, Andrey Gershun
|
|
10231
|
-
//
|
|
10232
|
-
*/
|
|
10233
|
-
|
|
10234
10230
|
{
|
|
10235
10231
|
const assign = Object.assign;
|
|
10236
10232
|
|
|
@@ -10421,63 +10417,42 @@ yy.Over = class Over {
|
|
|
10421
10417
|
}
|
|
10422
10418
|
}
|
|
10423
10419
|
|
|
10420
|
+
const toTypeNumberOps = new Set(['-', '*', '/', '%', '^']);
|
|
10421
|
+
const toTypeStringOps = new Set(['||']);
|
|
10422
|
+
const toTypeBoolOps = new Set([
|
|
10423
|
+
'AND', 'OR', 'NOT', '=', '==', '===', '!=', '!==', '!===',
|
|
10424
|
+
'>', '>=', '<', '<=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE',
|
|
10425
|
+
'REGEXP', 'GLOB', 'BETWEEN', 'NOT BETWEEN', 'IS NULL', 'IS NOT NULL'
|
|
10426
|
+
]);
|
|
10424
10427
|
class Op {
|
|
10425
10428
|
constructor(params) {
|
|
10426
10429
|
assign(this, params);
|
|
10427
10430
|
}
|
|
10428
10431
|
|
|
10429
10432
|
toString() {
|
|
10433
|
+
const leftStr = this.left.toString();
|
|
10434
|
+
let s;
|
|
10435
|
+
|
|
10430
10436
|
if (this.op === 'IN' || this.op === 'NOT IN') {
|
|
10431
|
-
return
|
|
10437
|
+
return `${leftStr} ${this.op} (${this.right.toString()})`;
|
|
10432
10438
|
}
|
|
10439
|
+
|
|
10433
10440
|
if (this.allsome) {
|
|
10434
|
-
return (
|
|
10435
|
-
this.left.toString() +
|
|
10436
|
-
' ' +
|
|
10437
|
-
this.op +
|
|
10438
|
-
' ' +
|
|
10439
|
-
this.allsome +
|
|
10440
|
-
' (' +
|
|
10441
|
-
this.right.toString() +
|
|
10442
|
-
')'
|
|
10443
|
-
);
|
|
10441
|
+
return `${leftStr} ${this.op} ${this.allsome} (${this.right.toString()})`;
|
|
10444
10442
|
}
|
|
10445
|
-
if (this.op === '->' || this.op === '!') {
|
|
10446
|
-
var s = this.left.toString() + this.op;
|
|
10447
|
-
|
|
10448
|
-
if (typeof this.right !== 'string' && typeof this.right !== 'number') {
|
|
10449
|
-
s += '(';
|
|
10450
|
-
}
|
|
10451
|
-
|
|
10452
|
-
s += this.right.toString();
|
|
10453
|
-
|
|
10454
|
-
if (typeof this.right !== 'string' && typeof this.right !== 'number') {
|
|
10455
|
-
s += ')';
|
|
10456
|
-
}
|
|
10457
10443
|
|
|
10458
|
-
|
|
10444
|
+
if (this.op === '->' || this.op === '!') {
|
|
10445
|
+
s = `${leftStr}${this.op}`;
|
|
10446
|
+
if (typeof this.right !== 'string' && typeof this.right !== 'number')
|
|
10447
|
+
return s + `(${this.right.toString()})`;
|
|
10448
|
+
return s + this.right.toString();
|
|
10459
10449
|
}
|
|
10460
|
-
if (this.op === 'BETWEEN' || this.op === 'NOT BETWEEN') {
|
|
10461
|
-
var s =
|
|
10462
|
-
this.left.toString() +
|
|
10463
|
-
' ' +
|
|
10464
|
-
this.op +
|
|
10465
|
-
' ' +
|
|
10466
|
-
this.right1.toString() +
|
|
10467
|
-
' AND ' +
|
|
10468
|
-
this.right2.toString();
|
|
10469
10450
|
|
|
10470
|
-
|
|
10451
|
+
if (this.op === 'BETWEEN' || this.op === 'NOT BETWEEN') {
|
|
10452
|
+
return `${leftStr} ${this.op} ${this.right1.toString()} AND ${this.right2.toString()}`;
|
|
10471
10453
|
}
|
|
10472
10454
|
|
|
10473
|
-
return (
|
|
10474
|
-
this.left.toString() +
|
|
10475
|
-
' ' +
|
|
10476
|
-
this.op +
|
|
10477
|
-
' ' +
|
|
10478
|
-
(this.allsome ? this.allsome + ' ' : '') +
|
|
10479
|
-
this.right.toString()
|
|
10480
|
-
);
|
|
10455
|
+
return `${leftStr} ${this.op} ${this.allsome ? this.allsome + ' ' : ''}${this.right.toString()}`;
|
|
10481
10456
|
}
|
|
10482
10457
|
|
|
10483
10458
|
findAggregator(query) {
|
|
@@ -10491,65 +10466,29 @@ yy.Over = class Over {
|
|
|
10491
10466
|
}
|
|
10492
10467
|
|
|
10493
10468
|
toType(tableid) {
|
|
10494
|
-
if (
|
|
10469
|
+
if (toTypeNumberOps.has(this.op))
|
|
10495
10470
|
return 'number';
|
|
10496
|
-
}
|
|
10497
10471
|
|
|
10498
|
-
if (
|
|
10472
|
+
if (toTypeStringOps.has(this.op))
|
|
10499
10473
|
return 'string';
|
|
10500
|
-
}
|
|
10501
10474
|
|
|
10502
10475
|
if (this.op === '+') {
|
|
10503
|
-
|
|
10476
|
+
const leftType = this.left.toType(tableid);
|
|
10477
|
+
const rightType = this.right.toType(tableid);
|
|
10478
|
+
|
|
10479
|
+
if (leftType === 'string' || rightType === 'string') {
|
|
10504
10480
|
return 'string';
|
|
10505
10481
|
}
|
|
10506
|
-
if (
|
|
10482
|
+
if (leftType === 'number' || rightType === 'number') {
|
|
10507
10483
|
return 'number';
|
|
10508
10484
|
}
|
|
10509
10485
|
}
|
|
10510
10486
|
|
|
10511
|
-
if (
|
|
10512
|
-
[
|
|
10513
|
-
'AND',
|
|
10514
|
-
'OR',
|
|
10515
|
-
'NOT',
|
|
10516
|
-
'=',
|
|
10517
|
-
'==',
|
|
10518
|
-
'===',
|
|
10519
|
-
'!=',
|
|
10520
|
-
'!==',
|
|
10521
|
-
'!===',
|
|
10522
|
-
'>',
|
|
10523
|
-
'>=',
|
|
10524
|
-
'<',
|
|
10525
|
-
'<=',
|
|
10526
|
-
'IN',
|
|
10527
|
-
'NOT IN',
|
|
10528
|
-
'LIKE',
|
|
10529
|
-
'NOT LIKE',
|
|
10530
|
-
'REGEXP',
|
|
10531
|
-
'GLOB',
|
|
10532
|
-
].indexOf(this.op) > -1
|
|
10533
|
-
) {
|
|
10534
|
-
return 'boolean';
|
|
10535
|
-
}
|
|
10536
|
-
|
|
10537
|
-
if (
|
|
10538
|
-
this.op === 'BETWEEN' ||
|
|
10539
|
-
this.op === 'NOT BETWEEN' ||
|
|
10540
|
-
this.op === 'IS NULL' ||
|
|
10541
|
-
this.op === 'IS NOT NULL'
|
|
10542
|
-
) {
|
|
10543
|
-
return 'boolean';
|
|
10544
|
-
}
|
|
10545
|
-
|
|
10546
|
-
if (this.allsome) {
|
|
10487
|
+
if (toTypeBoolOps.has(this.op) || this.allsome)
|
|
10547
10488
|
return 'boolean';
|
|
10548
|
-
}
|
|
10549
10489
|
|
|
10550
|
-
if (!this.op)
|
|
10551
|
-
return this.left.toType();
|
|
10552
|
-
}
|
|
10490
|
+
if (!this.op)
|
|
10491
|
+
return this.left.toType(tableid);
|
|
10553
10492
|
|
|
10554
10493
|
return 'unknown';
|
|
10555
10494
|
}
|
|
@@ -10707,7 +10646,10 @@ yy.Over = class Over {
|
|
|
10707
10646
|
s += '.indexOf(';
|
|
10708
10647
|
s += 'alasql.utils.getValueOf(' + leftJS() + '))>-1)';
|
|
10709
10648
|
} else if (Array.isArray(this.right)) {
|
|
10710
|
-
if (
|
|
10649
|
+
if (
|
|
10650
|
+
!alasql.options.cache ||
|
|
10651
|
+
this.right.filter(value => value instanceof yy.ParamValue).length > 0
|
|
10652
|
+
) {
|
|
10711
10653
|
// When not using cache, or when the array contains parameters, we need to re-create the Set
|
|
10712
10654
|
// leverage JS Set, which is faster for lookups than arrays
|
|
10713
10655
|
s =
|
|
@@ -10717,17 +10659,18 @@ yy.Over = class Over {
|
|
|
10717
10659
|
leftJS() +
|
|
10718
10660
|
')))';
|
|
10719
10661
|
} else {
|
|
10720
|
-
// Use a cache to not re-create the Set on every identitical query
|
|
10662
|
+
// Use a cache to not re-create the Set on every identitical query
|
|
10721
10663
|
if (!alasql.sets) {
|
|
10722
10664
|
alasql.sets = {};
|
|
10723
10665
|
}
|
|
10724
|
-
const allValues = this.right.map(
|
|
10725
|
-
const allValuesStr = allValues.join(
|
|
10666
|
+
const allValues = this.right.map(value => value.value);
|
|
10667
|
+
const allValuesStr = allValues.join(',');
|
|
10726
10668
|
if (!alasql.sets[allValuesStr]) {
|
|
10727
10669
|
// leverage JS Set, which is faster for lookups than arrays
|
|
10728
10670
|
alasql.sets[allValuesStr] = new Set(allValues);
|
|
10729
10671
|
}
|
|
10730
|
-
s =
|
|
10672
|
+
s =
|
|
10673
|
+
'alasql.sets["' + allValuesStr + '"].has(alasql.utils.getValueOf(' + leftJS() + '))';
|
|
10731
10674
|
}
|
|
10732
10675
|
} else {
|
|
10733
10676
|
s = '(' + rightJS() + '.indexOf(' + leftJS() + ')>-1)';
|
|
@@ -10744,7 +10687,10 @@ yy.Over = class Over {
|
|
|
10744
10687
|
s += '.indexOf(';
|
|
10745
10688
|
s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
|
|
10746
10689
|
} else if (Array.isArray(this.right)) {
|
|
10747
|
-
if (
|
|
10690
|
+
if (
|
|
10691
|
+
!alasql.options.cache ||
|
|
10692
|
+
this.right.filter(value => value instanceof yy.ParamValue).length > 0
|
|
10693
|
+
) {
|
|
10748
10694
|
// When not using cache, or when the array contains parameters, we need to re-create the Set
|
|
10749
10695
|
// leverage JS Set, which is faster for lookups than arrays
|
|
10750
10696
|
s =
|
|
@@ -10754,17 +10700,18 @@ yy.Over = class Over {
|
|
|
10754
10700
|
leftJS() +
|
|
10755
10701
|
'))))';
|
|
10756
10702
|
} else {
|
|
10757
|
-
// Use a cache to not re-create the Set on every identitical query
|
|
10703
|
+
// Use a cache to not re-create the Set on every identitical query
|
|
10758
10704
|
if (!alasql.sets) {
|
|
10759
10705
|
alasql.sets = {};
|
|
10760
10706
|
}
|
|
10761
|
-
const allValues = this.right.map(
|
|
10762
|
-
const allValuesStr = allValues.join(
|
|
10707
|
+
const allValues = this.right.map(value => value.value);
|
|
10708
|
+
const allValuesStr = allValues.join(',');
|
|
10763
10709
|
if (!alasql.sets[allValuesStr]) {
|
|
10764
10710
|
// leverage JS Set, which is faster for lookups than arrays
|
|
10765
10711
|
alasql.sets[allValuesStr] = new Set(allValues);
|
|
10766
10712
|
}
|
|
10767
|
-
s =
|
|
10713
|
+
s =
|
|
10714
|
+
'!alasql.sets["' + allValuesStr + '"].has(alasql.utils.getValueOf(' + leftJS() + '))';
|
|
10768
10715
|
}
|
|
10769
10716
|
} else {
|
|
10770
10717
|
s = '(' + rightJS() + '.indexOf(';
|
|
@@ -10831,13 +10778,6 @@ yy.Over = class Over {
|
|
|
10831
10778
|
op = '&&';
|
|
10832
10779
|
}
|
|
10833
10780
|
|
|
10834
|
-
// if(this.op === '^') {
|
|
10835
|
-
// // return 'Math.pow('
|
|
10836
|
-
// // + leftJS()
|
|
10837
|
-
// // + ','
|
|
10838
|
-
// // + rightJS()
|
|
10839
|
-
// // + ')';
|
|
10840
|
-
// }
|
|
10841
10781
|
var expr = s || '(' + leftJS() + op + rightJS() + ')';
|
|
10842
10782
|
|
|
10843
10783
|
var declareRefs = 'y=[(' + refs.join('), (') + ')]';
|
|
@@ -11001,38 +10941,33 @@ yy.Over = class Over {
|
|
|
11001
10941
|
}
|
|
11002
10942
|
}
|
|
11003
10943
|
|
|
10944
|
+
const toJsOpMapping = {
|
|
10945
|
+
'~': '~',
|
|
10946
|
+
'-': '-',
|
|
10947
|
+
'+': '+',
|
|
10948
|
+
'NOT': '!',
|
|
10949
|
+
};
|
|
10950
|
+
|
|
11004
10951
|
class UniOp {
|
|
11005
10952
|
constructor(params) {
|
|
11006
10953
|
assign(this, params);
|
|
11007
10954
|
}
|
|
11008
10955
|
|
|
11009
10956
|
toString() {
|
|
11010
|
-
var s;
|
|
11011
10957
|
const { op, right } = this;
|
|
11012
10958
|
const res = right.toString();
|
|
11013
10959
|
|
|
11014
|
-
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
|
|
11021
|
-
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
s = op + res;
|
|
11025
|
-
}
|
|
11026
|
-
if (op === 'NOT') {
|
|
11027
|
-
s = op + '(' + res + ')';
|
|
11028
|
-
}
|
|
11029
|
-
if (op === null) {
|
|
11030
|
-
s = '(' + res + ')';
|
|
10960
|
+
switch (op) {
|
|
10961
|
+
case '~':
|
|
10962
|
+
case '-':
|
|
10963
|
+
case '+':
|
|
10964
|
+
case '#':
|
|
10965
|
+
return op + res;
|
|
10966
|
+
case 'NOT':
|
|
10967
|
+
return op + '(' + res + ')';
|
|
10968
|
+
default:
|
|
10969
|
+
return '(' + res + ')';
|
|
11031
10970
|
}
|
|
11032
|
-
if (!s) {
|
|
11033
|
-
s = '(' + res + ')';
|
|
11034
|
-
}
|
|
11035
|
-
return s;
|
|
11036
10971
|
}
|
|
11037
10972
|
|
|
11038
10973
|
findAggregator(query) {
|
|
@@ -11042,58 +10977,35 @@ yy.Over = class Over {
|
|
|
11042
10977
|
}
|
|
11043
10978
|
|
|
11044
10979
|
toType() {
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
-
|
|
11052
|
-
|
|
11053
|
-
if (this.op === 'NOT') {
|
|
11054
|
-
return 'boolean';
|
|
10980
|
+
switch (this.op) {
|
|
10981
|
+
case '-':
|
|
10982
|
+
case '+':
|
|
10983
|
+
return 'number';
|
|
10984
|
+
case 'NOT':
|
|
10985
|
+
return 'boolean';
|
|
10986
|
+
default:
|
|
10987
|
+
return 'string';
|
|
11055
10988
|
}
|
|
11056
|
-
|
|
11057
|
-
// Todo: implement default case
|
|
11058
10989
|
}
|
|
11059
10990
|
|
|
11060
10991
|
toJS(context, tableid, defcols) {
|
|
11061
|
-
if (this.op === '
|
|
11062
|
-
return
|
|
11063
|
-
}
|
|
11064
|
-
|
|
11065
|
-
if (this.op === '-') {
|
|
11066
|
-
return '(-(' + this.right.toJS(context, tableid, defcols) + '))';
|
|
10992
|
+
if (this.right instanceof Column && this.op === '#') {
|
|
10993
|
+
return `(alasql.databases[alasql.useid].objects['${this.right.columnid}'])`;
|
|
11067
10994
|
}
|
|
11068
10995
|
|
|
11069
|
-
|
|
11070
|
-
return '(' + this.right.toJS(context, tableid, defcols) + ')';
|
|
11071
|
-
}
|
|
10996
|
+
const rightJS = this.right.toJS(context, tableid, defcols);
|
|
11072
10997
|
|
|
11073
|
-
if (this.op
|
|
11074
|
-
return
|
|
10998
|
+
if (toJsOpMapping.hasOwnProperty(this.op)) {
|
|
10999
|
+
return `(${toJsOpMapping[this.op]}(${rightJS}))`;
|
|
11075
11000
|
}
|
|
11076
11001
|
|
|
11077
|
-
if (this.op === '#') {
|
|
11078
|
-
if (this.right instanceof Column) {
|
|
11079
|
-
return "(alasql.databases[alasql.useid].objects['" + this.right.columnid + "'])";
|
|
11080
|
-
} else {
|
|
11081
|
-
return (
|
|
11082
|
-
'(alasql.databases[alasql.useid].objects[' +
|
|
11083
|
-
this.right.toJS(context, tableid, defcols) +
|
|
11084
|
-
'])'
|
|
11085
|
-
);
|
|
11086
|
-
}
|
|
11087
|
-
}
|
|
11088
|
-
|
|
11089
|
-
// Please avoid === here
|
|
11090
11002
|
if (this.op == null) {
|
|
11091
|
-
|
|
11092
|
-
return '(' + this.right.toJS(context, tableid, defcols) + ')';
|
|
11003
|
+
return `(${rightJS})`;
|
|
11093
11004
|
}
|
|
11094
11005
|
|
|
11095
|
-
|
|
11006
|
+
throw new Error(`Unsupported operator: ${this.op}`);
|
|
11096
11007
|
}
|
|
11008
|
+
|
|
11097
11009
|
}
|
|
11098
11010
|
|
|
11099
11011
|
class Column {
|
|
@@ -11102,82 +11014,54 @@ yy.Over = class Over {
|
|
|
11102
11014
|
}
|
|
11103
11015
|
|
|
11104
11016
|
toString() {
|
|
11105
|
-
|
|
11017
|
+
let s = this.columnid;
|
|
11018
|
+
|
|
11106
11019
|
if (this.columnid == +this.columnid) {
|
|
11107
11020
|
s = '[' + this.columnid + ']';
|
|
11108
|
-
} else {
|
|
11109
|
-
s = this.columnid;
|
|
11110
11021
|
}
|
|
11022
|
+
|
|
11111
11023
|
if (this.tableid) {
|
|
11112
|
-
|
|
11113
|
-
|
|
11114
|
-
} else {
|
|
11115
|
-
s = this.tableid + '.' + s;
|
|
11116
|
-
}
|
|
11024
|
+
s = this.tableid + (this.columnid === +this.columnid ? '' : '.') + s;
|
|
11025
|
+
|
|
11117
11026
|
if (this.databaseid) {
|
|
11118
11027
|
s = this.databaseid + '.' + s;
|
|
11119
11028
|
}
|
|
11120
11029
|
}
|
|
11030
|
+
|
|
11121
11031
|
return s;
|
|
11122
11032
|
}
|
|
11123
11033
|
|
|
11124
11034
|
toJS(context, tableid, defcols) {
|
|
11125
|
-
var s = '';
|
|
11126
11035
|
if (!this.tableid && tableid === '' && !defcols) {
|
|
11127
|
-
|
|
11128
|
-
|
|
11129
|
-
} else {
|
|
11130
|
-
if (context === 'g') {
|
|
11131
|
-
s = "g['_']";
|
|
11132
|
-
} else {
|
|
11133
|
-
s = context;
|
|
11134
|
-
}
|
|
11135
|
-
}
|
|
11136
|
-
} else {
|
|
11137
|
-
if (context === 'g') {
|
|
11138
|
-
s = "g['" + this.nick + "']";
|
|
11139
|
-
} else if (this.tableid) {
|
|
11140
|
-
if (this.columnid !== '_') {
|
|
11141
|
-
s = context + "['" + this.tableid + "']['" + this.columnid + "']";
|
|
11142
|
-
} else {
|
|
11143
|
-
if (context === 'g') {
|
|
11144
|
-
s = "g['_']";
|
|
11145
|
-
} else {
|
|
11146
|
-
s = context + "['" + this.tableid + "']";
|
|
11147
|
-
}
|
|
11148
|
-
}
|
|
11149
|
-
} else if (defcols) {
|
|
11150
|
-
var tbid = defcols[this.columnid];
|
|
11151
|
-
if (tbid === '-') {
|
|
11152
|
-
throw new Error(
|
|
11153
|
-
'Cannot resolve column "' + this.columnid + '" because it exists in two source tables'
|
|
11154
|
-
);
|
|
11155
|
-
} else if (tbid) {
|
|
11156
|
-
if (this.columnid !== '_') {
|
|
11157
|
-
s = context + "['" + tbid + "']['" + this.columnid + "']";
|
|
11158
|
-
} else {
|
|
11159
|
-
s = context + "['" + tbid + "']";
|
|
11160
|
-
}
|
|
11036
|
+
return this.columnid !== '_' ? `${context}['${this.columnid}']` : (context === 'g' ? "g['_']" : context);
|
|
11037
|
+
}
|
|
11161
11038
|
|
|
11162
|
-
|
|
11163
|
-
|
|
11164
|
-
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
|
|
11168
|
-
|
|
11169
|
-
|
|
11170
|
-
|
|
11039
|
+
if (context === 'g') {
|
|
11040
|
+
return `g['${this.nick}']`;
|
|
11041
|
+
}
|
|
11042
|
+
|
|
11043
|
+
if (this.tableid) {
|
|
11044
|
+
return this.columnid !== '_' ? `${context}['${this.tableid}']['${this.columnid}']` : (context === 'g' ? "g['_']" : `${context}['${this.tableid}']`);
|
|
11045
|
+
}
|
|
11046
|
+
|
|
11047
|
+
if (defcols) {
|
|
11048
|
+
const tbid = defcols[this.columnid];
|
|
11049
|
+
if (tbid === '-') {
|
|
11050
|
+
throw new Error(`Cannot resolve column "${this.columnid}" because it exists in two source tables`);
|
|
11051
|
+
} else if (tbid) {
|
|
11052
|
+
return this.columnid !== '_' ? `${context}['${tbid}']['${this.columnid}']` : `${context}['${tbid}']`;
|
|
11171
11053
|
} else {
|
|
11172
|
-
|
|
11173
|
-
s = context + "['" + (this.tableid || tableid) + "']['" + this.columnid + "']";
|
|
11174
|
-
} else {
|
|
11175
|
-
s = context + "['" + (this.tableid || tableid) + "']";
|
|
11176
|
-
}
|
|
11054
|
+
return this.columnid !== '_' ? `${context}['${this.tableid || tableid}']['${this.columnid}']` : `${context}['${this.tableid || tableid}']`;
|
|
11177
11055
|
}
|
|
11178
11056
|
}
|
|
11179
|
-
|
|
11057
|
+
|
|
11058
|
+
if (tableid === -1) {
|
|
11059
|
+
return `${context}['${this.columnid}']`;
|
|
11060
|
+
}
|
|
11061
|
+
|
|
11062
|
+
return this.columnid !== '_' ? `${context}['${this.tableid || tableid}']['${this.columnid}']` : `${context}['${this.tableid || tableid}']`;
|
|
11180
11063
|
}
|
|
11064
|
+
|
|
11181
11065
|
}
|
|
11182
11066
|
|
|
11183
11067
|
class AggrValue {
|
|
@@ -11186,68 +11070,37 @@ yy.Over = class Over {
|
|
|
11186
11070
|
}
|
|
11187
11071
|
|
|
11188
11072
|
toString() {
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
}
|
|
11193
|
-
s += this.aggregatorid + '(';
|
|
11194
|
-
}
|
|
11195
|
-
|
|
11196
|
-
if (this.distinct) {
|
|
11197
|
-
s += 'DISTINCT ';
|
|
11198
|
-
}
|
|
11199
|
-
|
|
11200
|
-
if (this.expression) {
|
|
11201
|
-
s += this.expression.toString();
|
|
11202
|
-
}
|
|
11203
|
-
|
|
11204
|
-
s += ')';
|
|
11073
|
+
const funcName = this.aggregatorid === 'REDUCE' ? this.funcid.replace(re_invalidFnNameChars, '') : this.aggregatorid;
|
|
11074
|
+
const distinctPart = this.distinct ? 'DISTINCT ' : '';
|
|
11075
|
+
const expressionPart = this.expression ? this.expression.toString() : '';
|
|
11076
|
+
const overPart = this.over ? ` ${this.over.toString()}` : '';
|
|
11205
11077
|
|
|
11206
|
-
|
|
11207
|
-
s += ' ' + this.over.toString();
|
|
11208
|
-
}
|
|
11209
|
-
return s;
|
|
11078
|
+
return `${funcName}(${distinctPart}${expressionPart})${overPart}`;
|
|
11210
11079
|
}
|
|
11211
11080
|
|
|
11212
11081
|
findAggregator(query) {
|
|
11213
|
-
|
|
11214
|
-
|
|
11215
|
-
if (!
|
|
11216
|
-
|
|
11217
|
-
|
|
11218
|
-
|
|
11219
|
-
|
|
11220
|
-
if (query.removeKeys[i] === colas) {
|
|
11221
|
-
found = true;
|
|
11222
|
-
break;
|
|
11223
|
-
}
|
|
11224
|
-
}
|
|
11225
|
-
if (!found) {
|
|
11226
|
-
query.removeKeys.push(colas);
|
|
11227
|
-
}
|
|
11082
|
+
const colas = escapeq(this.toString()) + ':' + query.selectGroup.length;
|
|
11083
|
+
|
|
11084
|
+
if (!this.nick) {
|
|
11085
|
+
this.nick = colas;
|
|
11086
|
+
|
|
11087
|
+
if (!query.removeKeys.includes(colas)) {
|
|
11088
|
+
query.removeKeys.push(colas);
|
|
11228
11089
|
}
|
|
11229
|
-
query.selectGroup.push(this);
|
|
11230
11090
|
}
|
|
11231
|
-
|
|
11091
|
+
|
|
11092
|
+
query.selectGroup.push(this);
|
|
11232
11093
|
}
|
|
11233
11094
|
|
|
11234
11095
|
toType() {
|
|
11235
|
-
if (
|
|
11236
|
-
['SUM', 'COUNT', 'AVG', 'MIN', 'MAX', 'AGGR', 'VAR', 'STDDEV', 'TOTAL'].indexOf(
|
|
11237
|
-
this.aggregatorid
|
|
11238
|
-
) > -1
|
|
11239
|
-
) {
|
|
11096
|
+
if (['SUM', 'COUNT', 'AVG', 'MIN', 'MAX', 'AGGR', 'VAR', 'STDDEV', 'TOTAL'].includes(this.aggregatorid)) {
|
|
11240
11097
|
return 'number';
|
|
11241
11098
|
}
|
|
11242
11099
|
|
|
11243
|
-
if (
|
|
11100
|
+
if (this.aggregatorid === 'ARRAY') {
|
|
11244
11101
|
return 'array';
|
|
11245
11102
|
}
|
|
11246
11103
|
|
|
11247
|
-
if (['FIRST', 'LAST'].indexOf(this.aggregatorid) > -1) {
|
|
11248
|
-
return this.expression.toType();
|
|
11249
|
-
}
|
|
11250
|
-
|
|
11251
11104
|
return this.expression.toType();
|
|
11252
11105
|
}
|
|
11253
11106
|
|
|
@@ -12277,51 +12130,60 @@ alasql.stdfn.CONVERT = function (value, args) {
|
|
|
12277
12130
|
}
|
|
12278
12131
|
}
|
|
12279
12132
|
|
|
12280
|
-
|
|
12281
|
-
|
|
12282
|
-
|
|
12283
|
-
|
|
12284
|
-
|
|
12285
|
-
|
|
12286
|
-
|
|
12287
|
-
|
|
12288
|
-
|
|
12289
|
-
|
|
12290
|
-
|
|
12291
|
-
|
|
12292
|
-
|
|
12293
|
-
|
|
12294
|
-
|
|
12295
|
-
|
|
12296
|
-
|
|
12297
|
-
|
|
12298
|
-
|
|
12299
|
-
|
|
12300
|
-
|
|
12301
|
-
|
|
12302
|
-
|
|
12303
|
-
|
|
12304
|
-
|
|
12305
|
-
|
|
12306
|
-
|
|
12307
|
-
|
|
12308
|
-
|
|
12309
|
-
|
|
12310
|
-
|
|
12311
|
-
|
|
12312
|
-
|
|
12313
|
-
|
|
12314
|
-
|
|
12315
|
-
|
|
12316
|
-
|
|
12317
|
-
|
|
12318
|
-
|
|
12319
|
-
return
|
|
12320
|
-
|
|
12321
|
-
|
|
12322
|
-
|
|
12133
|
+
switch (udbtypeid) {
|
|
12134
|
+
case 'DATE':
|
|
12135
|
+
return `${s.formattedYear}.${s.formattedMonth}.${s.formattedDate}`;
|
|
12136
|
+
case 'DATETIME':
|
|
12137
|
+
case 'DATETIME2':
|
|
12138
|
+
return `${s.fullYear}.${s.formattedMonth}.${s.formattedDate} ${s.formattedHour}:${s.formattedMinutes}:${s.formattedSeconds}.${s.formattedMilliseconds}`;
|
|
12139
|
+
case 'MONEY':
|
|
12140
|
+
var m = +val;
|
|
12141
|
+
return (m | 0) + ((m * 100) % 100) / 100;
|
|
12142
|
+
case 'BOOLEAN':
|
|
12143
|
+
return !!val;
|
|
12144
|
+
case 'INT':
|
|
12145
|
+
case 'INTEGER':
|
|
12146
|
+
case 'SMALLINT':
|
|
12147
|
+
case 'BIGINT':
|
|
12148
|
+
case 'SERIAL':
|
|
12149
|
+
case 'SMALLSERIAL':
|
|
12150
|
+
case 'BIGSERIAL':
|
|
12151
|
+
return val | 0;
|
|
12152
|
+
case 'STRING':
|
|
12153
|
+
case 'VARCHAR':
|
|
12154
|
+
case 'NVARCHAR':
|
|
12155
|
+
case 'CHARACTER VARIABLE':
|
|
12156
|
+
return args.dbsize ? String(val).substr(0, args.dbsize) : String(val);
|
|
12157
|
+
case 'CHAR':
|
|
12158
|
+
case 'CHARACTER':
|
|
12159
|
+
case 'NCHAR':
|
|
12160
|
+
return (val + ' '.repeat(args.dbsize)).substr(0, args.dbsize);
|
|
12161
|
+
case 'NUMBER':
|
|
12162
|
+
case 'FLOAT':
|
|
12163
|
+
case 'DECIMAL':
|
|
12164
|
+
case 'NUMERIC':
|
|
12165
|
+
var m = +val;
|
|
12166
|
+
if (args.dbsize !== undefined) {
|
|
12167
|
+
m = parseFloat(m.toPrecision(args.dbsize));
|
|
12168
|
+
}
|
|
12169
|
+
if (args.dbprecision !== undefined) {
|
|
12170
|
+
m = parseFloat(m.toFixed(args.dbprecision));
|
|
12171
|
+
}
|
|
12172
|
+
return m;
|
|
12173
|
+
case 'JSON':
|
|
12174
|
+
if (typeof val === 'object') {
|
|
12175
|
+
return val;
|
|
12176
|
+
}
|
|
12177
|
+
try {
|
|
12178
|
+
return JSON.parse(val);
|
|
12179
|
+
} catch (err) {
|
|
12180
|
+
throw new Error('Cannot convert string to JSON');
|
|
12181
|
+
}
|
|
12182
|
+
case 'Date':
|
|
12183
|
+
return val;
|
|
12184
|
+
default:
|
|
12185
|
+
return val;
|
|
12323
12186
|
}
|
|
12324
|
-
return val;
|
|
12325
12187
|
};
|
|
12326
12188
|
/*
|
|
12327
12189
|
//
|