@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.
@@ -18,83 +18,83 @@ class ExpressionImpl {
18
18
  }
19
19
  // Arithmetic operations
20
20
  plus(other) {
21
- return new ArithmeticExpressionImpl('plus', this, coerceToExpression(other));
21
+ return new ArithmeticExpressionImpl("plus", this, coerceToExpression(other));
22
22
  }
23
23
  minus(other) {
24
- return new ArithmeticExpressionImpl('minus', this, coerceToExpression(other));
24
+ return new ArithmeticExpressionImpl("minus", this, coerceToExpression(other));
25
25
  }
26
26
  multiply(other) {
27
- return new ArithmeticExpressionImpl('multiply', this, coerceToExpression(other));
27
+ return new ArithmeticExpressionImpl("multiply", this, coerceToExpression(other));
28
28
  }
29
29
  truediv(other) {
30
- return new ArithmeticExpressionImpl('truediv', this, coerceToExpression(other));
30
+ return new ArithmeticExpressionImpl("truediv", this, coerceToExpression(other));
31
31
  }
32
32
  floordiv(other) {
33
- return new ArithmeticExpressionImpl('floordiv', this, coerceToExpression(other));
33
+ return new ArithmeticExpressionImpl("floordiv", this, coerceToExpression(other));
34
34
  }
35
35
  // Comparison operations
36
36
  gt(other) {
37
- return new ComparisonExpressionImpl('gt', this, coerceToExpression(other));
37
+ return new ComparisonExpressionImpl("gt", this, coerceToExpression(other));
38
38
  }
39
39
  ge(other) {
40
- return new ComparisonExpressionImpl('ge', this, coerceToExpression(other));
40
+ return new ComparisonExpressionImpl("ge", this, coerceToExpression(other));
41
41
  }
42
42
  eq(other) {
43
- return new ComparisonExpressionImpl('eq', this, coerceToExpression(other));
43
+ return new ComparisonExpressionImpl("eq", this, coerceToExpression(other));
44
44
  }
45
45
  lt(other) {
46
- return new ComparisonExpressionImpl('lt', this, coerceToExpression(other));
46
+ return new ComparisonExpressionImpl("lt", this, coerceToExpression(other));
47
47
  }
48
48
  le(other) {
49
- return new ComparisonExpressionImpl('le', this, coerceToExpression(other));
49
+ return new ComparisonExpressionImpl("le", this, coerceToExpression(other));
50
50
  }
51
51
  neq(other) {
52
- return new ComparisonExpressionImpl('neq', this, coerceToExpression(other));
52
+ return new ComparisonExpressionImpl("neq", this, coerceToExpression(other));
53
53
  }
54
54
  // Logical operations
55
55
  and(...others) {
56
- return new LogicalExpressionImpl('and', [this, ...others]);
56
+ return new LogicalExpressionImpl("and", [this, ...others]);
57
57
  }
58
58
  or(...others) {
59
- return new LogicalExpressionImpl('or', [this, ...others]);
59
+ return new LogicalExpressionImpl("or", [this, ...others]);
60
60
  }
61
61
  not() {
62
- return new LogicalExpressionImpl('not', [this]);
62
+ return new LogicalExpressionImpl("not", [this]);
63
63
  }
64
64
  // Unary arithmetic operations
65
65
  abs() {
66
- return new UnaryArithmeticExpressionImpl('abs', this);
66
+ return new UnaryArithmeticExpressionImpl("abs", this);
67
67
  }
68
68
  sqrt() {
69
- return new UnaryArithmeticExpressionImpl('sqrt', this);
69
+ return new UnaryArithmeticExpressionImpl("sqrt", this);
70
70
  }
71
71
  log() {
72
- return new UnaryArithmeticExpressionImpl('log', this);
72
+ return new UnaryArithmeticExpressionImpl("log", this);
73
73
  }
74
74
  log10() {
75
- return new UnaryArithmeticExpressionImpl('log10', this);
75
+ return new UnaryArithmeticExpressionImpl("log10", this);
76
76
  }
77
77
  log2() {
78
- return new UnaryArithmeticExpressionImpl('log2', this);
78
+ return new UnaryArithmeticExpressionImpl("log2", this);
79
79
  }
80
80
  floor() {
81
- return new UnaryArithmeticExpressionImpl('floor', this);
81
+ return new UnaryArithmeticExpressionImpl("floor", this);
82
82
  }
83
83
  ceil() {
84
- return new UnaryArithmeticExpressionImpl('ceil', this);
84
+ return new UnaryArithmeticExpressionImpl("ceil", this);
85
85
  }
86
86
  round() {
87
- return new UnaryArithmeticExpressionImpl('round', this);
87
+ return new UnaryArithmeticExpressionImpl("round", this);
88
88
  }
89
89
  negate() {
90
- return new UnaryArithmeticExpressionImpl('negate', this);
90
+ return new UnaryArithmeticExpressionImpl("negate", this);
91
91
  }
92
92
  // Null checks
93
93
  isNull() {
94
- return new NullCheckExpressionImpl('is_na', this);
94
+ return new NullCheckExpressionImpl("is_na", this);
95
95
  }
96
96
  isNotNull() {
97
- return new NullCheckExpressionImpl('is_not_na', this);
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('to_upper', this);
120
+ return new StringCaseExpressionImpl("to_upper", this);
121
121
  }
122
122
  strToLower() {
123
- return new StringCaseExpressionImpl('to_lower', this);
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('sum', this);
133
+ return new AggregationExpressionImpl("sum", this);
134
134
  }
135
135
  mean() {
136
- return new AggregationExpressionImpl('mean', this);
136
+ return new AggregationExpressionImpl("mean", this);
137
137
  }
138
138
  count() {
139
- return new AggregationExpressionImpl('count', this);
139
+ return new AggregationExpressionImpl("count", this);
140
140
  }
141
141
  min() {
142
- return new AggregationExpressionImpl('min', this);
142
+ return new AggregationExpressionImpl("min", this);
143
143
  }
144
144
  max() {
145
- return new AggregationExpressionImpl('max', this);
145
+ return new AggregationExpressionImpl("max", this);
146
146
  }
147
147
  first() {
148
- return new AggregationExpressionImpl('first', this);
148
+ return new AggregationExpressionImpl("first", this);
149
149
  }
150
150
  last() {
151
- return new AggregationExpressionImpl('last', this);
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: 'col',
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 === 'not') {
286
+ if (this.operator === "not") {
287
287
  return {
288
- type: 'not',
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 === 'not') {
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: 'const',
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 'null';
388
+ return "null";
389
389
  }
390
- if (typeof this.value === 'string') {
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) + '...' : safe;
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 === 'boolean') {
396
- return this.value ? 'true' : 'false';
395
+ if (typeof this.value === "boolean") {
396
+ return this.value ? "true" : "false";
397
397
  }
398
- if (typeof this.value === 'number') {
398
+ if (typeof this.value === "number") {
399
399
  return String(this.value);
400
400
  }
401
401
  if (Array.isArray(this.value)) {
402
- return 'array';
402
+ return "array";
403
403
  }
404
- if (typeof this.value === 'object') {
405
- return 'object';
404
+ if (typeof this.value === "object") {
405
+ return "object";
406
406
  }
407
- return 'literal';
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: 'fill_null',
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: 'fill_nan',
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: 'str_join',
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: 'substring',
494
+ type: "substring",
495
495
  value: this.expr.toJSON(),
496
- start: { type: 'const', value: this.start },
497
- length: this.length !== undefined ? { type: 'const', value: this.length } : undefined,
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: 'str_replace',
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: 'str_contains',
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: 'str_starts_with',
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: 'str_ends_with',
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: 'cumsum',
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: 'aggregate',
681
+ type: "aggregate",
682
682
  aggregation: this.operation,
683
- value: this.expr?.toJSON() || { type: 'const', value: 1 },
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 ? '_' + this.expr.getAlias() : ''}`;
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: 'aggregate',
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: 'string_distance',
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: 'fuzzy_string_filter',
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: 'rank',
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 ? 'desc' : 'asc';
805
- return this._alias || `rank_${order}${part ? `_over_${part}` : ''}_${dir}`;
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: 'when_then_otherwise',
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 || 'conditional';
832
+ return this._alias || "conditional";
833
833
  }
834
834
  clone() {
835
835
  const cloned = new WhenThenOtherwiseExpressionImpl(this.conditions, this.otherwiseValue);