@milaboratories/ptabler-expression-js 1.1.12 → 1.1.14
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/dist/expressions.cjs +77 -77
- package/dist/expressions.cjs.map +1 -1
- package/dist/expressions.d.ts +5 -5
- package/dist/expressions.d.ts.map +1 -1
- package/dist/expressions.js +77 -77
- package/dist/expressions.js.map +1 -1
- package/dist/functions.cjs +23 -23
- package/dist/functions.cjs.map +1 -1
- package/dist/functions.d.ts +2 -2
- package/dist/functions.d.ts.map +1 -1
- package/dist/functions.js +23 -23
- package/dist/functions.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/types.d.ts +1 -1
- package/package.json +16 -15
- package/src/expressions.ts +202 -109
- package/src/functions.ts +48 -30
- package/src/index.ts +3 -3
- package/src/types.ts +1 -1
package/dist/expressions.cjs
CHANGED
|
@@ -18,83 +18,83 @@ class ExpressionImpl {
|
|
|
18
18
|
}
|
|
19
19
|
// Arithmetic operations
|
|
20
20
|
plus(other) {
|
|
21
|
-
return new ArithmeticExpressionImpl(
|
|
21
|
+
return new ArithmeticExpressionImpl("plus", this, coerceToExpression(other));
|
|
22
22
|
}
|
|
23
23
|
minus(other) {
|
|
24
|
-
return new ArithmeticExpressionImpl(
|
|
24
|
+
return new ArithmeticExpressionImpl("minus", this, coerceToExpression(other));
|
|
25
25
|
}
|
|
26
26
|
multiply(other) {
|
|
27
|
-
return new ArithmeticExpressionImpl(
|
|
27
|
+
return new ArithmeticExpressionImpl("multiply", this, coerceToExpression(other));
|
|
28
28
|
}
|
|
29
29
|
truediv(other) {
|
|
30
|
-
return new ArithmeticExpressionImpl(
|
|
30
|
+
return new ArithmeticExpressionImpl("truediv", this, coerceToExpression(other));
|
|
31
31
|
}
|
|
32
32
|
floordiv(other) {
|
|
33
|
-
return new ArithmeticExpressionImpl(
|
|
33
|
+
return new ArithmeticExpressionImpl("floordiv", this, coerceToExpression(other));
|
|
34
34
|
}
|
|
35
35
|
// Comparison operations
|
|
36
36
|
gt(other) {
|
|
37
|
-
return new ComparisonExpressionImpl(
|
|
37
|
+
return new ComparisonExpressionImpl("gt", this, coerceToExpression(other));
|
|
38
38
|
}
|
|
39
39
|
ge(other) {
|
|
40
|
-
return new ComparisonExpressionImpl(
|
|
40
|
+
return new ComparisonExpressionImpl("ge", this, coerceToExpression(other));
|
|
41
41
|
}
|
|
42
42
|
eq(other) {
|
|
43
|
-
return new ComparisonExpressionImpl(
|
|
43
|
+
return new ComparisonExpressionImpl("eq", this, coerceToExpression(other));
|
|
44
44
|
}
|
|
45
45
|
lt(other) {
|
|
46
|
-
return new ComparisonExpressionImpl(
|
|
46
|
+
return new ComparisonExpressionImpl("lt", this, coerceToExpression(other));
|
|
47
47
|
}
|
|
48
48
|
le(other) {
|
|
49
|
-
return new ComparisonExpressionImpl(
|
|
49
|
+
return new ComparisonExpressionImpl("le", this, coerceToExpression(other));
|
|
50
50
|
}
|
|
51
51
|
neq(other) {
|
|
52
|
-
return new ComparisonExpressionImpl(
|
|
52
|
+
return new ComparisonExpressionImpl("neq", this, coerceToExpression(other));
|
|
53
53
|
}
|
|
54
54
|
// Logical operations
|
|
55
55
|
and(...others) {
|
|
56
|
-
return new LogicalExpressionImpl(
|
|
56
|
+
return new LogicalExpressionImpl("and", [this, ...others]);
|
|
57
57
|
}
|
|
58
58
|
or(...others) {
|
|
59
|
-
return new LogicalExpressionImpl(
|
|
59
|
+
return new LogicalExpressionImpl("or", [this, ...others]);
|
|
60
60
|
}
|
|
61
61
|
not() {
|
|
62
|
-
return new LogicalExpressionImpl(
|
|
62
|
+
return new LogicalExpressionImpl("not", [this]);
|
|
63
63
|
}
|
|
64
64
|
// Unary arithmetic operations
|
|
65
65
|
abs() {
|
|
66
|
-
return new UnaryArithmeticExpressionImpl(
|
|
66
|
+
return new UnaryArithmeticExpressionImpl("abs", this);
|
|
67
67
|
}
|
|
68
68
|
sqrt() {
|
|
69
|
-
return new UnaryArithmeticExpressionImpl(
|
|
69
|
+
return new UnaryArithmeticExpressionImpl("sqrt", this);
|
|
70
70
|
}
|
|
71
71
|
log() {
|
|
72
|
-
return new UnaryArithmeticExpressionImpl(
|
|
72
|
+
return new UnaryArithmeticExpressionImpl("log", this);
|
|
73
73
|
}
|
|
74
74
|
log10() {
|
|
75
|
-
return new UnaryArithmeticExpressionImpl(
|
|
75
|
+
return new UnaryArithmeticExpressionImpl("log10", this);
|
|
76
76
|
}
|
|
77
77
|
log2() {
|
|
78
|
-
return new UnaryArithmeticExpressionImpl(
|
|
78
|
+
return new UnaryArithmeticExpressionImpl("log2", this);
|
|
79
79
|
}
|
|
80
80
|
floor() {
|
|
81
|
-
return new UnaryArithmeticExpressionImpl(
|
|
81
|
+
return new UnaryArithmeticExpressionImpl("floor", this);
|
|
82
82
|
}
|
|
83
83
|
ceil() {
|
|
84
|
-
return new UnaryArithmeticExpressionImpl(
|
|
84
|
+
return new UnaryArithmeticExpressionImpl("ceil", this);
|
|
85
85
|
}
|
|
86
86
|
round() {
|
|
87
|
-
return new UnaryArithmeticExpressionImpl(
|
|
87
|
+
return new UnaryArithmeticExpressionImpl("round", this);
|
|
88
88
|
}
|
|
89
89
|
negate() {
|
|
90
|
-
return new UnaryArithmeticExpressionImpl(
|
|
90
|
+
return new UnaryArithmeticExpressionImpl("negate", this);
|
|
91
91
|
}
|
|
92
92
|
// Null checks
|
|
93
93
|
isNull() {
|
|
94
|
-
return new NullCheckExpressionImpl(
|
|
94
|
+
return new NullCheckExpressionImpl("is_na", this);
|
|
95
95
|
}
|
|
96
96
|
isNotNull() {
|
|
97
|
-
return new NullCheckExpressionImpl(
|
|
97
|
+
return new NullCheckExpressionImpl("is_not_na", this);
|
|
98
98
|
}
|
|
99
99
|
// Fill null/NaN
|
|
100
100
|
fillNull(value) {
|
|
@@ -117,10 +117,10 @@ class ExpressionImpl {
|
|
|
117
117
|
return new StringContainsExpressionImpl(this, coerceToExpression(pattern), literal, strict);
|
|
118
118
|
}
|
|
119
119
|
strToUpper() {
|
|
120
|
-
return new StringCaseExpressionImpl(
|
|
120
|
+
return new StringCaseExpressionImpl("to_upper", this);
|
|
121
121
|
}
|
|
122
122
|
strToLower() {
|
|
123
|
-
return new StringCaseExpressionImpl(
|
|
123
|
+
return new StringCaseExpressionImpl("to_lower", this);
|
|
124
124
|
}
|
|
125
125
|
strStartsWith(pattern) {
|
|
126
126
|
return new StringStartsWithExpressionImpl(this, coerceToExpression(pattern));
|
|
@@ -130,25 +130,25 @@ class ExpressionImpl {
|
|
|
130
130
|
}
|
|
131
131
|
// Aggregation operations
|
|
132
132
|
sum() {
|
|
133
|
-
return new AggregationExpressionImpl(
|
|
133
|
+
return new AggregationExpressionImpl("sum", this);
|
|
134
134
|
}
|
|
135
135
|
mean() {
|
|
136
|
-
return new AggregationExpressionImpl(
|
|
136
|
+
return new AggregationExpressionImpl("mean", this);
|
|
137
137
|
}
|
|
138
138
|
count() {
|
|
139
|
-
return new AggregationExpressionImpl(
|
|
139
|
+
return new AggregationExpressionImpl("count", this);
|
|
140
140
|
}
|
|
141
141
|
min() {
|
|
142
|
-
return new AggregationExpressionImpl(
|
|
142
|
+
return new AggregationExpressionImpl("min", this);
|
|
143
143
|
}
|
|
144
144
|
max() {
|
|
145
|
-
return new AggregationExpressionImpl(
|
|
145
|
+
return new AggregationExpressionImpl("max", this);
|
|
146
146
|
}
|
|
147
147
|
first() {
|
|
148
|
-
return new AggregationExpressionImpl(
|
|
148
|
+
return new AggregationExpressionImpl("first", this);
|
|
149
149
|
}
|
|
150
150
|
last() {
|
|
151
|
-
return new AggregationExpressionImpl(
|
|
151
|
+
return new AggregationExpressionImpl("last", this);
|
|
152
152
|
}
|
|
153
153
|
cumsum() {
|
|
154
154
|
return new CumsumExpressionImpl(this);
|
|
@@ -169,7 +169,7 @@ class ColumnExpressionImpl extends ExpressionImpl {
|
|
|
169
169
|
}
|
|
170
170
|
toJSON() {
|
|
171
171
|
return {
|
|
172
|
-
type:
|
|
172
|
+
type: "col",
|
|
173
173
|
name: this.columnName,
|
|
174
174
|
};
|
|
175
175
|
}
|
|
@@ -212,7 +212,7 @@ class MinMaxExpressionImpl extends ExpressionImpl {
|
|
|
212
212
|
};
|
|
213
213
|
}
|
|
214
214
|
getAlias() {
|
|
215
|
-
return this._alias || `${this.op}_${this.ops.map((o) => o.getAlias()).join(
|
|
215
|
+
return this._alias || `${this.op}_${this.ops.map((o) => o.getAlias()).join("_")}`;
|
|
216
216
|
}
|
|
217
217
|
clone() {
|
|
218
218
|
const cloned = new MinMaxExpressionImpl(this.op, this.ops);
|
|
@@ -283,9 +283,9 @@ class LogicalExpressionImpl extends ExpressionImpl {
|
|
|
283
283
|
this.operands = operands;
|
|
284
284
|
}
|
|
285
285
|
toJSON() {
|
|
286
|
-
if (this.operator ===
|
|
286
|
+
if (this.operator === "not") {
|
|
287
287
|
return {
|
|
288
|
-
type:
|
|
288
|
+
type: "not",
|
|
289
289
|
value: this.operands[0].toJSON(),
|
|
290
290
|
};
|
|
291
291
|
}
|
|
@@ -297,7 +297,7 @@ class LogicalExpressionImpl extends ExpressionImpl {
|
|
|
297
297
|
getAlias() {
|
|
298
298
|
if (this._alias)
|
|
299
299
|
return this._alias;
|
|
300
|
-
if (this.operator ===
|
|
300
|
+
if (this.operator === "not") {
|
|
301
301
|
return `not_${this.operands[0].getAlias()}`;
|
|
302
302
|
}
|
|
303
303
|
return this.operands.map((op) => op.getAlias()).join(`_${this.operator}_`);
|
|
@@ -362,7 +362,7 @@ class LiteralExpressionImpl extends ExpressionImpl {
|
|
|
362
362
|
}
|
|
363
363
|
toJSON() {
|
|
364
364
|
return {
|
|
365
|
-
type:
|
|
365
|
+
type: "const",
|
|
366
366
|
value: this.value,
|
|
367
367
|
};
|
|
368
368
|
}
|
|
@@ -385,26 +385,26 @@ class LiteralExpressionImpl extends ExpressionImpl {
|
|
|
385
385
|
*/
|
|
386
386
|
generateDefaultAlias() {
|
|
387
387
|
if (this.value === null || this.value === undefined) {
|
|
388
|
-
return
|
|
388
|
+
return "null";
|
|
389
389
|
}
|
|
390
|
-
if (typeof this.value ===
|
|
390
|
+
if (typeof this.value === "string") {
|
|
391
391
|
// For string values, truncate if too long and make safe for column names
|
|
392
|
-
const safe = this.value.replace(/[^a-zA-Z0-9_]/g,
|
|
393
|
-
return safe.length > 20 ? safe.substring(0, 17) +
|
|
392
|
+
const safe = this.value.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
393
|
+
return safe.length > 20 ? safe.substring(0, 17) + "..." : safe;
|
|
394
394
|
}
|
|
395
|
-
if (typeof this.value ===
|
|
396
|
-
return this.value ?
|
|
395
|
+
if (typeof this.value === "boolean") {
|
|
396
|
+
return this.value ? "true" : "false";
|
|
397
397
|
}
|
|
398
|
-
if (typeof this.value ===
|
|
398
|
+
if (typeof this.value === "number") {
|
|
399
399
|
return String(this.value);
|
|
400
400
|
}
|
|
401
401
|
if (Array.isArray(this.value)) {
|
|
402
|
-
return
|
|
402
|
+
return "array";
|
|
403
403
|
}
|
|
404
|
-
if (typeof this.value ===
|
|
405
|
-
return
|
|
404
|
+
if (typeof this.value === "object") {
|
|
405
|
+
return "object";
|
|
406
406
|
}
|
|
407
|
-
return
|
|
407
|
+
return "literal";
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
class FillNullExpressionImpl extends ExpressionImpl {
|
|
@@ -417,7 +417,7 @@ class FillNullExpressionImpl extends ExpressionImpl {
|
|
|
417
417
|
}
|
|
418
418
|
toJSON() {
|
|
419
419
|
return {
|
|
420
|
-
type:
|
|
420
|
+
type: "fill_null",
|
|
421
421
|
input: this.expr.toJSON(),
|
|
422
422
|
fillValue: this.fillValue.toJSON(),
|
|
423
423
|
};
|
|
@@ -441,7 +441,7 @@ class FillNaNExpressionImpl extends ExpressionImpl {
|
|
|
441
441
|
}
|
|
442
442
|
toJSON() {
|
|
443
443
|
return {
|
|
444
|
-
type:
|
|
444
|
+
type: "fill_nan",
|
|
445
445
|
input: this.expr.toJSON(),
|
|
446
446
|
fillValue: this.fillValue.toJSON(),
|
|
447
447
|
};
|
|
@@ -458,20 +458,20 @@ class FillNaNExpressionImpl extends ExpressionImpl {
|
|
|
458
458
|
class StringConcatExpressionImpl extends ExpressionImpl {
|
|
459
459
|
operands;
|
|
460
460
|
delimiter;
|
|
461
|
-
constructor(operands, delimiter =
|
|
461
|
+
constructor(operands, delimiter = "") {
|
|
462
462
|
super();
|
|
463
463
|
this.operands = operands;
|
|
464
464
|
this.delimiter = delimiter;
|
|
465
465
|
}
|
|
466
466
|
toJSON() {
|
|
467
467
|
return {
|
|
468
|
-
type:
|
|
468
|
+
type: "str_join",
|
|
469
469
|
operands: this.operands.map((o) => o.toJSON()),
|
|
470
470
|
delimiter: this.delimiter,
|
|
471
471
|
};
|
|
472
472
|
}
|
|
473
473
|
getAlias() {
|
|
474
|
-
return this._alias || this.operands.map((o) => o.getAlias()).join(
|
|
474
|
+
return this._alias || this.operands.map((o) => o.getAlias()).join("_");
|
|
475
475
|
}
|
|
476
476
|
clone() {
|
|
477
477
|
const cloned = new StringConcatExpressionImpl(this.operands);
|
|
@@ -491,10 +491,10 @@ class SubstringExpressionImpl extends ExpressionImpl {
|
|
|
491
491
|
}
|
|
492
492
|
toJSON() {
|
|
493
493
|
return {
|
|
494
|
-
type:
|
|
494
|
+
type: "substring",
|
|
495
495
|
value: this.expr.toJSON(),
|
|
496
|
-
start: { type:
|
|
497
|
-
length: this.length !== undefined ? { type:
|
|
496
|
+
start: { type: "const", value: this.start },
|
|
497
|
+
length: this.length !== undefined ? { type: "const", value: this.length } : undefined,
|
|
498
498
|
};
|
|
499
499
|
}
|
|
500
500
|
getAlias() {
|
|
@@ -520,7 +520,7 @@ class StringReplaceExpressionImpl extends ExpressionImpl {
|
|
|
520
520
|
}
|
|
521
521
|
toJSON() {
|
|
522
522
|
return {
|
|
523
|
-
type:
|
|
523
|
+
type: "str_replace",
|
|
524
524
|
value: this.expr.toJSON(),
|
|
525
525
|
pattern: this.pattern,
|
|
526
526
|
replacement: this.value,
|
|
@@ -551,7 +551,7 @@ class StringContainsExpressionImpl extends ExpressionImpl {
|
|
|
551
551
|
}
|
|
552
552
|
toJSON() {
|
|
553
553
|
return {
|
|
554
|
-
type:
|
|
554
|
+
type: "str_contains",
|
|
555
555
|
value: this.expr.toJSON(),
|
|
556
556
|
pattern: this.pattern.toJSON(),
|
|
557
557
|
literal: this.literal || false,
|
|
@@ -600,7 +600,7 @@ class StringStartsWithExpressionImpl extends ExpressionImpl {
|
|
|
600
600
|
}
|
|
601
601
|
toJSON() {
|
|
602
602
|
return {
|
|
603
|
-
type:
|
|
603
|
+
type: "str_starts_with",
|
|
604
604
|
value: this.expr.toJSON(),
|
|
605
605
|
prefix: this.pattern.toJSON(),
|
|
606
606
|
};
|
|
@@ -624,7 +624,7 @@ class StringEndsWithExpressionImpl extends ExpressionImpl {
|
|
|
624
624
|
}
|
|
625
625
|
toJSON() {
|
|
626
626
|
return {
|
|
627
|
-
type:
|
|
627
|
+
type: "str_ends_with",
|
|
628
628
|
value: this.expr.toJSON(),
|
|
629
629
|
suffix: this.pattern.toJSON(),
|
|
630
630
|
};
|
|
@@ -652,7 +652,7 @@ class CumsumExpressionImpl extends ExpressionImpl {
|
|
|
652
652
|
}
|
|
653
653
|
toJSON() {
|
|
654
654
|
return {
|
|
655
|
-
type:
|
|
655
|
+
type: "cumsum",
|
|
656
656
|
value: this.value.toJSON(),
|
|
657
657
|
additionalOrderBy: this.additionalOrderBy.map((expr) => expr.toJSON()),
|
|
658
658
|
partitionBy: this.partitionBy.map((expr) => expr.toJSON()),
|
|
@@ -678,14 +678,14 @@ class AggregationExpressionImpl extends ExpressionImpl {
|
|
|
678
678
|
}
|
|
679
679
|
toJSON() {
|
|
680
680
|
return {
|
|
681
|
-
type:
|
|
681
|
+
type: "aggregate",
|
|
682
682
|
aggregation: this.operation,
|
|
683
|
-
value: this.expr?.toJSON() || { type:
|
|
683
|
+
value: this.expr?.toJSON() || { type: "const", value: 1 },
|
|
684
684
|
partitionBy: [],
|
|
685
685
|
};
|
|
686
686
|
}
|
|
687
687
|
getAlias() {
|
|
688
|
-
return this._alias || `${this.operation}${this.expr ?
|
|
688
|
+
return this._alias || `${this.operation}${this.expr ? "_" + this.expr.getAlias() : ""}`;
|
|
689
689
|
}
|
|
690
690
|
clone() {
|
|
691
691
|
const cloned = new AggregationExpressionImpl(this.operation, this.expr);
|
|
@@ -705,7 +705,7 @@ class WindowExpressionImpl extends ExpressionImpl {
|
|
|
705
705
|
}
|
|
706
706
|
toJSON() {
|
|
707
707
|
return {
|
|
708
|
-
type:
|
|
708
|
+
type: "aggregate",
|
|
709
709
|
aggregation: this.aggregation,
|
|
710
710
|
value: this.expr.toJSON(),
|
|
711
711
|
partitionBy: this.partitionBy.map((expr) => expr.toJSON()),
|
|
@@ -734,7 +734,7 @@ class StringDistanceExpressionImpl extends ExpressionImpl {
|
|
|
734
734
|
}
|
|
735
735
|
toJSON() {
|
|
736
736
|
return {
|
|
737
|
-
type:
|
|
737
|
+
type: "string_distance",
|
|
738
738
|
metric: this.metric,
|
|
739
739
|
string1: this.string1.toJSON(),
|
|
740
740
|
string2: this.string2.toJSON(),
|
|
@@ -764,7 +764,7 @@ class FuzzyStringFilterExpressionImpl extends ExpressionImpl {
|
|
|
764
764
|
}
|
|
765
765
|
toJSON() {
|
|
766
766
|
return {
|
|
767
|
-
type:
|
|
767
|
+
type: "fuzzy_string_filter",
|
|
768
768
|
metric: this.metric,
|
|
769
769
|
value: this.expr.toJSON(),
|
|
770
770
|
pattern: this.pattern.toJSON(),
|
|
@@ -792,17 +792,17 @@ class RankExpressionImpl extends ExpressionImpl {
|
|
|
792
792
|
}
|
|
793
793
|
toJSON() {
|
|
794
794
|
return {
|
|
795
|
-
type:
|
|
795
|
+
type: "rank",
|
|
796
796
|
orderBy: this.orderBy.map((e) => e.toJSON()),
|
|
797
797
|
partitionBy: this.partitionBy.map((e) => e.toJSON()),
|
|
798
798
|
descending: this.descending || undefined,
|
|
799
799
|
};
|
|
800
800
|
}
|
|
801
801
|
getAlias() {
|
|
802
|
-
const order = this.orderBy.map((e) => e.getAlias()).join(
|
|
803
|
-
const part = this.partitionBy.map((e) => e.getAlias()).join(
|
|
804
|
-
const dir = this.descending ?
|
|
805
|
-
return this._alias || `rank_${order}${part ? `_over_${part}` :
|
|
802
|
+
const order = this.orderBy.map((e) => e.getAlias()).join("_");
|
|
803
|
+
const part = this.partitionBy.map((e) => e.getAlias()).join("_");
|
|
804
|
+
const dir = this.descending ? "desc" : "asc";
|
|
805
|
+
return this._alias || `rank_${order}${part ? `_over_${part}` : ""}_${dir}`;
|
|
806
806
|
}
|
|
807
807
|
clone() {
|
|
808
808
|
const cloned = new RankExpressionImpl(this.orderBy, this.partitionBy, this.descending);
|
|
@@ -820,7 +820,7 @@ class WhenThenOtherwiseExpressionImpl extends ExpressionImpl {
|
|
|
820
820
|
}
|
|
821
821
|
toJSON() {
|
|
822
822
|
return {
|
|
823
|
-
type:
|
|
823
|
+
type: "when_then_otherwise",
|
|
824
824
|
conditions: this.conditions.map((clause) => ({
|
|
825
825
|
when: clause.when.toJSON(),
|
|
826
826
|
then: clause.then.toJSON(),
|
|
@@ -829,7 +829,7 @@ class WhenThenOtherwiseExpressionImpl extends ExpressionImpl {
|
|
|
829
829
|
};
|
|
830
830
|
}
|
|
831
831
|
getAlias() {
|
|
832
|
-
return this._alias ||
|
|
832
|
+
return this._alias || "conditional";
|
|
833
833
|
}
|
|
834
834
|
clone() {
|
|
835
835
|
const cloned = new WhenThenOtherwiseExpressionImpl(this.conditions, this.otherwiseValue);
|