@milaboratories/ptabler-expression-js 1.1.23 → 1.1.24

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