@milaboratories/ptabler-expression-js 1.1.0

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.
@@ -0,0 +1,867 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Base expressionImpl classes and interfaces for PTabler JavaScript implementation
5
+ */
6
+ /**
7
+ * Base abstract class for all expressions
8
+ */
9
+ class ExpressionImpl {
10
+ _alias;
11
+ /**
12
+ * Set an alias for this expression
13
+ */
14
+ alias(name) {
15
+ const cloned = this.clone();
16
+ cloned._alias = name;
17
+ return cloned;
18
+ }
19
+ // Arithmetic operations
20
+ plus(other) {
21
+ return new ArithmeticExpressionImpl('plus', this, coerceToExpression(other));
22
+ }
23
+ minus(other) {
24
+ return new ArithmeticExpressionImpl('minus', this, coerceToExpression(other));
25
+ }
26
+ multiply(other) {
27
+ return new ArithmeticExpressionImpl('multiply', this, coerceToExpression(other));
28
+ }
29
+ truediv(other) {
30
+ return new ArithmeticExpressionImpl('truediv', this, coerceToExpression(other));
31
+ }
32
+ floordiv(other) {
33
+ return new ArithmeticExpressionImpl('floordiv', this, coerceToExpression(other));
34
+ }
35
+ // Comparison operations
36
+ gt(other) {
37
+ return new ComparisonExpressionImpl('gt', this, coerceToExpression(other));
38
+ }
39
+ ge(other) {
40
+ return new ComparisonExpressionImpl('ge', this, coerceToExpression(other));
41
+ }
42
+ eq(other) {
43
+ return new ComparisonExpressionImpl('eq', this, coerceToExpression(other));
44
+ }
45
+ lt(other) {
46
+ return new ComparisonExpressionImpl('lt', this, coerceToExpression(other));
47
+ }
48
+ le(other) {
49
+ return new ComparisonExpressionImpl('le', this, coerceToExpression(other));
50
+ }
51
+ neq(other) {
52
+ return new ComparisonExpressionImpl('neq', this, coerceToExpression(other));
53
+ }
54
+ // Logical operations
55
+ and(...others) {
56
+ return new LogicalExpressionImpl('and', [this, ...others]);
57
+ }
58
+ or(...others) {
59
+ return new LogicalExpressionImpl('or', [this, ...others]);
60
+ }
61
+ not() {
62
+ return new LogicalExpressionImpl('not', [this]);
63
+ }
64
+ // Unary arithmetic operations
65
+ abs() {
66
+ return new UnaryArithmeticExpressionImpl('abs', this);
67
+ }
68
+ sqrt() {
69
+ return new UnaryArithmeticExpressionImpl('sqrt', this);
70
+ }
71
+ log() {
72
+ return new UnaryArithmeticExpressionImpl('log', this);
73
+ }
74
+ log10() {
75
+ return new UnaryArithmeticExpressionImpl('log10', this);
76
+ }
77
+ log2() {
78
+ return new UnaryArithmeticExpressionImpl('log2', this);
79
+ }
80
+ floor() {
81
+ return new UnaryArithmeticExpressionImpl('floor', this);
82
+ }
83
+ ceil() {
84
+ return new UnaryArithmeticExpressionImpl('ceil', this);
85
+ }
86
+ round() {
87
+ return new UnaryArithmeticExpressionImpl('round', this);
88
+ }
89
+ negate() {
90
+ return new UnaryArithmeticExpressionImpl('negate', this);
91
+ }
92
+ // Null checks
93
+ isNull() {
94
+ return new NullCheckExpressionImpl('is_na', this);
95
+ }
96
+ isNotNull() {
97
+ return new NullCheckExpressionImpl('is_not_na', this);
98
+ }
99
+ // Fill null/NaN
100
+ fillNull(value) {
101
+ return new FillNullExpressionImpl(this, coerceToExpression(value));
102
+ }
103
+ fillNaN(value) {
104
+ return new FillNaNExpressionImpl(this, coerceToExpression(value));
105
+ }
106
+ // String operations
107
+ strConcat(...others) {
108
+ return new StringConcatExpressionImpl([this, ...others.map(coerceToExpression)]);
109
+ }
110
+ substring(start, length) {
111
+ return new SubstringExpressionImpl(this, start, length);
112
+ }
113
+ strReplace(pattern, value, options) {
114
+ return new StringReplaceExpressionImpl(this, pattern, value, options);
115
+ }
116
+ strContains(pattern, literal, strict) {
117
+ return new StringContainsExpressionImpl(this, coerceToExpression(pattern), literal, strict);
118
+ }
119
+ strToUpper() {
120
+ return new StringCaseExpressionImpl('to_upper', this);
121
+ }
122
+ strToLower() {
123
+ return new StringCaseExpressionImpl('to_lower', this);
124
+ }
125
+ strStartsWith(pattern) {
126
+ return new StringStartsWithExpressionImpl(this, coerceToExpression(pattern));
127
+ }
128
+ strEndsWith(pattern) {
129
+ return new StringEndsWithExpressionImpl(this, coerceToExpression(pattern));
130
+ }
131
+ // Aggregation operations
132
+ sum() {
133
+ return new AggregationExpressionImpl('sum', this);
134
+ }
135
+ mean() {
136
+ return new AggregationExpressionImpl('mean', this);
137
+ }
138
+ count() {
139
+ return new AggregationExpressionImpl('count', this);
140
+ }
141
+ min() {
142
+ return new AggregationExpressionImpl('min', this);
143
+ }
144
+ max() {
145
+ return new AggregationExpressionImpl('max', this);
146
+ }
147
+ first() {
148
+ return new AggregationExpressionImpl('first', this);
149
+ }
150
+ last() {
151
+ return new AggregationExpressionImpl('last', this);
152
+ }
153
+ cumsum() {
154
+ return new CumsumExpressionImpl(this);
155
+ }
156
+ // Fuzzy operations
157
+ stringDistance(other, metric, returnSimilarity) {
158
+ return new StringDistanceExpressionImpl(this, coerceToExpression(other), metric, returnSimilarity);
159
+ }
160
+ fuzzyStringFilter(pattern, metric, bound) {
161
+ return new FuzzyStringFilterExpressionImpl(this, coerceToExpression(pattern), metric, bound);
162
+ }
163
+ }
164
+ class ColumnExpressionImpl extends ExpressionImpl {
165
+ columnName;
166
+ constructor(columnName) {
167
+ super();
168
+ this.columnName = columnName;
169
+ }
170
+ toJSON() {
171
+ return {
172
+ type: 'col',
173
+ name: this.columnName,
174
+ };
175
+ }
176
+ getAlias() {
177
+ return this._alias || this.columnName;
178
+ }
179
+ clone() {
180
+ const cloned = new ColumnExpressionImpl(this.columnName);
181
+ cloned._alias = this._alias;
182
+ return cloned;
183
+ }
184
+ /**
185
+ * Get the column name
186
+ */
187
+ getColumnName() {
188
+ return this.columnName;
189
+ }
190
+ }
191
+ /**
192
+ * Helper function to coerce values to expressions
193
+ */
194
+ function coerceToExpression(value) {
195
+ if (value instanceof ExpressionImpl) {
196
+ return value;
197
+ }
198
+ return new LiteralExpressionImpl(value);
199
+ }
200
+ class MinMaxExpressionImpl extends ExpressionImpl {
201
+ op;
202
+ ops;
203
+ constructor(op, ops) {
204
+ super();
205
+ this.op = op;
206
+ this.ops = ops;
207
+ }
208
+ toJSON() {
209
+ return {
210
+ type: this.op,
211
+ operands: this.ops.map((o) => o.toJSON()),
212
+ };
213
+ }
214
+ getAlias() {
215
+ return this._alias || `${this.op}_${this.ops.map((o) => o.getAlias()).join('_')}`;
216
+ }
217
+ clone() {
218
+ const cloned = new MinMaxExpressionImpl(this.op, this.ops);
219
+ cloned._alias = this._alias;
220
+ return cloned;
221
+ }
222
+ }
223
+ // Forward declarations for concrete expressionImpl classes
224
+ // These will be imported from their respective modules
225
+ class ArithmeticExpressionImpl extends ExpressionImpl {
226
+ operator;
227
+ lhs;
228
+ rhs;
229
+ constructor(operator, lhs, rhs) {
230
+ super();
231
+ this.operator = operator;
232
+ this.lhs = lhs;
233
+ this.rhs = rhs;
234
+ }
235
+ toJSON() {
236
+ return {
237
+ type: this.operator,
238
+ lhs: this.lhs.toJSON(),
239
+ rhs: this.rhs.toJSON(),
240
+ };
241
+ }
242
+ getAlias() {
243
+ return this._alias || `${this.lhs.getAlias()}_${this.operator}_${this.rhs.getAlias()}`;
244
+ }
245
+ clone() {
246
+ const cloned = new ArithmeticExpressionImpl(this.operator, this.lhs, this.rhs);
247
+ cloned._alias = this._alias;
248
+ return cloned;
249
+ }
250
+ }
251
+ class ComparisonExpressionImpl extends ExpressionImpl {
252
+ operator;
253
+ lhs;
254
+ rhs;
255
+ constructor(operator, lhs, rhs) {
256
+ super();
257
+ this.operator = operator;
258
+ this.lhs = lhs;
259
+ this.rhs = rhs;
260
+ }
261
+ toJSON() {
262
+ return {
263
+ type: this.operator,
264
+ lhs: this.lhs.toJSON(),
265
+ rhs: this.rhs.toJSON(),
266
+ };
267
+ }
268
+ getAlias() {
269
+ return this._alias || `${this.lhs.getAlias()}_${this.operator}_${this.rhs.getAlias()}`;
270
+ }
271
+ clone() {
272
+ const cloned = new ComparisonExpressionImpl(this.operator, this.lhs, this.rhs);
273
+ cloned._alias = this._alias;
274
+ return cloned;
275
+ }
276
+ }
277
+ class LogicalExpressionImpl extends ExpressionImpl {
278
+ operator;
279
+ operands;
280
+ constructor(operator, operands) {
281
+ super();
282
+ this.operator = operator;
283
+ this.operands = operands;
284
+ }
285
+ toJSON() {
286
+ if (this.operator === 'not') {
287
+ return {
288
+ type: 'not',
289
+ value: this.operands[0].toJSON(),
290
+ };
291
+ }
292
+ return {
293
+ type: this.operator,
294
+ operands: this.operands.map((op) => op.toJSON()),
295
+ };
296
+ }
297
+ getAlias() {
298
+ if (this._alias)
299
+ return this._alias;
300
+ if (this.operator === 'not') {
301
+ return `not_${this.operands[0].getAlias()}`;
302
+ }
303
+ return this.operands.map((op) => op.getAlias()).join(`_${this.operator}_`);
304
+ }
305
+ clone() {
306
+ const cloned = new LogicalExpressionImpl(this.operator, this.operands);
307
+ cloned._alias = this._alias;
308
+ return cloned;
309
+ }
310
+ }
311
+ class UnaryArithmeticExpressionImpl extends ExpressionImpl {
312
+ operator;
313
+ value;
314
+ constructor(operator, value) {
315
+ super();
316
+ this.operator = operator;
317
+ this.value = value;
318
+ }
319
+ toJSON() {
320
+ return {
321
+ type: this.operator,
322
+ value: this.value.toJSON(),
323
+ };
324
+ }
325
+ getAlias() {
326
+ return this._alias || `${this.operator}_${this.value.getAlias()}`;
327
+ }
328
+ clone() {
329
+ const cloned = new UnaryArithmeticExpressionImpl(this.operator, this.value);
330
+ cloned._alias = this._alias;
331
+ return cloned;
332
+ }
333
+ }
334
+ class NullCheckExpressionImpl extends ExpressionImpl {
335
+ operator;
336
+ value;
337
+ constructor(operator, value) {
338
+ super();
339
+ this.operator = operator;
340
+ this.value = value;
341
+ }
342
+ toJSON() {
343
+ return {
344
+ type: this.operator,
345
+ value: this.value.toJSON(),
346
+ };
347
+ }
348
+ getAlias() {
349
+ return this._alias || `${this.value.getAlias()}_${this.operator}`;
350
+ }
351
+ clone() {
352
+ const cloned = new NullCheckExpressionImpl(this.operator, this.value);
353
+ cloned._alias = this._alias;
354
+ return cloned;
355
+ }
356
+ }
357
+ class LiteralExpressionImpl extends ExpressionImpl {
358
+ value;
359
+ constructor(value) {
360
+ super();
361
+ this.value = value;
362
+ }
363
+ toJSON() {
364
+ return {
365
+ type: 'const',
366
+ value: this.value,
367
+ };
368
+ }
369
+ getAlias() {
370
+ return this._alias || this.generateDefaultAlias();
371
+ }
372
+ clone() {
373
+ const cloned = new LiteralExpressionImpl(this.value);
374
+ cloned._alias = this._alias;
375
+ return cloned;
376
+ }
377
+ /**
378
+ * Get the literal value
379
+ */
380
+ getValue() {
381
+ return this.value;
382
+ }
383
+ /**
384
+ * Generate a default alias based on the value
385
+ */
386
+ generateDefaultAlias() {
387
+ if (this.value === null || this.value === undefined) {
388
+ return 'null';
389
+ }
390
+ if (typeof this.value === 'string') {
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;
394
+ }
395
+ if (typeof this.value === 'boolean') {
396
+ return this.value ? 'true' : 'false';
397
+ }
398
+ if (typeof this.value === 'number') {
399
+ return String(this.value);
400
+ }
401
+ if (Array.isArray(this.value)) {
402
+ return 'array';
403
+ }
404
+ if (typeof this.value === 'object') {
405
+ return 'object';
406
+ }
407
+ return 'literal';
408
+ }
409
+ }
410
+ class FillNullExpressionImpl extends ExpressionImpl {
411
+ expr;
412
+ fillValue;
413
+ constructor(expr, fillValue) {
414
+ super();
415
+ this.expr = expr;
416
+ this.fillValue = fillValue;
417
+ }
418
+ toJSON() {
419
+ return {
420
+ type: 'fill_null',
421
+ input: this.expr.toJSON(),
422
+ fillValue: this.fillValue.toJSON(),
423
+ };
424
+ }
425
+ getAlias() {
426
+ return this._alias || `${this.expr.getAlias()}_fill_null`;
427
+ }
428
+ clone() {
429
+ const cloned = new FillNullExpressionImpl(this.expr, this.fillValue);
430
+ cloned._alias = this._alias;
431
+ return cloned;
432
+ }
433
+ }
434
+ class FillNaNExpressionImpl extends ExpressionImpl {
435
+ expr;
436
+ fillValue;
437
+ constructor(expr, fillValue) {
438
+ super();
439
+ this.expr = expr;
440
+ this.fillValue = fillValue;
441
+ }
442
+ toJSON() {
443
+ return {
444
+ type: 'fill_nan',
445
+ input: this.expr.toJSON(),
446
+ fillValue: this.fillValue.toJSON(),
447
+ };
448
+ }
449
+ getAlias() {
450
+ return this._alias || `${this.expr.getAlias()}_fill_nan`;
451
+ }
452
+ clone() {
453
+ const cloned = new FillNaNExpressionImpl(this.expr, this.fillValue);
454
+ cloned._alias = this._alias;
455
+ return cloned;
456
+ }
457
+ }
458
+ class StringConcatExpressionImpl extends ExpressionImpl {
459
+ operands;
460
+ delimiter;
461
+ constructor(operands, delimiter = '') {
462
+ super();
463
+ this.operands = operands;
464
+ this.delimiter = delimiter;
465
+ }
466
+ toJSON() {
467
+ return {
468
+ type: 'str_join',
469
+ operands: this.operands.map((o) => o.toJSON()),
470
+ delimiter: this.delimiter,
471
+ };
472
+ }
473
+ getAlias() {
474
+ return this._alias || this.operands.map((o) => o.getAlias()).join('_');
475
+ }
476
+ clone() {
477
+ const cloned = new StringConcatExpressionImpl(this.operands);
478
+ cloned._alias = this._alias;
479
+ return cloned;
480
+ }
481
+ }
482
+ class SubstringExpressionImpl extends ExpressionImpl {
483
+ expr;
484
+ start;
485
+ length;
486
+ constructor(expr, start, length) {
487
+ super();
488
+ this.expr = expr;
489
+ this.start = start;
490
+ this.length = length;
491
+ }
492
+ toJSON() {
493
+ return {
494
+ type: 'substring',
495
+ value: this.expr.toJSON(),
496
+ start: { type: 'const', value: this.start },
497
+ length: this.length !== undefined ? { type: 'const', value: this.length } : undefined,
498
+ };
499
+ }
500
+ getAlias() {
501
+ return this._alias || `${this.expr.getAlias()}_substring`;
502
+ }
503
+ clone() {
504
+ const cloned = new SubstringExpressionImpl(this.expr, this.start, this.length);
505
+ cloned._alias = this._alias;
506
+ return cloned;
507
+ }
508
+ }
509
+ class StringReplaceExpressionImpl extends ExpressionImpl {
510
+ expr;
511
+ pattern;
512
+ value;
513
+ options;
514
+ constructor(expr, pattern, value, options) {
515
+ super();
516
+ this.expr = expr;
517
+ this.pattern = pattern;
518
+ this.value = value;
519
+ this.options = options;
520
+ }
521
+ toJSON() {
522
+ return {
523
+ type: 'str_replace',
524
+ value: this.expr.toJSON(),
525
+ pattern: this.pattern,
526
+ replacement: this.value,
527
+ replaceAll: this.options?.replaceAll || false,
528
+ literal: this.options?.literal || false,
529
+ };
530
+ }
531
+ getAlias() {
532
+ return this._alias || `${this.expr.getAlias()}_replace`;
533
+ }
534
+ clone() {
535
+ const cloned = new StringReplaceExpressionImpl(this.expr, this.pattern, this.value, this.options);
536
+ cloned._alias = this._alias;
537
+ return cloned;
538
+ }
539
+ }
540
+ class StringContainsExpressionImpl extends ExpressionImpl {
541
+ expr;
542
+ pattern;
543
+ literal;
544
+ strict;
545
+ constructor(expr, pattern, literal, strict) {
546
+ super();
547
+ this.expr = expr;
548
+ this.pattern = pattern;
549
+ this.literal = literal;
550
+ this.strict = strict;
551
+ }
552
+ toJSON() {
553
+ return {
554
+ type: 'str_contains',
555
+ value: this.expr.toJSON(),
556
+ pattern: this.pattern.toJSON(),
557
+ literal: this.literal || false,
558
+ strict: this.strict !== undefined ? this.strict : true,
559
+ };
560
+ }
561
+ getAlias() {
562
+ return this._alias || `${this.expr.getAlias()}_contains`;
563
+ }
564
+ clone() {
565
+ const cloned = new StringContainsExpressionImpl(this.expr, this.pattern, this.literal, this.strict);
566
+ cloned._alias = this._alias;
567
+ return cloned;
568
+ }
569
+ }
570
+ class StringCaseExpressionImpl extends ExpressionImpl {
571
+ operation;
572
+ expr;
573
+ constructor(operation, expr) {
574
+ super();
575
+ this.operation = operation;
576
+ this.expr = expr;
577
+ }
578
+ toJSON() {
579
+ return {
580
+ type: this.operation,
581
+ value: this.expr.toJSON(),
582
+ };
583
+ }
584
+ getAlias() {
585
+ return this._alias || `${this.expr.getAlias()}_${this.operation}`;
586
+ }
587
+ clone() {
588
+ const cloned = new StringCaseExpressionImpl(this.operation, this.expr);
589
+ cloned._alias = this._alias;
590
+ return cloned;
591
+ }
592
+ }
593
+ class StringStartsWithExpressionImpl extends ExpressionImpl {
594
+ expr;
595
+ pattern;
596
+ constructor(expr, pattern) {
597
+ super();
598
+ this.expr = expr;
599
+ this.pattern = pattern;
600
+ }
601
+ toJSON() {
602
+ return {
603
+ type: 'str_starts_with',
604
+ value: this.expr.toJSON(),
605
+ prefix: this.pattern.toJSON(),
606
+ };
607
+ }
608
+ getAlias() {
609
+ return this._alias || `${this.expr.getAlias()}_starts_with`;
610
+ }
611
+ clone() {
612
+ const cloned = new StringStartsWithExpressionImpl(this.expr, this.pattern);
613
+ cloned._alias = this._alias;
614
+ return cloned;
615
+ }
616
+ }
617
+ class StringEndsWithExpressionImpl extends ExpressionImpl {
618
+ expr;
619
+ pattern;
620
+ constructor(expr, pattern) {
621
+ super();
622
+ this.expr = expr;
623
+ this.pattern = pattern;
624
+ }
625
+ toJSON() {
626
+ return {
627
+ type: 'str_ends_with',
628
+ value: this.expr.toJSON(),
629
+ suffix: this.pattern.toJSON(),
630
+ };
631
+ }
632
+ getAlias() {
633
+ return this._alias || `${this.expr.getAlias()}_ends_with`;
634
+ }
635
+ clone() {
636
+ const cloned = new StringEndsWithExpressionImpl(this.expr, this.pattern);
637
+ cloned._alias = this._alias;
638
+ return cloned;
639
+ }
640
+ }
641
+ class CumsumExpressionImpl extends ExpressionImpl {
642
+ value;
643
+ additionalOrderBy;
644
+ partitionBy;
645
+ descending;
646
+ constructor(value, additionalOrderBy = [], partitionBy = [], descending) {
647
+ super();
648
+ this.value = value;
649
+ this.additionalOrderBy = additionalOrderBy;
650
+ this.partitionBy = partitionBy;
651
+ this.descending = descending;
652
+ }
653
+ toJSON() {
654
+ return {
655
+ type: 'cumsum',
656
+ value: this.value.toJSON(),
657
+ additionalOrderBy: this.additionalOrderBy.map((expr) => expr.toJSON()),
658
+ partitionBy: this.partitionBy.map((expr) => expr.toJSON()),
659
+ descending: this.descending,
660
+ };
661
+ }
662
+ getAlias() {
663
+ return this._alias || `cumsum_${this.value.getAlias()}`;
664
+ }
665
+ clone() {
666
+ const cloned = new CumsumExpressionImpl(this.value, this.additionalOrderBy, this.partitionBy, this.descending);
667
+ cloned._alias = this._alias;
668
+ return cloned;
669
+ }
670
+ }
671
+ class AggregationExpressionImpl extends ExpressionImpl {
672
+ operation;
673
+ expr;
674
+ constructor(operation, expr) {
675
+ super();
676
+ this.operation = operation;
677
+ this.expr = expr;
678
+ }
679
+ toJSON() {
680
+ return {
681
+ type: 'aggregate',
682
+ aggregation: this.operation,
683
+ value: this.expr?.toJSON() || { type: 'const', value: 1 },
684
+ partitionBy: [],
685
+ };
686
+ }
687
+ getAlias() {
688
+ return this._alias || `${this.operation}${this.expr ? '_' + this.expr.getAlias() : ''}`;
689
+ }
690
+ clone() {
691
+ const cloned = new AggregationExpressionImpl(this.operation, this.expr);
692
+ cloned._alias = this._alias;
693
+ return cloned;
694
+ }
695
+ }
696
+ class WindowExpressionImpl extends ExpressionImpl {
697
+ expr;
698
+ aggregation;
699
+ partitionBy;
700
+ constructor(expr, aggregation, partitionBy) {
701
+ super();
702
+ this.expr = expr;
703
+ this.aggregation = aggregation;
704
+ this.partitionBy = partitionBy;
705
+ }
706
+ toJSON() {
707
+ return {
708
+ type: 'aggregate',
709
+ aggregation: this.aggregation,
710
+ value: this.expr.toJSON(),
711
+ partitionBy: this.partitionBy.map((expr) => expr.toJSON()),
712
+ };
713
+ }
714
+ getAlias() {
715
+ return this._alias || `${this.expr.getAlias()}_window`;
716
+ }
717
+ clone() {
718
+ const cloned = new WindowExpressionImpl(this.expr, this.aggregation, this.partitionBy);
719
+ cloned._alias = this._alias;
720
+ return cloned;
721
+ }
722
+ }
723
+ class StringDistanceExpressionImpl extends ExpressionImpl {
724
+ string1;
725
+ string2;
726
+ metric;
727
+ returnSimilarity;
728
+ constructor(string1, string2, metric, returnSimilarity) {
729
+ super();
730
+ this.string1 = string1;
731
+ this.string2 = string2;
732
+ this.metric = metric;
733
+ this.returnSimilarity = returnSimilarity;
734
+ }
735
+ toJSON() {
736
+ return {
737
+ type: 'string_distance',
738
+ metric: this.metric,
739
+ string1: this.string1.toJSON(),
740
+ string2: this.string2.toJSON(),
741
+ returnSimilarity: this.returnSimilarity || false,
742
+ };
743
+ }
744
+ getAlias() {
745
+ return this._alias || `${this.string1.getAlias()}_distance_${this.string2.getAlias()}`;
746
+ }
747
+ clone() {
748
+ const cloned = new StringDistanceExpressionImpl(this.string1, this.string2, this.metric, this.returnSimilarity);
749
+ cloned._alias = this._alias;
750
+ return cloned;
751
+ }
752
+ }
753
+ class FuzzyStringFilterExpressionImpl extends ExpressionImpl {
754
+ expr;
755
+ pattern;
756
+ metric;
757
+ bound;
758
+ constructor(expr, pattern, metric, bound) {
759
+ super();
760
+ this.expr = expr;
761
+ this.pattern = pattern;
762
+ this.metric = metric;
763
+ this.bound = bound;
764
+ }
765
+ toJSON() {
766
+ return {
767
+ type: 'fuzzy_string_filter',
768
+ metric: this.metric,
769
+ value: this.expr.toJSON(),
770
+ pattern: this.pattern.toJSON(),
771
+ bound: this.bound,
772
+ };
773
+ }
774
+ getAlias() {
775
+ return this._alias || `${this.expr.getAlias()}_fuzzy_filter`;
776
+ }
777
+ clone() {
778
+ const cloned = new FuzzyStringFilterExpressionImpl(this.expr, this.pattern, this.metric, this.bound);
779
+ cloned._alias = this._alias;
780
+ return cloned;
781
+ }
782
+ }
783
+ class RankExpressionImpl extends ExpressionImpl {
784
+ orderBy;
785
+ partitionBy;
786
+ descending;
787
+ constructor(orderBy, partitionBy, descending) {
788
+ super();
789
+ this.orderBy = orderBy;
790
+ this.partitionBy = partitionBy;
791
+ this.descending = descending;
792
+ }
793
+ toJSON() {
794
+ return {
795
+ type: 'rank',
796
+ orderBy: this.orderBy.map((e) => e.toJSON()),
797
+ partitionBy: this.partitionBy.map((e) => e.toJSON()),
798
+ descending: this.descending || undefined,
799
+ };
800
+ }
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}`;
806
+ }
807
+ clone() {
808
+ const cloned = new RankExpressionImpl(this.orderBy, this.partitionBy, this.descending);
809
+ cloned._alias = this._alias;
810
+ return cloned;
811
+ }
812
+ }
813
+ class WhenThenOtherwiseExpressionImpl extends ExpressionImpl {
814
+ conditions;
815
+ otherwiseValue;
816
+ constructor(conditions, otherwiseValue) {
817
+ super();
818
+ this.conditions = conditions;
819
+ this.otherwiseValue = otherwiseValue;
820
+ }
821
+ toJSON() {
822
+ return {
823
+ type: 'when_then_otherwise',
824
+ conditions: this.conditions.map((clause) => ({
825
+ when: clause.when.toJSON(),
826
+ then: clause.then.toJSON(),
827
+ })),
828
+ otherwise: this.otherwiseValue.toJSON(),
829
+ };
830
+ }
831
+ getAlias() {
832
+ return this._alias || 'conditional';
833
+ }
834
+ clone() {
835
+ const cloned = new WhenThenOtherwiseExpressionImpl(this.conditions, this.otherwiseValue);
836
+ cloned._alias = this._alias;
837
+ return cloned;
838
+ }
839
+ }
840
+
841
+ exports.AggregationExpressionImpl = AggregationExpressionImpl;
842
+ exports.ArithmeticExpressionImpl = ArithmeticExpressionImpl;
843
+ exports.ColumnExpressionImpl = ColumnExpressionImpl;
844
+ exports.ComparisonExpressionImpl = ComparisonExpressionImpl;
845
+ exports.CumsumExpressionImpl = CumsumExpressionImpl;
846
+ exports.ExpressionImpl = ExpressionImpl;
847
+ exports.FillNaNExpressionImpl = FillNaNExpressionImpl;
848
+ exports.FillNullExpressionImpl = FillNullExpressionImpl;
849
+ exports.FuzzyStringFilterExpressionImpl = FuzzyStringFilterExpressionImpl;
850
+ exports.LiteralExpressionImpl = LiteralExpressionImpl;
851
+ exports.LogicalExpressionImpl = LogicalExpressionImpl;
852
+ exports.MinMaxExpressionImpl = MinMaxExpressionImpl;
853
+ exports.NullCheckExpressionImpl = NullCheckExpressionImpl;
854
+ exports.RankExpressionImpl = RankExpressionImpl;
855
+ exports.StringCaseExpressionImpl = StringCaseExpressionImpl;
856
+ exports.StringConcatExpressionImpl = StringConcatExpressionImpl;
857
+ exports.StringContainsExpressionImpl = StringContainsExpressionImpl;
858
+ exports.StringDistanceExpressionImpl = StringDistanceExpressionImpl;
859
+ exports.StringEndsWithExpressionImpl = StringEndsWithExpressionImpl;
860
+ exports.StringReplaceExpressionImpl = StringReplaceExpressionImpl;
861
+ exports.StringStartsWithExpressionImpl = StringStartsWithExpressionImpl;
862
+ exports.SubstringExpressionImpl = SubstringExpressionImpl;
863
+ exports.UnaryArithmeticExpressionImpl = UnaryArithmeticExpressionImpl;
864
+ exports.WhenThenOtherwiseExpressionImpl = WhenThenOtherwiseExpressionImpl;
865
+ exports.WindowExpressionImpl = WindowExpressionImpl;
866
+ exports.coerceToExpression = coerceToExpression;
867
+ //# sourceMappingURL=expressions.cjs.map