@quillsql/react 2.12.31 → 2.12.33

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.
Files changed (44) hide show
  1. package/dist/cjs/hooks/useQuill.d.ts.map +1 -1
  2. package/dist/cjs/hooks/useQuill.js +2 -2
  3. package/dist/cjs/utils/dataProcessing.d.ts +1 -1
  4. package/dist/cjs/utils/dataProcessing.d.ts.map +1 -1
  5. package/dist/cjs/utils/dataProcessing.js +7 -1
  6. package/dist/esm/hooks/useQuill.d.ts.map +1 -1
  7. package/dist/esm/hooks/useQuill.js +3 -3
  8. package/dist/esm/utils/dataProcessing.d.ts +1 -1
  9. package/dist/esm/utils/dataProcessing.d.ts.map +1 -1
  10. package/dist/esm/utils/dataProcessing.js +7 -1
  11. package/package.json +1 -1
  12. package/dist/esm/components/ReportBuilder/convert.uspec.d.ts +0 -2
  13. package/dist/esm/components/ReportBuilder/convert.uspec.d.ts.map +0 -1
  14. package/dist/esm/components/ReportBuilder/convert.uspec.js +0 -1419
  15. package/dist/esm/test-utils/constants.d.ts +0 -56
  16. package/dist/esm/test-utils/constants.d.ts.map +0 -1
  17. package/dist/esm/test-utils/constants.js +0 -271
  18. package/dist/esm/test-utils/generators.d.ts +0 -4
  19. package/dist/esm/test-utils/generators.d.ts.map +0 -1
  20. package/dist/esm/test-utils/generators.js +0 -37
  21. package/dist/esm/utils/astFilterProcessing.uspec.d.ts +0 -2
  22. package/dist/esm/utils/astFilterProcessing.uspec.d.ts.map +0 -1
  23. package/dist/esm/utils/astFilterProcessing.uspec.js +0 -2877
  24. package/dist/esm/utils/columnProcessing.uspec.d.ts +0 -2
  25. package/dist/esm/utils/columnProcessing.uspec.d.ts.map +0 -1
  26. package/dist/esm/utils/columnProcessing.uspec.js +0 -65
  27. package/dist/esm/utils/dataProcessing.uspec.d.ts +0 -2
  28. package/dist/esm/utils/dataProcessing.uspec.d.ts.map +0 -1
  29. package/dist/esm/utils/dataProcessing.uspec.js +0 -205
  30. package/dist/esm/utils/filterProcessing.uspec.d.ts +0 -2
  31. package/dist/esm/utils/filterProcessing.uspec.d.ts.map +0 -1
  32. package/dist/esm/utils/filterProcessing.uspec.js +0 -245
  33. package/dist/esm/utils/queryConstructor.uspec.d.ts +0 -2
  34. package/dist/esm/utils/queryConstructor.uspec.d.ts.map +0 -1
  35. package/dist/esm/utils/queryConstructor.uspec.js +0 -223
  36. package/dist/esm/utils/report.ispec.d.ts +0 -2
  37. package/dist/esm/utils/report.ispec.d.ts.map +0 -1
  38. package/dist/esm/utils/report.ispec.js +0 -46
  39. package/dist/esm/utils/report.uspec.d.ts +0 -2
  40. package/dist/esm/utils/report.uspec.d.ts.map +0 -1
  41. package/dist/esm/utils/report.uspec.js +0 -66
  42. package/dist/esm/utils/tableProcessing.ispec.d.ts +0 -2
  43. package/dist/esm/utils/tableProcessing.ispec.d.ts.map +0 -1
  44. package/dist/esm/utils/tableProcessing.ispec.js +0 -61
@@ -1,2877 +0,0 @@
1
- /* eslint-disable no-undef */
2
- import { BoolOperator, DateOperator, FieldTypes, FilterNames, NullOperator, NumberOperator, StringOperator, TimeUnit, } from '../models/Filter';
3
- import { astToFilter, filterToAst } from './astFilterProcessing';
4
- import { format, subDays, subMonths, subYears } from 'date-fns';
5
- import * as fs from 'fs';
6
- import * as path from 'path';
7
- const astLookup = () => {
8
- const filePath = path.join(__dirname, 'astFilterProcessingInputs.json');
9
- const fileContent = fs.readFileSync(filePath, 'utf-8');
10
- return JSON.parse(fileContent);
11
- };
12
- const parseSelectSQL = (sql, db) => astLookup()[sql][db ?? 'default'];
13
- describe('Filter to AST - String', () => {
14
- it('should convert Filter to AST for string field - Is', () => {
15
- const filter = {
16
- field: 'field',
17
- name: FilterNames.StringInFilter,
18
- type: FieldTypes.String,
19
- operator: StringOperator.Is,
20
- value: ['value 1', 'value 2'],
21
- };
22
- const ast = filterToAst(filter, 'mysql');
23
- const sql = "SELECT * FROM t WHERE LOWER(field) IN (LOWER('value 1'), LOWER('value 2'))";
24
- const expectedAst = parseSelectSQL(sql).where;
25
- expect(ast).toEqual(expectedAst);
26
- });
27
- it('should convert Filter to AST for string field - IsNot', () => {
28
- const filter = {
29
- field: 'field',
30
- name: FilterNames.StringInFilter,
31
- type: FieldTypes.String,
32
- operator: StringOperator.IsNot,
33
- value: ['value 1', 'value 2'],
34
- };
35
- const ast = filterToAst(filter, 'mysql');
36
- const sql = "SELECT * FROM t WHERE LOWER(field) NOT IN (LOWER('value 1'), LOWER('value 2'))";
37
- const expectedAst = parseSelectSQL(sql).where;
38
- expect(ast).toEqual(expectedAst);
39
- });
40
- it('should convert Filter to AST for string field - IsNull', () => {
41
- const filter = {
42
- field: 'field',
43
- name: FilterNames.NullFilter,
44
- type: FieldTypes.Null,
45
- operator: NullOperator.IsNull,
46
- value: null,
47
- };
48
- const ast = filterToAst(filter, 'mysql');
49
- const sql = 'SELECT * FROM t WHERE field IS NULL';
50
- const expectedAst = parseSelectSQL(sql).where;
51
- expect(ast).toEqual(expectedAst);
52
- });
53
- it('should convert Filter to AST for string field - IsNotNull', () => {
54
- const filter = {
55
- field: 'field',
56
- name: FilterNames.NullFilter,
57
- type: FieldTypes.Null,
58
- operator: NullOperator.IsNotNull,
59
- value: null,
60
- };
61
- const ast = filterToAst(filter, 'mysql');
62
- const sql = 'SELECT * FROM t WHERE field IS NOT NULL';
63
- const expectedAst = parseSelectSQL(sql).where;
64
- expect(ast).toEqual(expectedAst);
65
- });
66
- it('should convert Filter to AST for string field - IsExactly (Redshift)', () => {
67
- const filter = {
68
- field: 'field',
69
- name: FilterNames.StringFilter,
70
- type: FieldTypes.String,
71
- operator: StringOperator.IsExactly,
72
- value: 'value 1',
73
- };
74
- const ast = filterToAst(filter, 'redshift');
75
- const sql = "SELECT * FROM t WHERE LOWER(field) = LOWER('value 1')";
76
- const expectedAst = parseSelectSQL(sql, 'redshift').where;
77
- expect(ast).toEqual(expectedAst);
78
- });
79
- it('should convert Filter to AST for string field - IsExactly (Snowflake)', () => {
80
- const filter = {
81
- field: 'field',
82
- name: FilterNames.StringFilter,
83
- type: FieldTypes.String,
84
- operator: StringOperator.IsExactly,
85
- value: 'value 1',
86
- };
87
- const ast = filterToAst(filter, 'snowflake');
88
- const sql = "SELECT * FROM t WHERE LOWER(field) = LOWER('value 1')";
89
- const expectedAst = parseSelectSQL(sql, 'snowflake').where;
90
- expect(ast).toEqual(expectedAst);
91
- });
92
- it('should convert Filter to AST for string field - IsExactly (Bigquery)', () => {
93
- const filter = {
94
- field: 'field',
95
- name: FilterNames.StringFilter,
96
- type: FieldTypes.String,
97
- operator: StringOperator.IsExactly,
98
- value: 'value 1',
99
- };
100
- const ast = filterToAst(filter, 'bigquery');
101
- const sql = "SELECT * FROM t WHERE LOWER(field) = LOWER('value 1')";
102
- const expectedAst = parseSelectSQL(sql, 'bigquery').where;
103
- expect(ast).toEqual(expectedAst);
104
- });
105
- it('should convert Filter to AST for string field - IsExactly (PostgresQL)', () => {
106
- const filter = {
107
- field: 'field',
108
- name: FilterNames.StringFilter,
109
- type: FieldTypes.String,
110
- operator: StringOperator.IsExactly,
111
- value: 'value 1',
112
- };
113
- const ast = filterToAst(filter, 'postgresql');
114
- const sql = "SELECT * FROM t WHERE LOWER(field) = LOWER('value 1')";
115
- const expectedAst = parseSelectSQL(sql, 'postgresql').where;
116
- expect(ast).toEqual(expectedAst);
117
- });
118
- it('should convert Filter to AST for string field - IsExactly (MySQL)', () => {
119
- const filter = {
120
- field: 'field',
121
- name: FilterNames.StringFilter,
122
- type: FieldTypes.String,
123
- operator: StringOperator.IsExactly,
124
- value: 'value 1',
125
- };
126
- const ast = filterToAst(filter, 'mysql');
127
- const sql = "SELECT * FROM t WHERE LOWER(field) = LOWER('value 1')";
128
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
129
- expect(ast).toEqual(expectedAst);
130
- });
131
- it('should convert Filter to AST for string field - IsNotExactly (Redshift)', () => {
132
- const filter = {
133
- field: 'field',
134
- name: FilterNames.StringFilter,
135
- type: FieldTypes.String,
136
- operator: StringOperator.IsNotExactly,
137
- value: 'value 1',
138
- };
139
- const ast = filterToAst(filter, 'redshift');
140
- const sql = "SELECT * FROM t WHERE LOWER(field) <> LOWER('value 1')";
141
- const expectedAst = parseSelectSQL(sql, 'redshift').where;
142
- expect(ast).toEqual(expectedAst);
143
- });
144
- it('should convert Filter to AST for string field - IsNotExactly (Snowflake)', () => {
145
- const filter = {
146
- field: 'field',
147
- name: FilterNames.StringFilter,
148
- type: FieldTypes.String,
149
- operator: StringOperator.IsNotExactly,
150
- value: 'value 1',
151
- };
152
- const ast = filterToAst(filter, 'snowflake');
153
- const sql = "SELECT * FROM t WHERE LOWER(field) <> LOWER('value 1')";
154
- const expectedAst = parseSelectSQL(sql, 'snowflake').where;
155
- expect(ast).toEqual(expectedAst);
156
- });
157
- it('should convert Filter to AST for string field - IsNotExactly (BigQuery)', () => {
158
- const filter = {
159
- field: 'field',
160
- name: FilterNames.StringFilter,
161
- type: FieldTypes.String,
162
- operator: StringOperator.IsNotExactly,
163
- value: 'value 1',
164
- };
165
- const ast = filterToAst(filter, 'bigquery');
166
- const sql = "SELECT * FROM t WHERE LOWER(field) <> LOWER('value 1')";
167
- const expectedAst = parseSelectSQL(sql, 'bigquery').where;
168
- expect(ast).toEqual(expectedAst);
169
- });
170
- it('should convert Filter to AST for string field - IsNotExactly (PostgresQL)', () => {
171
- const filter = {
172
- field: 'field',
173
- name: FilterNames.StringFilter,
174
- type: FieldTypes.String,
175
- operator: StringOperator.IsNotExactly,
176
- value: 'value 1',
177
- };
178
- const ast = filterToAst(filter, 'postgresql');
179
- const sql = "SELECT * FROM t WHERE LOWER(field) <> LOWER('value 1')";
180
- const expectedAst = parseSelectSQL(sql, 'postgresql').where;
181
- expect(ast).toEqual(expectedAst);
182
- });
183
- it('should convert Filter to AST for string field - IsNotExactly (MySQL)', () => {
184
- const filter = {
185
- field: 'field',
186
- name: FilterNames.StringFilter,
187
- type: FieldTypes.String,
188
- operator: StringOperator.IsNotExactly,
189
- value: 'value 1',
190
- };
191
- const ast = filterToAst(filter, 'mysql');
192
- const sql = "SELECT * FROM t WHERE LOWER(field) <> LOWER('value 1')";
193
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
194
- expect(ast).toEqual(expectedAst);
195
- });
196
- it('should convert Filter to AST for string field - Contains (Redshift)', () => {
197
- const filter = {
198
- field: 'field',
199
- name: FilterNames.StringFilter,
200
- type: FieldTypes.String,
201
- operator: StringOperator.Contains,
202
- value: 'value 1',
203
- };
204
- const ast = filterToAst(filter, 'redshift');
205
- const sql = "SELECT * FROM t WHERE LOWER(field) LIKE LOWER('%value 1%')";
206
- const expectedAst = parseSelectSQL(sql, 'redshift').where;
207
- expect(ast).toEqual(expectedAst);
208
- });
209
- it('should convert Filter to AST for string field - Contains (Snowflake)', () => {
210
- const filter = {
211
- field: 'field',
212
- name: FilterNames.StringFilter,
213
- type: FieldTypes.String,
214
- operator: StringOperator.Contains,
215
- value: 'value 1',
216
- };
217
- const ast = filterToAst(filter, 'snowflake');
218
- const sql = "SELECT * FROM t WHERE LOWER(field) LIKE LOWER('%value 1%')";
219
- const expectedAst = parseSelectSQL(sql, 'snowflake').where;
220
- expect(ast).toEqual(expectedAst);
221
- });
222
- it('should convert Filter to AST for string field - Contains (BigQuery)', () => {
223
- const filter = {
224
- field: 'field',
225
- name: FilterNames.StringFilter,
226
- type: FieldTypes.String,
227
- operator: StringOperator.Contains,
228
- value: 'value 1',
229
- };
230
- const ast = filterToAst(filter, 'bigquery');
231
- const sql = "SELECT * FROM t WHERE LOWER(field) LIKE LOWER('%value 1%')";
232
- const expectedAst = parseSelectSQL(sql, 'bigquery').where;
233
- expect(ast).toEqual(expectedAst);
234
- });
235
- it('should convert Filter to AST for string field - Contains (PostgresQL)', () => {
236
- const filter = {
237
- field: 'field',
238
- name: FilterNames.StringFilter,
239
- type: FieldTypes.String,
240
- operator: StringOperator.Contains,
241
- value: 'value 1',
242
- };
243
- const ast = filterToAst(filter, 'postgresql');
244
- const sql = "SELECT * FROM t WHERE LOWER(field) LIKE LOWER('%value 1%')";
245
- const expectedAst = parseSelectSQL(sql, 'postgresql').where;
246
- expect(ast).toEqual(expectedAst);
247
- });
248
- it('should convert Filter to AST for string field - Contains (MySQL)', () => {
249
- const filter = {
250
- field: 'field',
251
- name: FilterNames.StringFilter,
252
- type: FieldTypes.String,
253
- operator: StringOperator.Contains,
254
- value: 'value 1',
255
- };
256
- const ast = filterToAst(filter, 'mysql');
257
- const sql = "SELECT * FROM t WHERE LOWER(field) LIKE LOWER('%value 1%')";
258
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
259
- expect(ast).toEqual(expectedAst);
260
- });
261
- });
262
- describe('AST to Filter - String', () => {
263
- it('should convert AST to Filter for string field - Is', () => {
264
- const sql = "SELECT * FROM t WHERE LOWER(field) IN (LOWER('value 1'), LOWER('value 2'))";
265
- const ast = parseSelectSQL(sql);
266
- const filter = astToFilter(ast.where, 'mysql');
267
- const expectedFilter = {
268
- field: 'field',
269
- name: FilterNames.StringInFilter,
270
- type: FieldTypes.String,
271
- operator: StringOperator.Is,
272
- value: ['value 1', 'value 2'],
273
- };
274
- expect(filter).toEqual(expectedFilter);
275
- });
276
- it('should convert AST to Filter for string field - IsNot', () => {
277
- const sql = "SELECT * FROM t WHERE LOWER(field) NOT IN (LOWER('value 1'), LOWER('value 2'))";
278
- const ast = parseSelectSQL(sql);
279
- const filter = astToFilter(ast.where, 'mysql');
280
- const expectedFilter = {
281
- field: 'field',
282
- name: FilterNames.StringInFilter,
283
- type: FieldTypes.String,
284
- operator: StringOperator.IsNot,
285
- value: ['value 1', 'value 2'],
286
- };
287
- expect(filter).toEqual(expectedFilter);
288
- });
289
- it('should convert AST to Filter for string field - IsNull', () => {
290
- const sql = 'SELECT * FROM t WHERE field IS NULL';
291
- const ast = parseSelectSQL(sql);
292
- const filter = astToFilter(ast.where, 'mysql');
293
- const expectedFilter = {
294
- field: 'field',
295
- name: FilterNames.NullFilter,
296
- type: FieldTypes.Null,
297
- operator: NullOperator.IsNull,
298
- value: null,
299
- };
300
- expect(filter).toEqual(expectedFilter);
301
- });
302
- it('should convert AST to Filter for string field - IsNotNull', () => {
303
- const sql = 'SELECT * FROM t WHERE field IS NOT NULL';
304
- const ast = parseSelectSQL(sql);
305
- const filter = astToFilter(ast.where, 'mysql');
306
- const expectedFilter = {
307
- field: 'field',
308
- name: FilterNames.NullFilter,
309
- type: FieldTypes.Null,
310
- operator: NullOperator.IsNotNull,
311
- value: null,
312
- };
313
- expect(filter).toEqual(expectedFilter);
314
- });
315
- it('should convert AST to Filter for string field - IsExactly', () => {
316
- const sql = "SELECT * FROM t WHERE field = 'value 1'";
317
- const ast = parseSelectSQL(sql);
318
- const filter = astToFilter(ast.where, 'mysql');
319
- const expectedFilter = {
320
- field: 'field',
321
- name: FilterNames.StringFilter,
322
- type: FieldTypes.String,
323
- operator: StringOperator.IsExactly,
324
- value: 'value 1',
325
- };
326
- expect(filter).toEqual(expectedFilter);
327
- });
328
- it('should convert AST to Filter for string field - IsNotExactly', () => {
329
- const sql = "SELECT * FROM t WHERE field <> 'value 1'";
330
- const ast = parseSelectSQL(sql);
331
- const filter = astToFilter(ast.where, 'mysql');
332
- const expectedFilter = {
333
- field: 'field',
334
- name: FilterNames.StringFilter,
335
- type: FieldTypes.String,
336
- operator: StringOperator.IsNotExactly,
337
- value: 'value 1',
338
- };
339
- expect(filter).toEqual(expectedFilter);
340
- });
341
- it('should convert AST to Filter for string field - Contains', () => {
342
- const sql = "SELECT * FROM t WHERE field LIKE '%value 1%'";
343
- const ast = parseSelectSQL(sql);
344
- const filter = astToFilter(ast.where, 'mysql');
345
- const expectedFilter = {
346
- field: 'field',
347
- name: FilterNames.StringFilter,
348
- type: FieldTypes.String,
349
- operator: StringOperator.Contains,
350
- value: 'value 1',
351
- };
352
- expect(filter).toEqual(expectedFilter);
353
- });
354
- });
355
- describe('Filter to AST - Numeric', () => {
356
- it('should convert Filter to AST for numeric field - EqualTo', () => {
357
- const filter = {
358
- field: 'field',
359
- name: FilterNames.NumericFilter,
360
- type: FieldTypes.Numeric,
361
- operator: NumberOperator.EqualTo,
362
- value: 123,
363
- };
364
- const ast = filterToAst(filter, 'mysql');
365
- const sql = 'SELECT * FROM t WHERE field = 123';
366
- const expectedAst = parseSelectSQL(sql).where;
367
- expect(ast).toEqual(expectedAst);
368
- });
369
- it('should convert Filter to AST for numeric field - NotEqualTo', () => {
370
- const filter = {
371
- field: 'field',
372
- name: FilterNames.NumericFilter,
373
- type: FieldTypes.Numeric,
374
- operator: NumberOperator.NotEqualTo,
375
- value: 123,
376
- };
377
- const ast = filterToAst(filter, 'mysql');
378
- const sql = 'SELECT * FROM t WHERE field <> 123';
379
- const expectedAst = parseSelectSQL(sql).where;
380
- expect(ast).toEqual(expectedAst);
381
- });
382
- it('should convert Filter to AST for numeric field - GreaterThan', () => {
383
- const filter = {
384
- field: 'field',
385
- name: FilterNames.NumericFilter,
386
- type: FieldTypes.Numeric,
387
- operator: NumberOperator.GreaterThan,
388
- value: 123,
389
- };
390
- const ast = filterToAst(filter, 'mysql');
391
- const sql = 'SELECT * FROM t WHERE field > 123';
392
- const expectedAst = parseSelectSQL(sql).where;
393
- expect(ast).toEqual(expectedAst);
394
- });
395
- it('should convert Filter to AST for numeric field - LessThan', () => {
396
- const filter = {
397
- field: 'field',
398
- name: FilterNames.NumericFilter,
399
- type: FieldTypes.Numeric,
400
- operator: NumberOperator.LessThan,
401
- value: 123,
402
- };
403
- const ast = filterToAst(filter, 'mysql');
404
- const sql = 'SELECT * FROM t WHERE field < 123';
405
- const expectedAst = parseSelectSQL(sql).where;
406
- expect(ast).toEqual(expectedAst);
407
- });
408
- it('should convert Filter to AST for numeric field - GreaterThanOrEqualTo', () => {
409
- const filter = {
410
- field: 'field',
411
- name: FilterNames.NumericFilter,
412
- type: FieldTypes.Numeric,
413
- operator: NumberOperator.GreaterThanOrEqualTo,
414
- value: 123,
415
- };
416
- const ast = filterToAst(filter, 'mysql');
417
- const sql = 'SELECT * FROM t WHERE field >= 123';
418
- const expectedAst = parseSelectSQL(sql).where;
419
- expect(ast).toEqual(expectedAst);
420
- });
421
- it('should convert Filter to AST for numeric field - LessThanOrEqualTo', () => {
422
- const filter = {
423
- field: 'field',
424
- name: FilterNames.NumericFilter,
425
- type: FieldTypes.Numeric,
426
- operator: NumberOperator.LessThanOrEqualTo,
427
- value: 123,
428
- };
429
- const ast = filterToAst(filter, 'mysql');
430
- const sql = 'SELECT * FROM t WHERE field <= 123';
431
- const expectedAst = parseSelectSQL(sql).where;
432
- expect(ast).toEqual(expectedAst);
433
- });
434
- it('should convert Filter to AST for numeric field - IsNull', () => {
435
- const filter = {
436
- field: 'field',
437
- name: FilterNames.NullFilter,
438
- type: FieldTypes.Null,
439
- operator: NullOperator.IsNull,
440
- value: null,
441
- };
442
- const ast = filterToAst(filter, 'mysql');
443
- const sql = 'SELECT * FROM t WHERE field IS NULL';
444
- const expectedAst = parseSelectSQL(sql).where;
445
- expect(ast).toEqual(expectedAst);
446
- });
447
- it('should convert Filter to AST for numeric field - IsNotNull', () => {
448
- const filter = {
449
- field: 'field',
450
- name: FilterNames.NullFilter,
451
- type: FieldTypes.Null,
452
- operator: NullOperator.IsNotNull,
453
- value: null,
454
- };
455
- const ast = filterToAst(filter, 'mysql');
456
- const sql = 'SELECT * FROM t WHERE field IS NOT NULL';
457
- const expectedAst = parseSelectSQL(sql).where;
458
- expect(ast).toEqual(expectedAst);
459
- });
460
- });
461
- describe('AST to Filter - Numeric', () => {
462
- it('should convert AST to Filter for numeric field - EqualTo', () => {
463
- const sql = 'SELECT * FROM t WHERE field = 123';
464
- const ast = parseSelectSQL(sql);
465
- const filter = astToFilter(ast.where, 'mysql');
466
- const expectedFilter = {
467
- field: 'field',
468
- name: FilterNames.NumericFilter,
469
- type: FieldTypes.Numeric,
470
- operator: NumberOperator.EqualTo,
471
- value: 123,
472
- };
473
- expect(filter).toEqual(expectedFilter);
474
- });
475
- it('should convert AST to Filter for numeric field - NotEqualTo', () => {
476
- const sql = 'SELECT * FROM t WHERE field <> 123';
477
- const ast = parseSelectSQL(sql);
478
- const filter = astToFilter(ast.where, 'mysql');
479
- const expectedFilter = {
480
- field: 'field',
481
- name: FilterNames.NumericFilter,
482
- type: FieldTypes.Numeric,
483
- operator: NumberOperator.NotEqualTo,
484
- value: 123,
485
- };
486
- expect(filter).toEqual(expectedFilter);
487
- });
488
- it('should convert AST to Filter for numeric field - GreaterThan', () => {
489
- const sql = 'SELECT * FROM t WHERE field > 123';
490
- const ast = parseSelectSQL(sql);
491
- const filter = astToFilter(ast.where, 'mysql');
492
- const expectedFilter = {
493
- field: 'field',
494
- name: FilterNames.NumericFilter,
495
- type: FieldTypes.Numeric,
496
- operator: NumberOperator.GreaterThan,
497
- value: 123,
498
- };
499
- expect(filter).toEqual(expectedFilter);
500
- });
501
- it('should convert AST to Filter for numeric field - LessThan', () => {
502
- const sql = 'SELECT * FROM t WHERE field < 123';
503
- const ast = parseSelectSQL(sql);
504
- const filter = astToFilter(ast.where, 'mysql');
505
- const expectedFilter = {
506
- field: 'field',
507
- name: FilterNames.NumericFilter,
508
- type: FieldTypes.Numeric,
509
- operator: NumberOperator.LessThan,
510
- value: 123,
511
- };
512
- expect(filter).toEqual(expectedFilter);
513
- });
514
- it('should convert AST to Filter for numeric field - GreaterThanOrEqualTo', () => {
515
- const sql = 'SELECT * FROM t WHERE field >= 123';
516
- const ast = parseSelectSQL(sql);
517
- const filter = astToFilter(ast.where, 'mysql');
518
- const expectedFilter = {
519
- field: 'field',
520
- name: FilterNames.NumericFilter,
521
- type: FieldTypes.Numeric,
522
- operator: NumberOperator.GreaterThanOrEqualTo,
523
- value: 123,
524
- };
525
- expect(filter).toEqual(expectedFilter);
526
- });
527
- it('should convert AST to Filter for numeric field - LessThanOrEqualTo', () => {
528
- const sql = 'SELECT * FROM t WHERE field <= 123';
529
- const ast = parseSelectSQL(sql);
530
- const filter = astToFilter(ast.where, 'mysql');
531
- const expectedFilter = {
532
- field: 'field',
533
- name: FilterNames.NumericFilter,
534
- type: FieldTypes.Numeric,
535
- operator: NumberOperator.LessThanOrEqualTo,
536
- value: 123,
537
- };
538
- expect(filter).toEqual(expectedFilter);
539
- });
540
- it('should convert AST to Filter for numeric field - IsNotNull', () => {
541
- const sql = 'SELECT * FROM t WHERE field IS NOT NULL';
542
- const ast = parseSelectSQL(sql);
543
- const filter = astToFilter(ast.where, 'mysql');
544
- const expectedFilter = {
545
- field: 'field',
546
- name: FilterNames.NullFilter,
547
- type: FieldTypes.Null,
548
- operator: NullOperator.IsNotNull,
549
- value: null,
550
- };
551
- expect(filter).toEqual(expectedFilter);
552
- });
553
- it('should convert AST to Filter for numeric field - IsNull', () => {
554
- const sql = 'SELECT * FROM t WHERE field IS NULL';
555
- const ast = parseSelectSQL(sql);
556
- const filter = astToFilter(ast.where, 'mysql');
557
- const expectedFilter = {
558
- field: 'field',
559
- name: FilterNames.NullFilter,
560
- type: FieldTypes.Null,
561
- operator: NullOperator.IsNull,
562
- value: null,
563
- };
564
- expect(filter).toEqual(expectedFilter);
565
- });
566
- });
567
- describe('Filter to AST - Date (Custom)', () => {
568
- it('should convert Filter to AST for date field - Custom', () => {
569
- const filter = {
570
- field: 'date_field',
571
- name: FilterNames.DateCustomFilter,
572
- type: FieldTypes.Date,
573
- operator: DateOperator.Custom,
574
- value: {
575
- startDate: '2024-05-12',
576
- endDate: '2024-06-11',
577
- },
578
- };
579
- const ast = filterToAst(filter, 'mysql');
580
- const sql = "SELECT * FROM t WHERE date_field BETWEEN '2024-05-12' AND '2024-06-11'";
581
- const expectedAst = parseSelectSQL(sql).where;
582
- expect(ast).toEqual(expectedAst);
583
- });
584
- });
585
- describe('AST to Filter - Date (Custom)', () => {
586
- it('should convert AST to Filter for date field - Custom', () => {
587
- const sql = "SELECT * FROM t WHERE date_field BETWEEN '2024-05-12' AND '2024-06-11'";
588
- const ast = parseSelectSQL(sql);
589
- const filter = astToFilter(ast.where, 'mysql');
590
- const expectedFilter = {
591
- field: 'date_field',
592
- name: FilterNames.DateCustomFilter,
593
- type: FieldTypes.Date,
594
- operator: DateOperator.Custom,
595
- value: {
596
- startDate: '2024-05-12',
597
- endDate: '2024-06-11',
598
- },
599
- };
600
- expect(filter).toEqual(expectedFilter);
601
- });
602
- });
603
- describe('Filter to AST - Date (InTheLast', () => {
604
- it('should convert Filter to AST for date field - InTheLast (Redshift)', () => {
605
- const filter = {
606
- field: 'transaction_date',
607
- name: FilterNames.DateFilter,
608
- type: FieldTypes.Date,
609
- operator: DateOperator.InTheLast,
610
- value: {
611
- value: 90,
612
- unit: TimeUnit.Day,
613
- },
614
- };
615
- const ast = filterToAst(filter, 'redshift');
616
- const sql = `
617
- SELECT *
618
- FROM transactions
619
- WHERE transaction_date >= DATEADD(day, -90, CURRENT_DATE)
620
- `
621
- .replace(/\s+/g, ' ')
622
- .trim();
623
- const expectedAst = parseSelectSQL(sql, 'redshift').where;
624
- expect(ast).toEqual(expectedAst);
625
- });
626
- it('should convert Filter to AST for date field - InTheLast (Snowflake)', () => {
627
- const filter = {
628
- field: 'transaction_date',
629
- name: FilterNames.DateFilter,
630
- type: FieldTypes.Date,
631
- operator: DateOperator.InTheLast,
632
- value: {
633
- value: 90,
634
- unit: TimeUnit.Day,
635
- },
636
- };
637
- const ast = filterToAst(filter, 'snowflake');
638
- const sql = `
639
- SELECT *
640
- FROM transactions
641
- WHERE transaction_date >= CURRENT_DATE() - INTERVAL '90 DAY'
642
- `
643
- .replace(/\s+/g, ' ')
644
- .trim();
645
- const expectedAst = parseSelectSQL(sql, 'snowflake').where;
646
- expect(ast).toEqual(expectedAst);
647
- });
648
- it('should convert Filter to AST for date field - InTheLast (BigQuery)', () => {
649
- const filter = {
650
- field: 'transaction_date',
651
- name: FilterNames.DateFilter,
652
- type: FieldTypes.Date,
653
- operator: DateOperator.InTheLast,
654
- value: {
655
- value: 90,
656
- unit: TimeUnit.Day,
657
- },
658
- };
659
- const ast = filterToAst(filter, 'bigquery');
660
- const sql = `
661
- SELECT *
662
- FROM transactions
663
- WHERE transaction_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
664
- `
665
- .replace(/\s+/g, ' ')
666
- .trim();
667
- const expectedAst = parseSelectSQL(sql, 'bigquery').where;
668
- expect(ast).toEqual(expectedAst);
669
- });
670
- it('should convert Filter to AST for date field - InTheLast (MySQL)', () => {
671
- const filter = {
672
- field: 'transaction_date',
673
- name: FilterNames.DateFilter,
674
- type: FieldTypes.Date,
675
- operator: DateOperator.InTheLast,
676
- value: {
677
- value: 1,
678
- unit: TimeUnit.Month,
679
- },
680
- };
681
- const ast = filterToAst(filter, 'mysql');
682
- const sql = `
683
- SELECT *
684
- FROM transactions
685
- WHERE transaction_date >= CURDATE() - INTERVAL 1 MONTH
686
- `
687
- .replace(/\s+/g, ' ')
688
- .trim();
689
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
690
- expect(ast).toEqual(expectedAst);
691
- });
692
- it('should convert Filter to AST for date field - InTheLast (Postgres)', () => {
693
- const filter = {
694
- field: 'transaction_date',
695
- name: FilterNames.DateFilter,
696
- type: FieldTypes.Date,
697
- operator: DateOperator.InTheLast,
698
- value: {
699
- value: 30,
700
- unit: TimeUnit.Month,
701
- },
702
- };
703
- const ast = filterToAst(filter, 'postgresql');
704
- const sql = `
705
- SELECT *
706
- FROM transactions
707
- WHERE transaction_date >= CURRENT_DATE - INTERVAL '30 months'
708
- `
709
- .replace(/\s+/g, ' ')
710
- .trim();
711
- const expectedAst = parseSelectSQL(sql, 'postgresql').where;
712
- expect(ast).toEqual(expectedAst);
713
- });
714
- });
715
- describe('AST to Filter - Date (InTheLast)', () => {
716
- it('should convert AST to Filter for date field (Redshift-1) - InTheLast', () => {
717
- const sql = `
718
- SELECT * FROM transactions
719
- WHERE transaction_date >= DATEADD(day, -90, CURRENT_DATE)
720
- `
721
- .replace(/\s+/g, ' ')
722
- .trim();
723
- const ast = parseSelectSQL(sql, 'redshift');
724
- const filter = astToFilter(ast.where, 'redshift');
725
- const expectedFilter = {
726
- field: 'transaction_date',
727
- name: FilterNames.DateFilter,
728
- type: FieldTypes.Date,
729
- operator: DateOperator.InTheLast,
730
- value: {
731
- value: 90,
732
- unit: TimeUnit.Day,
733
- },
734
- };
735
- expect(filter).toEqual(expectedFilter);
736
- });
737
- it('should convert AST to Filter for date field (Redshift-2) - InTheLast', () => {
738
- const sql = `
739
- SELECT * FROM transactions
740
- WHERE transaction_date >= DATEADD(day, -90, GETDATE())
741
- `
742
- .replace(/\s+/g, ' ')
743
- .trim();
744
- const ast = parseSelectSQL(sql, 'redshift');
745
- const filter = astToFilter(ast.where, 'redshift');
746
- const expectedFilter = {
747
- field: 'transaction_date',
748
- name: FilterNames.DateFilter,
749
- type: FieldTypes.Date,
750
- operator: DateOperator.InTheLast,
751
- value: {
752
- value: 90,
753
- unit: TimeUnit.Day,
754
- },
755
- };
756
- expect(filter).toEqual(expectedFilter);
757
- });
758
- it('should convert AST to Filter for date field (Snowflake-1) - InTheLast', () => {
759
- const sql = `
760
- SELECT * FROM transactions
761
- WHERE transaction_date >= CURRENT_DATE() - INTERVAL '1 YEAR'
762
- `
763
- .replace(/\s+/g, ' ')
764
- .trim();
765
- const ast = parseSelectSQL(sql, 'snowflake');
766
- const filter = astToFilter(ast.where, 'snowflake');
767
- const expectedFilter = {
768
- field: 'transaction_date',
769
- name: FilterNames.DateFilter,
770
- type: FieldTypes.Date,
771
- operator: DateOperator.InTheLast,
772
- value: {
773
- value: 1,
774
- unit: TimeUnit.Year,
775
- },
776
- };
777
- expect(filter).toEqual(expectedFilter);
778
- });
779
- it('should convert AST to Filter for date field (Snowflake-2) - InTheLast', () => {
780
- const sql = `
781
- SELECT * FROM transactions
782
- WHERE transaction_date >= DATEADD(YEAR, -1, CURRENT_DATE())
783
- `
784
- .replace(/\s+/g, ' ')
785
- .trim();
786
- const ast = parseSelectSQL(sql, 'snowflake');
787
- const filter = astToFilter(ast.where, 'snowflake');
788
- const expectedFilter = {
789
- field: 'transaction_date',
790
- name: FilterNames.DateFilter,
791
- type: FieldTypes.Date,
792
- operator: DateOperator.InTheLast,
793
- value: {
794
- value: 1,
795
- unit: TimeUnit.Year,
796
- },
797
- };
798
- expect(filter).toEqual(expectedFilter);
799
- });
800
- it('should convert AST to Filter for date field (BigQuery) - InTheLast', () => {
801
- const sql = `
802
- SELECT * FROM transactions
803
- WHERE transaction_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
804
- `
805
- .replace(/\s+/g, ' ')
806
- .trim();
807
- const ast = parseSelectSQL(sql, 'bigquery');
808
- const filter = astToFilter(ast.where, 'bigquery');
809
- const expectedFilter = {
810
- field: 'transaction_date',
811
- name: FilterNames.DateFilter,
812
- type: FieldTypes.Date,
813
- operator: DateOperator.InTheLast,
814
- value: {
815
- value: 90,
816
- unit: TimeUnit.Day,
817
- },
818
- };
819
- expect(filter).toEqual(expectedFilter);
820
- });
821
- it('should convert AST to Filter for date field (MySQL-1) - InTheLast', () => {
822
- const sql = `
823
- SELECT * FROM transactions
824
- WHERE transaction_date >= CURDATE() - INTERVAL 1 MONTH
825
- `
826
- .replace(/\s+/g, ' ')
827
- .trim();
828
- const ast = parseSelectSQL(sql, 'mysql');
829
- const filter = astToFilter(ast.where, 'mysql');
830
- const expectedFilter = {
831
- field: 'transaction_date',
832
- name: FilterNames.DateFilter,
833
- type: FieldTypes.Date,
834
- operator: DateOperator.InTheLast,
835
- value: {
836
- value: 1,
837
- unit: TimeUnit.Month,
838
- },
839
- };
840
- expect(filter).toEqual(expectedFilter);
841
- });
842
- it('should convert AST to Filter for date field (MySQL-2) - InTheLast', () => {
843
- const sql = `
844
- SELECT * FROM transactions
845
- WHERE transaction_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
846
- `
847
- .replace(/\s+/g, ' ')
848
- .trim();
849
- const ast = parseSelectSQL(sql, 'mysql');
850
- const filter = astToFilter(ast.where, 'mysql');
851
- const expectedFilter = {
852
- field: 'transaction_date',
853
- name: FilterNames.DateFilter,
854
- type: FieldTypes.Date,
855
- operator: DateOperator.InTheLast,
856
- value: {
857
- value: 1,
858
- unit: TimeUnit.Month,
859
- },
860
- };
861
- expect(filter).toEqual(expectedFilter);
862
- });
863
- it('should convert AST to Filter for date field (MySQL-3) - InTheLast', () => {
864
- const sql = `
865
- SELECT * FROM transactions
866
- WHERE transaction_date >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
867
- `
868
- .replace(/\s+/g, ' ')
869
- .trim();
870
- const ast = parseSelectSQL(sql, 'mysql');
871
- const filter = astToFilter(ast.where, 'mysql');
872
- const expectedFilter = {
873
- field: 'transaction_date',
874
- name: FilterNames.DateFilter,
875
- type: FieldTypes.Date,
876
- operator: DateOperator.InTheLast,
877
- value: {
878
- value: 1,
879
- unit: TimeUnit.Month,
880
- },
881
- };
882
- expect(filter).toEqual(expectedFilter);
883
- });
884
- it('should convert AST to Filter for date field (Postgres) - InTheLast', () => {
885
- const sql = `
886
- SELECT * FROM transactions
887
- WHERE transaction_date >= CURRENT_DATE - INTERVAL 1 month
888
- `
889
- .replace(/\s+/g, ' ')
890
- .trim();
891
- const ast = parseSelectSQL(sql, 'postgresql');
892
- const filter = astToFilter(ast.where, 'postgresql');
893
- const expectedFilter = {
894
- field: 'transaction_date',
895
- name: FilterNames.DateFilter,
896
- type: FieldTypes.Date,
897
- operator: DateOperator.InTheLast,
898
- value: {
899
- value: 1,
900
- unit: TimeUnit.Month,
901
- },
902
- };
903
- expect(filter).toEqual(expectedFilter);
904
- });
905
- });
906
- describe('Filter to AST - Date (InTheCurrent', () => {
907
- it('should convert Filter to AST for date field - InTheCurrent Year (Redshift)', () => {
908
- const filter = {
909
- field: 'transaction_date',
910
- name: FilterNames.DateFilter,
911
- type: FieldTypes.Date,
912
- operator: DateOperator.InTheCurrent,
913
- value: {
914
- value: 0,
915
- unit: TimeUnit.Year,
916
- },
917
- };
918
- const ast = filterToAst(filter, 'redshift');
919
- const sql = `
920
- SELECT * FROM transactions
921
- WHERE transaction_date >= DATE_TRUNC('year', CURRENT_DATE)
922
- AND transaction_date < (DATE_TRUNC('year', CURRENT_DATE) + INTERVAL '1 year')
923
- `
924
- .replace(/\s+/g, ' ')
925
- .trim();
926
- const expectedAst = parseSelectSQL(sql, 'redshift').where;
927
- expect(ast).toEqual(expectedAst);
928
- });
929
- it('should convert Filter to AST for date field - InTheCurrent Year (Snowflake)', () => {
930
- const filter = {
931
- field: 'transaction_date',
932
- name: FilterNames.DateFilter,
933
- type: FieldTypes.Date,
934
- operator: DateOperator.InTheCurrent,
935
- value: {
936
- value: 0,
937
- unit: TimeUnit.Year,
938
- },
939
- };
940
- const ast = filterToAst(filter, 'snowflake');
941
- const sql = `
942
- SELECT * FROM transactions
943
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
944
- `
945
- .replace(/\s+/g, ' ')
946
- .trim();
947
- const expectedAst = parseSelectSQL(sql, 'snowflake').where;
948
- expect(ast).toEqual(expectedAst);
949
- });
950
- it('should convert Filter to AST for date field - InTheCurrent Year (BigQuery)', () => {
951
- const filter = {
952
- field: 'transaction_date',
953
- name: FilterNames.DateFilter,
954
- type: FieldTypes.Date,
955
- operator: DateOperator.InTheCurrent,
956
- value: {
957
- value: 0,
958
- unit: TimeUnit.Year,
959
- },
960
- };
961
- const ast = filterToAst(filter, 'bigquery');
962
- const sql = `
963
- SELECT * FROM transactions
964
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE())
965
- `
966
- .replace(/\s+/g, ' ')
967
- .trim();
968
- const expectedAst = parseSelectSQL(sql, 'bigquery').where;
969
- expect(ast).toEqual(expectedAst);
970
- });
971
- it('should convert Filter to AST for date field - InTheCurrent Year (MySQL)', () => {
972
- const filter = {
973
- field: 'transaction_date',
974
- name: FilterNames.DateFilter,
975
- type: FieldTypes.Date,
976
- operator: DateOperator.InTheCurrent,
977
- value: {
978
- value: 0,
979
- unit: TimeUnit.Year,
980
- },
981
- };
982
- const ast = filterToAst(filter, 'mysql');
983
- const sql = `
984
- SELECT * FROM transactions
985
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
986
- `
987
- .replace(/\s+/g, ' ')
988
- .trim();
989
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
990
- expect(ast).toEqual(expectedAst);
991
- });
992
- it('should convert Filter to AST for date field - InTheCurrent Year (Postgres)', () => {
993
- const filter = {
994
- field: 'transaction_date',
995
- name: FilterNames.DateFilter,
996
- type: FieldTypes.Date,
997
- operator: DateOperator.InTheCurrent,
998
- value: {
999
- value: 0,
1000
- unit: TimeUnit.Year,
1001
- },
1002
- };
1003
- const ast = filterToAst(filter, 'postgresql');
1004
- const sql = `
1005
- SELECT * FROM transactions
1006
- WHERE DATE_TRUNC('year', transaction_date) = DATE_TRUNC('year', CURRENT_DATE)
1007
- `
1008
- .replace(/\s+/g, ' ')
1009
- .trim();
1010
- const expectedAst = parseSelectSQL(sql, 'postgresql').where;
1011
- expect(ast).toEqual(expectedAst);
1012
- });
1013
- it('should convert Filter to AST for date field - InTheCurrent Quarter (Redshift)', () => {
1014
- const filter = {
1015
- field: 'transaction_date',
1016
- name: FilterNames.DateFilter,
1017
- type: FieldTypes.Date,
1018
- operator: DateOperator.InTheCurrent,
1019
- value: {
1020
- value: 0,
1021
- unit: TimeUnit.Quarter,
1022
- },
1023
- };
1024
- const ast = filterToAst(filter, 'redshift');
1025
- const sql = `
1026
- SELECT * FROM transactions
1027
- WHERE transaction_date >= DATE_TRUNC('quarter', CURRENT_DATE)
1028
- AND transaction_date < (DATE_TRUNC('quarter', CURRENT_DATE) + INTERVAL '1 quarter')
1029
- `
1030
- .replace(/\s+/g, ' ')
1031
- .trim();
1032
- const expectedAst = parseSelectSQL(sql, 'redshift').where;
1033
- expect(ast).toEqual(expectedAst);
1034
- });
1035
- it('should convert Filter to AST for date field - InTheCurrent Quarter (Snowflake)', () => {
1036
- const filter = {
1037
- field: 'transaction_date',
1038
- name: FilterNames.DateFilter,
1039
- type: FieldTypes.Date,
1040
- operator: DateOperator.InTheCurrent,
1041
- value: {
1042
- value: 0,
1043
- unit: TimeUnit.Quarter,
1044
- },
1045
- };
1046
- const ast = filterToAst(filter, 'snowflake');
1047
- const sql = `
1048
- SELECT * FROM transactions
1049
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1050
- AND QUARTER(transaction_date) = QUARTER(CURRENT_DATE())
1051
- `
1052
- .replace(/\s+/g, ' ')
1053
- .trim();
1054
- const expectedAst = parseSelectSQL(sql, 'snowflake').where;
1055
- expect(ast).toEqual(expectedAst);
1056
- });
1057
- it('should convert Filter to AST for date field - InTheCurrent Quarter (BigQuery)', () => {
1058
- const filter = {
1059
- field: 'transaction_date',
1060
- name: FilterNames.DateFilter,
1061
- type: FieldTypes.Date,
1062
- operator: DateOperator.InTheCurrent,
1063
- value: {
1064
- value: 0,
1065
- unit: TimeUnit.Quarter,
1066
- },
1067
- };
1068
- const ast = filterToAst(filter, 'bigquery');
1069
- const sql = `
1070
- SELECT * FROM transactions
1071
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE())
1072
- AND EXTRACT(QUARTER FROM transaction_date) = EXTRACT(QUARTER FROM CURRENT_DATE())
1073
- `
1074
- .replace(/\s+/g, ' ')
1075
- .trim();
1076
- const expectedAst = parseSelectSQL(sql, 'bigquery').where;
1077
- expect(ast).toEqual(expectedAst);
1078
- });
1079
- it('should convert Filter to AST for date field - InTheCurrent Quarter (MySQL)', () => {
1080
- const filter = {
1081
- field: 'transaction_date',
1082
- name: FilterNames.DateFilter,
1083
- type: FieldTypes.Date,
1084
- operator: DateOperator.InTheCurrent,
1085
- value: {
1086
- value: 0,
1087
- unit: TimeUnit.Quarter,
1088
- },
1089
- };
1090
- const ast = filterToAst(filter, 'mysql');
1091
- const sql = `
1092
- SELECT * FROM transactions
1093
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1094
- AND QUARTER(transaction_date) = QUARTER(CURRENT_DATE())
1095
- `
1096
- .replace(/\s+/g, ' ')
1097
- .trim();
1098
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
1099
- expect(ast).toEqual(expectedAst);
1100
- });
1101
- it('should convert Filter to AST for date field - InTheCurrent Month (Postgres)', () => {
1102
- const filter = {
1103
- field: 'transaction_date',
1104
- name: FilterNames.DateFilter,
1105
- type: FieldTypes.Date,
1106
- operator: DateOperator.InTheCurrent,
1107
- value: {
1108
- value: 0,
1109
- unit: TimeUnit.Quarter,
1110
- },
1111
- };
1112
- const ast = filterToAst(filter, 'postgresql');
1113
- const sql = `
1114
- SELECT * FROM transactions
1115
- WHERE DATE_TRUNC('quarter', transaction_date) = DATE_TRUNC('quarter', CURRENT_DATE)
1116
- `
1117
- .replace(/\s+/g, ' ')
1118
- .trim();
1119
- const expectedAst = parseSelectSQL(sql, 'postgresql').where;
1120
- expect(ast).toEqual(expectedAst);
1121
- });
1122
- it('should convert Filter to AST for date field - InTheCurrent Month (Redshift)', () => {
1123
- const filter = {
1124
- field: 'transaction_date',
1125
- name: FilterNames.DateFilter,
1126
- type: FieldTypes.Date,
1127
- operator: DateOperator.InTheCurrent,
1128
- value: {
1129
- value: 0,
1130
- unit: TimeUnit.Month,
1131
- },
1132
- };
1133
- const ast = filterToAst(filter, 'redshift');
1134
- const sql = `
1135
- SELECT * FROM transactions
1136
- WHERE transaction_date >= DATE_TRUNC('month', CURRENT_DATE)
1137
- AND transaction_date < (DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month')
1138
- `
1139
- .replace(/\s+/g, ' ')
1140
- .trim();
1141
- const expectedAst = parseSelectSQL(sql, 'redshift').where;
1142
- expect(ast).toEqual(expectedAst);
1143
- });
1144
- it('should convert Filter to AST for date field - InTheCurrent Month (Snowflake)', () => {
1145
- const filter = {
1146
- field: 'transaction_date',
1147
- name: FilterNames.DateFilter,
1148
- type: FieldTypes.Date,
1149
- operator: DateOperator.InTheCurrent,
1150
- value: {
1151
- value: 0,
1152
- unit: TimeUnit.Month,
1153
- },
1154
- };
1155
- const ast = filterToAst(filter, 'snowflake');
1156
- const sql = `
1157
- SELECT * FROM transactions
1158
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1159
- AND MONTH(transaction_date) = MONTH(CURRENT_DATE())
1160
- `
1161
- .replace(/\s+/g, ' ')
1162
- .trim();
1163
- const expectedAst = parseSelectSQL(sql, 'snowflake').where;
1164
- expect(ast).toEqual(expectedAst);
1165
- });
1166
- it('should convert Filter to AST for date field - InTheCurrent Month (BigQuery)', () => {
1167
- const filter = {
1168
- field: 'transaction_date',
1169
- name: FilterNames.DateFilter,
1170
- type: FieldTypes.Date,
1171
- operator: DateOperator.InTheCurrent,
1172
- value: {
1173
- value: 0,
1174
- unit: TimeUnit.Month,
1175
- },
1176
- };
1177
- const ast = filterToAst(filter, 'bigquery');
1178
- const sql = `
1179
- SELECT * FROM transactions
1180
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE())
1181
- AND EXTRACT(MONTH FROM transaction_date) = EXTRACT(MONTH FROM CURRENT_DATE())
1182
- `
1183
- .replace(/\s+/g, ' ')
1184
- .trim();
1185
- const expectedAst = parseSelectSQL(sql, 'bigquery').where;
1186
- expect(ast).toEqual(expectedAst);
1187
- });
1188
- it('should convert Filter to AST for date field - InTheCurrent Month (MySQL)', () => {
1189
- const filter = {
1190
- field: 'transaction_date',
1191
- name: FilterNames.DateFilter,
1192
- type: FieldTypes.Date,
1193
- operator: DateOperator.InTheCurrent,
1194
- value: {
1195
- value: 0,
1196
- unit: TimeUnit.Month,
1197
- },
1198
- };
1199
- const ast = filterToAst(filter, 'mysql');
1200
- const sql = `
1201
- SELECT * FROM transactions
1202
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1203
- AND MONTH(transaction_date) = MONTH(CURRENT_DATE())
1204
- `
1205
- .replace(/\s+/g, ' ')
1206
- .trim();
1207
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
1208
- expect(ast).toEqual(expectedAst);
1209
- });
1210
- it('should convert Filter to AST for date field - InTheCurrent Month (Postgres)', () => {
1211
- const filter = {
1212
- field: 'transaction_date',
1213
- name: FilterNames.DateFilter,
1214
- type: FieldTypes.Date,
1215
- operator: DateOperator.InTheCurrent,
1216
- value: {
1217
- value: 0,
1218
- unit: TimeUnit.Month,
1219
- },
1220
- };
1221
- const ast = filterToAst(filter, 'postgresql');
1222
- const sql = `
1223
- SELECT * FROM transactions
1224
- WHERE DATE_TRUNC('month', transaction_date) = DATE_TRUNC('month', CURRENT_DATE)
1225
- `
1226
- .replace(/\s+/g, ' ')
1227
- .trim();
1228
- const expectedAst = parseSelectSQL(sql, 'postgresql').where;
1229
- expect(ast).toEqual(expectedAst);
1230
- });
1231
- it('should convert Filter to AST for date field - InTheCurrent Week (Redshift)', () => {
1232
- const filter = {
1233
- field: 'transaction_date',
1234
- name: FilterNames.DateFilter,
1235
- type: FieldTypes.Date,
1236
- operator: DateOperator.InTheCurrent,
1237
- value: {
1238
- value: 0,
1239
- unit: TimeUnit.Week,
1240
- },
1241
- };
1242
- const ast = filterToAst(filter, 'redshift');
1243
- const sql = `
1244
- SELECT * FROM transactions
1245
- WHERE transaction_date >= DATE_TRUNC('week', CURRENT_DATE)
1246
- AND transaction_date < (DATE_TRUNC('week', CURRENT_DATE) + INTERVAL '1 week')
1247
- `
1248
- .replace(/\s+/g, ' ')
1249
- .trim();
1250
- const expectedAst = parseSelectSQL(sql, 'redshift').where;
1251
- expect(ast).toEqual(expectedAst);
1252
- });
1253
- it('should convert Filter to AST for date field - InTheCurrent Week (Snowflake)', () => {
1254
- const filter = {
1255
- field: 'transaction_date',
1256
- name: FilterNames.DateFilter,
1257
- type: FieldTypes.Date,
1258
- operator: DateOperator.InTheCurrent,
1259
- value: {
1260
- value: 0,
1261
- unit: TimeUnit.Week,
1262
- },
1263
- };
1264
- const ast = filterToAst(filter, 'snowflake');
1265
- const sql = `
1266
- SELECT * FROM transactions
1267
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1268
- AND MONTH(transaction_date) = MONTH(CURRENT_DATE())
1269
- AND WEEK(transaction_date) = WEEK(CURRENT_DATE())
1270
- `
1271
- .replace(/\s+/g, ' ')
1272
- .trim();
1273
- const expectedAst = parseSelectSQL(sql, 'snowflake').where;
1274
- expect(ast).toEqual(expectedAst);
1275
- });
1276
- it('should convert Filter to AST for date field - InTheCurrent Week (BigQuery)', () => {
1277
- const filter = {
1278
- field: 'transaction_date',
1279
- name: FilterNames.DateFilter,
1280
- type: FieldTypes.Date,
1281
- operator: DateOperator.InTheCurrent,
1282
- value: {
1283
- value: 0,
1284
- unit: TimeUnit.Week,
1285
- },
1286
- };
1287
- const ast = filterToAst(filter, 'bigquery');
1288
- const sql = `
1289
- SELECT * FROM transactions
1290
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE())
1291
- AND EXTRACT(MONTH FROM transaction_date) = EXTRACT(MONTH FROM CURRENT_DATE())
1292
- AND EXTRACT(WEEK FROM transaction_date) = EXTRACT(WEEK FROM CURRENT_DATE())
1293
- `
1294
- .replace(/\s+/g, ' ')
1295
- .trim();
1296
- const expectedAst = parseSelectSQL(sql, 'bigquery').where;
1297
- expect(ast).toEqual(expectedAst);
1298
- });
1299
- it('should convert Filter to AST for date field - InTheCurrent Week (MySQL)', () => {
1300
- const filter = {
1301
- field: 'transaction_date',
1302
- name: FilterNames.DateFilter,
1303
- type: FieldTypes.Date,
1304
- operator: DateOperator.InTheCurrent,
1305
- value: {
1306
- value: 0,
1307
- unit: TimeUnit.Week,
1308
- },
1309
- };
1310
- const ast = filterToAst(filter, 'mysql');
1311
- const sql = `
1312
- SELECT * FROM transactions
1313
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1314
- AND MONTH(transaction_date) = MONTH(CURRENT_DATE())
1315
- AND WEEK(transaction_date) = WEEK(CURRENT_DATE())
1316
- `
1317
- .replace(/\s+/g, ' ')
1318
- .trim();
1319
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
1320
- expect(ast).toEqual(expectedAst);
1321
- });
1322
- it('should convert Filter to AST for date field - InTheCurrent Week (Postgres)', () => {
1323
- const filter = {
1324
- field: 'transaction_date',
1325
- name: FilterNames.DateFilter,
1326
- type: FieldTypes.Date,
1327
- operator: DateOperator.InTheCurrent,
1328
- value: {
1329
- value: 0,
1330
- unit: TimeUnit.Week,
1331
- },
1332
- };
1333
- const ast = filterToAst(filter, 'postgresql');
1334
- const sql = `
1335
- SELECT * FROM transactions
1336
- WHERE DATE_TRUNC('week', transaction_date) = DATE_TRUNC('week', CURRENT_DATE)
1337
- `
1338
- .replace(/\s+/g, ' ')
1339
- .trim();
1340
- const expectedAst = parseSelectSQL(sql, 'postgresql').where;
1341
- expect(ast).toEqual(expectedAst);
1342
- });
1343
- it('should convert Filter to AST for date field - InTheCurrent Day (Redshift)', () => {
1344
- const filter = {
1345
- field: 'transaction_date',
1346
- name: FilterNames.DateFilter,
1347
- type: FieldTypes.Date,
1348
- operator: DateOperator.InTheCurrent,
1349
- value: {
1350
- value: 0,
1351
- unit: TimeUnit.Day,
1352
- },
1353
- };
1354
- const ast = filterToAst(filter, 'redshift');
1355
- const sql = `
1356
- SELECT * FROM transactions
1357
- WHERE transaction_date >= DATE_TRUNC('day', CURRENT_DATE)
1358
- AND transaction_date < (DATE_TRUNC('day', CURRENT_DATE) + INTERVAL '1 day')
1359
- `
1360
- .replace(/\s+/g, ' ')
1361
- .trim();
1362
- const expectedAst = parseSelectSQL(sql, 'redshift').where;
1363
- expect(ast).toEqual(expectedAst);
1364
- });
1365
- it('should convert Filter to AST for date field - InTheCurrent Day (Snowflake)', () => {
1366
- const filter = {
1367
- field: 'transaction_date',
1368
- name: FilterNames.DateFilter,
1369
- type: FieldTypes.Date,
1370
- operator: DateOperator.InTheCurrent,
1371
- value: {
1372
- value: 0,
1373
- unit: TimeUnit.Day,
1374
- },
1375
- };
1376
- const ast = filterToAst(filter, 'snowflake');
1377
- const sql = `
1378
- SELECT * FROM transactions
1379
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1380
- AND MONTH(transaction_date) = MONTH(CURRENT_DATE())
1381
- AND DAY(transaction_date) = DAY(CURRENT_DATE())
1382
- `
1383
- .replace(/\s+/g, ' ')
1384
- .trim();
1385
- const expectedAst = parseSelectSQL(sql, 'snowflake').where;
1386
- expect(ast).toEqual(expectedAst);
1387
- });
1388
- it('should convert Filter to AST for date field - InTheCurrent Day (BigQuery)', () => {
1389
- const filter = {
1390
- field: 'transaction_date',
1391
- name: FilterNames.DateFilter,
1392
- type: FieldTypes.Date,
1393
- operator: DateOperator.InTheCurrent,
1394
- value: {
1395
- value: 0,
1396
- unit: TimeUnit.Day,
1397
- },
1398
- };
1399
- const ast = filterToAst(filter, 'bigquery');
1400
- const sql = `
1401
- SELECT * FROM transactions
1402
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE())
1403
- AND EXTRACT(MONTH FROM transaction_date) = EXTRACT(MONTH FROM CURRENT_DATE())
1404
- AND EXTRACT(DAY FROM transaction_date) = EXTRACT(DAY FROM CURRENT_DATE())
1405
- `
1406
- .replace(/\s+/g, ' ')
1407
- .trim();
1408
- const expectedAst = parseSelectSQL(sql, 'bigquery').where;
1409
- expect(ast).toEqual(expectedAst);
1410
- });
1411
- it('should convert Filter to AST for date field - InTheCurrent Day (MySQL)', () => {
1412
- const filter = {
1413
- field: 'transaction_date',
1414
- name: FilterNames.DateFilter,
1415
- type: FieldTypes.Date,
1416
- operator: DateOperator.InTheCurrent,
1417
- value: {
1418
- value: 0,
1419
- unit: TimeUnit.Day,
1420
- },
1421
- };
1422
- const ast = filterToAst(filter, 'mysql');
1423
- const sql = `
1424
- SELECT * FROM transactions
1425
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1426
- AND MONTH(transaction_date) = MONTH(CURRENT_DATE())
1427
- AND DAY(transaction_date) = DAY(CURRENT_DATE())
1428
- `
1429
- .replace(/\s+/g, ' ')
1430
- .trim();
1431
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
1432
- expect(ast).toEqual(expectedAst);
1433
- });
1434
- it('should convert Filter to AST for date field - InTheCurrent Day (Postgres)', () => {
1435
- const filter = {
1436
- field: 'transaction_date',
1437
- name: FilterNames.DateFilter,
1438
- type: FieldTypes.Date,
1439
- operator: DateOperator.InTheCurrent,
1440
- value: {
1441
- value: 0,
1442
- unit: TimeUnit.Day,
1443
- },
1444
- };
1445
- const ast = filterToAst(filter, 'postgresql');
1446
- const sql = `
1447
- SELECT * FROM transactions
1448
- WHERE DATE_TRUNC('day', transaction_date) = DATE_TRUNC('day', CURRENT_DATE)
1449
- `
1450
- .replace(/\s+/g, ' ')
1451
- .trim();
1452
- const expectedAst = parseSelectSQL(sql, 'postgresql').where;
1453
- expect(ast).toEqual(expectedAst);
1454
- });
1455
- it('should convert Filter to AST for date field - InTheCurrent Hour (Redshift)', () => {
1456
- const filter = {
1457
- field: 'transaction_date',
1458
- name: FilterNames.DateFilter,
1459
- type: FieldTypes.Date,
1460
- operator: DateOperator.InTheCurrent,
1461
- value: {
1462
- value: 0,
1463
- unit: TimeUnit.Hour,
1464
- },
1465
- };
1466
- const ast = filterToAst(filter, 'redshift');
1467
- const sql = `
1468
- SELECT * FROM transactions
1469
- WHERE transaction_date >= DATE_TRUNC('hour', CURRENT_TIMESTAMP)
1470
- AND transaction_date < (DATE_TRUNC('hour', CURRENT_TIMESTAMP) + INTERVAL '1 hour')
1471
- `
1472
- .replace(/\s+/g, ' ')
1473
- .trim();
1474
- const expectedAst = parseSelectSQL(sql, 'redshift').where;
1475
- expect(ast).toEqual(expectedAst);
1476
- });
1477
- it('should convert Filter to AST for date field - InTheCurrent Hour (Snowflake)', () => {
1478
- const filter = {
1479
- field: 'transaction_date',
1480
- name: FilterNames.DateFilter,
1481
- type: FieldTypes.Date,
1482
- operator: DateOperator.InTheCurrent,
1483
- value: {
1484
- value: 0,
1485
- unit: TimeUnit.Hour,
1486
- },
1487
- };
1488
- const ast = filterToAst(filter, 'snowflake');
1489
- const sql = `
1490
- SELECT * FROM transactions
1491
- WHERE YEAR(transaction_date) = YEAR(CURRENT_TIMESTAMP())
1492
- AND MONTH(transaction_date) = MONTH(CURRENT_TIMESTAMP())
1493
- AND DAY(transaction_date) = DAY(CURRENT_TIMESTAMP())
1494
- AND HOUR(transaction_date) = HOUR(CURRENT_TIMESTAMP())
1495
- `
1496
- .replace(/\s+/g, ' ')
1497
- .trim();
1498
- const expectedAst = parseSelectSQL(sql, 'snowflake').where;
1499
- expect(ast).toEqual(expectedAst);
1500
- });
1501
- it('should convert Filter to AST for date field - InTheCurrent Hour (BigQuery)', () => {
1502
- const filter = {
1503
- field: 'transaction_date',
1504
- name: FilterNames.DateFilter,
1505
- type: FieldTypes.Date,
1506
- operator: DateOperator.InTheCurrent,
1507
- value: {
1508
- value: 0,
1509
- unit: TimeUnit.Hour,
1510
- },
1511
- };
1512
- const ast = filterToAst(filter, 'bigquery');
1513
- const sql = `
1514
- SELECT * FROM transactions
1515
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_TIMESTAMP())
1516
- AND EXTRACT(MONTH FROM transaction_date) = EXTRACT(MONTH FROM CURRENT_TIMESTAMP())
1517
- AND EXTRACT(DAY FROM transaction_date) = EXTRACT(DAY FROM CURRENT_TIMESTAMP())
1518
- AND EXTRACT(HOUR FROM transaction_date) = EXTRACT(HOUR FROM CURRENT_TIMESTAMP())
1519
- `
1520
- .replace(/\s+/g, ' ')
1521
- .trim();
1522
- const expectedAst = parseSelectSQL(sql, 'bigquery').where;
1523
- expect(ast).toEqual(expectedAst);
1524
- });
1525
- it('should convert Filter to AST for date field - InTheCurrent Hour (MySQL)', () => {
1526
- const filter = {
1527
- field: 'transaction_date',
1528
- name: FilterNames.DateFilter,
1529
- type: FieldTypes.Date,
1530
- operator: DateOperator.InTheCurrent,
1531
- value: {
1532
- value: 0,
1533
- unit: TimeUnit.Hour,
1534
- },
1535
- };
1536
- const ast = filterToAst(filter, 'mysql');
1537
- const sql = `
1538
- SELECT * FROM transactions
1539
- WHERE YEAR(transaction_date) = YEAR(CURRENT_TIMESTAMP())
1540
- AND MONTH(transaction_date) = MONTH(CURRENT_TIMESTAMP())
1541
- AND DAY(transaction_date) = DAY(CURRENT_TIMESTAMP())
1542
- AND HOUR(transaction_date) = HOUR(CURRENT_TIMESTAMP())
1543
- `
1544
- .replace(/\s+/g, ' ')
1545
- .trim();
1546
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
1547
- expect(ast).toEqual(expectedAst);
1548
- });
1549
- it('should convert Filter to AST for date field - InTheCurrent Hour (Postgres)', () => {
1550
- const filter = {
1551
- field: 'transaction_date',
1552
- name: FilterNames.DateFilter,
1553
- type: FieldTypes.Date,
1554
- operator: DateOperator.InTheCurrent,
1555
- value: {
1556
- value: 0,
1557
- unit: TimeUnit.Hour,
1558
- },
1559
- };
1560
- const ast = filterToAst(filter, 'postgresql');
1561
- const sql = `
1562
- SELECT * FROM transactions
1563
- WHERE DATE_TRUNC('hour', transaction_date) = DATE_TRUNC('hour', CURRENT_TIMESTAMP)
1564
- `
1565
- .replace(/\s+/g, ' ')
1566
- .trim();
1567
- const expectedAst = parseSelectSQL(sql, 'postgresql').where;
1568
- expect(ast).toEqual(expectedAst);
1569
- });
1570
- });
1571
- describe('AST to Filter - Date (InTheCurrent)', () => {
1572
- it('should convert AST to Filter for date field (Redshift-1) - InTheCurrent', () => {
1573
- const sql = `
1574
- SELECT * FROM transactions
1575
- WHERE EXTRACT(MONTH FROM transaction_date) = EXTRACT(MONTH FROM CURRENT_DATE)
1576
- AND EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE)
1577
- `
1578
- .replace(/\s+/g, ' ')
1579
- .trim();
1580
- const ast = parseSelectSQL(sql, 'redshift');
1581
- const filter = astToFilter(ast.where, 'redshift');
1582
- const expectedFilter = {
1583
- field: 'transaction_date',
1584
- name: FilterNames.DateFilter,
1585
- type: FieldTypes.Date,
1586
- operator: DateOperator.InTheCurrent,
1587
- value: {
1588
- value: 0,
1589
- unit: TimeUnit.Month,
1590
- },
1591
- };
1592
- expect(filter).toEqual(expectedFilter);
1593
- });
1594
- it('should convert AST to Filter for date field (Redshift-2) - InTheCurrent', () => {
1595
- const sql = `
1596
- SELECT * FROM transactions
1597
- WHERE transaction_date >= DATE_TRUNC('month', CURRENT_DATE)
1598
- AND transaction_date < (DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month')
1599
- `
1600
- .replace(/\s+/g, ' ')
1601
- .trim();
1602
- const ast = parseSelectSQL(sql, 'redshift');
1603
- const filter = astToFilter(ast.where, 'redshift');
1604
- const expectedFilter = {
1605
- field: 'transaction_date',
1606
- name: FilterNames.DateFilter,
1607
- type: FieldTypes.Date,
1608
- operator: DateOperator.InTheCurrent,
1609
- value: {
1610
- value: 0,
1611
- unit: TimeUnit.Month,
1612
- },
1613
- };
1614
- expect(filter).toEqual(expectedFilter);
1615
- });
1616
- it('should convert AST to Filter for date field (Redshift-3) - InTheCurrent', () => {
1617
- const sql = `
1618
- SELECT * FROM transactions
1619
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE)
1620
- `
1621
- .replace(/\s+/g, ' ')
1622
- .trim();
1623
- const ast = parseSelectSQL(sql, 'redshift');
1624
- const filter = astToFilter(ast.where, 'redshift');
1625
- const expectedFilter = {
1626
- field: 'transaction_date',
1627
- name: FilterNames.DateFilter,
1628
- type: FieldTypes.Date,
1629
- operator: DateOperator.InTheCurrent,
1630
- value: {
1631
- value: 0,
1632
- unit: TimeUnit.Year,
1633
- },
1634
- };
1635
- expect(filter).toEqual(expectedFilter);
1636
- });
1637
- it('should convert AST to Filter for date field (Redshift-4) - InTheCurrent', () => {
1638
- const sql = `
1639
- SELECT * FROM transactions
1640
- WHERE EXTRACT(DAY FROM transaction_date) = EXTRACT(DAY FROM CURRENT_DATE)
1641
- AND EXTRACT(MONTH FROM transaction_date) = EXTRACT(MONTH FROM CURRENT_DATE)
1642
- AND EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE)
1643
- `
1644
- .replace(/\s+/g, ' ')
1645
- .trim();
1646
- const ast = parseSelectSQL(sql, 'redshift');
1647
- const filter = astToFilter(ast.where, 'redshift');
1648
- const expectedFilter = {
1649
- field: 'transaction_date',
1650
- name: FilterNames.DateFilter,
1651
- type: FieldTypes.Date,
1652
- operator: DateOperator.InTheCurrent,
1653
- value: {
1654
- value: 0,
1655
- unit: TimeUnit.Day,
1656
- },
1657
- };
1658
- expect(filter).toEqual(expectedFilter);
1659
- });
1660
- it('should convert AST to Filter for date field (Redshift-5) - InTheCurrent', () => {
1661
- const sql = `
1662
- SELECT * FROM transactions
1663
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE)
1664
- AND EXTRACT(DAY FROM transaction_date) = EXTRACT(DAY FROM CURRENT_DATE)
1665
- AND EXTRACT(MONTH FROM transaction_date) = EXTRACT(MONTH FROM CURRENT_DATE)
1666
- `
1667
- .replace(/\s+/g, ' ')
1668
- .trim();
1669
- const ast = parseSelectSQL(sql, 'redshift');
1670
- const filter = astToFilter(ast.where, 'redshift');
1671
- const expectedFilter = {
1672
- field: 'transaction_date',
1673
- name: FilterNames.DateFilter,
1674
- type: FieldTypes.Date,
1675
- operator: DateOperator.InTheCurrent,
1676
- value: {
1677
- value: 0,
1678
- unit: TimeUnit.Day,
1679
- },
1680
- };
1681
- expect(filter).toEqual(expectedFilter);
1682
- });
1683
- it('should convert AST to Filter for date field (Snowflake-1) - InTheCurrent', () => {
1684
- const sql = `
1685
- SELECT * FROM transactions
1686
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1687
- AND MONTH(transaction_date) = MONTH(CURRENT_DATE())
1688
- `
1689
- .replace(/\s+/g, ' ')
1690
- .trim();
1691
- const ast = parseSelectSQL(sql, 'snowflake');
1692
- const filter = astToFilter(ast.where, 'snowflake');
1693
- const expectedFilter = {
1694
- field: 'transaction_date',
1695
- name: FilterNames.DateFilter,
1696
- type: FieldTypes.Date,
1697
- operator: DateOperator.InTheCurrent,
1698
- value: {
1699
- value: 0,
1700
- unit: TimeUnit.Month,
1701
- },
1702
- };
1703
- expect(filter).toEqual(expectedFilter);
1704
- });
1705
- it('should convert AST to Filter for date field (Snowflake-2) - InTheCurrent', () => {
1706
- const sql = `
1707
- SELECT * FROM transactions
1708
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE())
1709
- AND EXTRACT(MONTH FROM transaction_date) = EXTRACT(MONTH FROM CURRENT_DATE())
1710
- `
1711
- .replace(/\s+/g, ' ')
1712
- .trim();
1713
- const ast = parseSelectSQL(sql, 'snowflake');
1714
- const filter = astToFilter(ast.where, 'snowflake');
1715
- const expectedFilter = {
1716
- field: 'transaction_date',
1717
- name: FilterNames.DateFilter,
1718
- type: FieldTypes.Date,
1719
- operator: DateOperator.InTheCurrent,
1720
- value: {
1721
- value: 0,
1722
- unit: TimeUnit.Month,
1723
- },
1724
- };
1725
- expect(filter).toEqual(expectedFilter);
1726
- });
1727
- it('should convert AST to Filter for date field (Snowflake-3) - InTheCurrent', () => {
1728
- const sql = `
1729
- SELECT * FROM transactions
1730
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE())
1731
- `
1732
- .replace(/\s+/g, ' ')
1733
- .trim();
1734
- const ast = parseSelectSQL(sql, 'snowflake');
1735
- const filter = astToFilter(ast.where, 'snowflake');
1736
- const expectedFilter = {
1737
- field: 'transaction_date',
1738
- name: FilterNames.DateFilter,
1739
- type: FieldTypes.Date,
1740
- operator: DateOperator.InTheCurrent,
1741
- value: {
1742
- value: 0,
1743
- unit: TimeUnit.Year,
1744
- },
1745
- };
1746
- expect(filter).toEqual(expectedFilter);
1747
- });
1748
- it('should convert AST to Filter for date field (Snowflake-4) - InTheCurrent', () => {
1749
- const sql = `
1750
- SELECT * FROM transactions
1751
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1752
- AND DAY(transaction_date) = DAY(CURRENT_DATE())
1753
- AND MONTH(transaction_date) = MONTH(CURRENT_DATE())
1754
- `
1755
- .replace(/\s+/g, ' ')
1756
- .trim();
1757
- const ast = parseSelectSQL(sql, 'snowflake');
1758
- const filter = astToFilter(ast.where, 'snowflake');
1759
- const expectedFilter = {
1760
- field: 'transaction_date',
1761
- name: FilterNames.DateFilter,
1762
- type: FieldTypes.Date,
1763
- operator: DateOperator.InTheCurrent,
1764
- value: {
1765
- value: 0,
1766
- unit: TimeUnit.Day,
1767
- },
1768
- };
1769
- expect(filter).toEqual(expectedFilter);
1770
- });
1771
- it('should convert AST to Filter for date field (Snowflake-5) - InTheCurrent', () => {
1772
- const sql = `
1773
- SELECT * FROM transactions
1774
- WHERE EXTRACT(DAY FROM transaction_date) = EXTRACT(DAY FROM CURRENT_DATE())
1775
- AND EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE())
1776
- AND EXTRACT(MONTH FROM transaction_date) = EXTRACT(MONTH FROM CURRENT_DATE())
1777
- `
1778
- .replace(/\s+/g, ' ')
1779
- .trim();
1780
- const ast = parseSelectSQL(sql, 'snowflake');
1781
- const filter = astToFilter(ast.where, 'snowflake');
1782
- const expectedFilter = {
1783
- field: 'transaction_date',
1784
- name: FilterNames.DateFilter,
1785
- type: FieldTypes.Date,
1786
- operator: DateOperator.InTheCurrent,
1787
- value: {
1788
- value: 0,
1789
- unit: TimeUnit.Day,
1790
- },
1791
- };
1792
- expect(filter).toEqual(expectedFilter);
1793
- });
1794
- it('should convert AST to Filter for date field (BigQuery-1) - InTheCurrent', () => {
1795
- const sql = `
1796
- SELECT * FROM transactions
1797
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE())
1798
- AND EXTRACT(MONTH FROM transaction_date) = EXTRACT(MONTH FROM CURRENT_DATE())
1799
- `
1800
- .replace(/\s+/g, ' ')
1801
- .trim();
1802
- const ast = parseSelectSQL(sql, 'bigquery');
1803
- const filter = astToFilter(ast.where, 'bigquery');
1804
- const expectedFilter = {
1805
- field: 'transaction_date',
1806
- name: FilterNames.DateFilter,
1807
- type: FieldTypes.Date,
1808
- operator: DateOperator.InTheCurrent,
1809
- value: {
1810
- value: 0,
1811
- unit: TimeUnit.Month,
1812
- },
1813
- };
1814
- expect(filter).toEqual(expectedFilter);
1815
- });
1816
- it('should convert AST to Filter for date field (BigQuery-2) - InTheCurrent', () => {
1817
- const sql = `
1818
- SELECT * FROM transactions
1819
- WHERE EXTRACT(YEAR FROM transaction_date) = EXTRACT(YEAR FROM CURRENT_DATE())
1820
- AND EXTRACT(DAY FROM transaction_date) = EXTRACT(DAY FROM CURRENT_DATE())
1821
- AND EXTRACT(MONTH FROM transaction_date) = EXTRACT(MONTH FROM CURRENT_DATE())
1822
- `
1823
- .replace(/\s+/g, ' ')
1824
- .trim();
1825
- const ast = parseSelectSQL(sql, 'bigquery');
1826
- const filter = astToFilter(ast.where, 'bigquery');
1827
- const expectedFilter = {
1828
- field: 'transaction_date',
1829
- name: FilterNames.DateFilter,
1830
- type: FieldTypes.Date,
1831
- operator: DateOperator.InTheCurrent,
1832
- value: {
1833
- value: 0,
1834
- unit: TimeUnit.Day,
1835
- },
1836
- };
1837
- expect(filter).toEqual(expectedFilter);
1838
- });
1839
- it('should convert AST to Filter for date field (MySQL-1) - InTheCurrent', () => {
1840
- const sql = `
1841
- SELECT * FROM transactions
1842
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1843
- AND MONTH(transaction_date) = MONTH(CURRENT_DATE())
1844
- `
1845
- .replace(/\s+/g, ' ')
1846
- .trim();
1847
- const ast = parseSelectSQL(sql, 'mysql');
1848
- const filter = astToFilter(ast.where, 'mysql');
1849
- const expectedFilter = {
1850
- field: 'transaction_date',
1851
- name: FilterNames.DateFilter,
1852
- type: FieldTypes.Date,
1853
- operator: DateOperator.InTheCurrent,
1854
- value: {
1855
- value: 0,
1856
- unit: TimeUnit.Month,
1857
- },
1858
- };
1859
- expect(filter).toEqual(expectedFilter);
1860
- });
1861
- it('should convert AST to Filter for date field (MySQL-2) - InTheCurrent', () => {
1862
- const sql = `
1863
- SELECT * FROM transactions
1864
- WHERE YEAR(transaction_date) = YEAR(CURDATE())
1865
- `
1866
- .replace(/\s+/g, ' ')
1867
- .trim();
1868
- const ast = parseSelectSQL(sql, 'mysql');
1869
- const filter = astToFilter(ast.where, 'mysql');
1870
- const expectedFilter = {
1871
- field: 'transaction_date',
1872
- name: FilterNames.DateFilter,
1873
- type: FieldTypes.Date,
1874
- operator: DateOperator.InTheCurrent,
1875
- value: {
1876
- value: 0,
1877
- unit: TimeUnit.Year,
1878
- },
1879
- };
1880
- expect(filter).toEqual(expectedFilter);
1881
- });
1882
- it('should convert AST to Filter for date field (MySQL-1) - InTheCurrent', () => {
1883
- const sql = `
1884
- SELECT * FROM transactions
1885
- WHERE YEAR(transaction_date) = YEAR(CURRENT_DATE())
1886
- AND DAY(transaction_date) = DAY(CURRENT_DATE())
1887
- AND MONTH(transaction_date) = MONTH(CURRENT_DATE())
1888
- `
1889
- .replace(/\s+/g, ' ')
1890
- .trim();
1891
- const ast = parseSelectSQL(sql, 'mysql');
1892
- const filter = astToFilter(ast.where, 'mysql');
1893
- const expectedFilter = {
1894
- field: 'transaction_date',
1895
- name: FilterNames.DateFilter,
1896
- type: FieldTypes.Date,
1897
- operator: DateOperator.InTheCurrent,
1898
- value: {
1899
- value: 0,
1900
- unit: TimeUnit.Day,
1901
- },
1902
- };
1903
- expect(filter).toEqual(expectedFilter);
1904
- });
1905
- it('should convert AST to Filter for date field (Postgres-1) - InTheCurrent', () => {
1906
- const sql = `
1907
- SELECT * FROM transactions
1908
- WHERE DATE_TRUNC('month', transaction_date) = DATE_TRUNC('month', CURRENT_DATE)
1909
- `
1910
- .replace(/\s+/g, ' ')
1911
- .trim();
1912
- const ast = parseSelectSQL(sql, 'postgresql');
1913
- const filter = astToFilter(ast.where, 'postgresql');
1914
- const expectedFilter = {
1915
- field: 'transaction_date',
1916
- name: FilterNames.DateFilter,
1917
- type: FieldTypes.Date,
1918
- operator: DateOperator.InTheCurrent,
1919
- value: {
1920
- value: 0,
1921
- unit: TimeUnit.Month,
1922
- },
1923
- };
1924
- expect(filter).toEqual(expectedFilter);
1925
- });
1926
- it('should convert AST to Filter for date field (Postgres-2) - InTheCurrent', () => {
1927
- const sql = `
1928
- SELECT * FROM transactions
1929
- WHERE created_at >= date_trunc('month', CURRENT_DATE)
1930
- AND created_at < (date_trunc('month', CURRENT_DATE) + INTERVAL '1 month')
1931
- `
1932
- .replace(/\s+/g, ' ')
1933
- .trim();
1934
- const ast = parseSelectSQL(sql, 'postgresql');
1935
- const filter = astToFilter(ast.where, 'postgresql');
1936
- const expectedFilter = {
1937
- field: 'created_at',
1938
- name: FilterNames.DateFilter,
1939
- type: FieldTypes.Date,
1940
- operator: DateOperator.InTheCurrent,
1941
- value: {
1942
- value: 0,
1943
- unit: TimeUnit.Month,
1944
- },
1945
- };
1946
- expect(filter).toEqual(expectedFilter);
1947
- });
1948
- });
1949
- describe('Filter to AST - Date (InThePrevious)', () => {
1950
- it('should convert Filter to AST for date field - InThePrevious (Redshift)', () => {
1951
- const filter = {
1952
- field: 'transaction_date',
1953
- name: FilterNames.DateFilter,
1954
- type: FieldTypes.Date,
1955
- operator: DateOperator.InThePrevious,
1956
- value: {
1957
- value: 100,
1958
- unit: TimeUnit.Month,
1959
- },
1960
- };
1961
- const ast = filterToAst(filter, 'redshift');
1962
- const sql = `
1963
- SELECT * FROM transactions
1964
- WHERE transaction_date >= DATEADD(month, -200, CURRENT_DATE)
1965
- AND transaction_date < DATEADD(month, -100, CURRENT_DATE)
1966
- `
1967
- .replace(/\s+/g, ' ')
1968
- .trim();
1969
- const expectedAst = parseSelectSQL(sql, 'redshift').where;
1970
- expect(ast).toEqual(expectedAst);
1971
- });
1972
- it('should convert Filter to AST for date field - InThePrevious (Snowflake)', () => {
1973
- const filter = {
1974
- field: 'transaction_date',
1975
- name: FilterNames.DateFilter,
1976
- type: FieldTypes.Date,
1977
- operator: DateOperator.InThePrevious,
1978
- value: {
1979
- value: 100,
1980
- unit: TimeUnit.Month,
1981
- },
1982
- };
1983
- const ast = filterToAst(filter, 'snowflake');
1984
- const sql = `
1985
- SELECT *
1986
- FROM transactions
1987
- WHERE transaction_date >= CURRENT_DATE() - INTERVAL '200 MONTHS'
1988
- AND transaction_date < CURRENT_DATE() - INTERVAL '100 MONTHS'
1989
- `
1990
- .replace(/\s+/g, ' ')
1991
- .trim();
1992
- const expectedAst = parseSelectSQL(sql, 'snowflake').where;
1993
- expect(ast).toEqual(expectedAst);
1994
- });
1995
- it('should convert Filter to AST for date field - InThePrevious (BigQuery)', () => {
1996
- const filter = {
1997
- field: 'transaction_date',
1998
- name: FilterNames.DateFilter,
1999
- type: FieldTypes.Date,
2000
- operator: DateOperator.InThePrevious,
2001
- value: {
2002
- value: 100,
2003
- unit: TimeUnit.Month,
2004
- },
2005
- };
2006
- const ast = filterToAst(filter, 'bigquery');
2007
- const sql = `
2008
- SELECT *
2009
- FROM transactions
2010
- WHERE transaction_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 200 MONTH)
2011
- AND transaction_date < DATE_SUB(CURRENT_DATE(), INTERVAL 100 MONTH)
2012
- `
2013
- .replace(/\s+/g, ' ')
2014
- .trim();
2015
- const expectedAst = parseSelectSQL(sql, 'bigquery').where;
2016
- expect(ast).toEqual(expectedAst);
2017
- });
2018
- it('should convert Filter to AST for date field - InThePrevious (MySQL)', () => {
2019
- const filter = {
2020
- field: 'transaction_date',
2021
- name: FilterNames.DateFilter,
2022
- type: FieldTypes.Date,
2023
- operator: DateOperator.InThePrevious,
2024
- value: {
2025
- value: 2,
2026
- unit: TimeUnit.Year,
2027
- },
2028
- };
2029
- const ast = filterToAst(filter, 'mysql');
2030
- const sql = `
2031
- SELECT *
2032
- FROM transactions
2033
- WHERE transaction_date >= CURDATE() - INTERVAL 4 YEAR
2034
- AND transaction_date < CURDATE() - INTERVAL 2 YEAR
2035
- `
2036
- .replace(/\s+/g, ' ')
2037
- .trim();
2038
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
2039
- expect(ast).toEqual(expectedAst);
2040
- });
2041
- it('should convert Filter to AST for date field - InThePrevious (Postgres)', () => {
2042
- const filter = {
2043
- field: 'transaction_date',
2044
- name: FilterNames.DateFilter,
2045
- type: FieldTypes.Date,
2046
- operator: DateOperator.InThePrevious,
2047
- value: {
2048
- value: 40,
2049
- unit: TimeUnit.Day,
2050
- },
2051
- };
2052
- const ast = filterToAst(filter, 'postgresql');
2053
- const sql = `
2054
- SELECT *
2055
- FROM transactions
2056
- WHERE transaction_date >= CURRENT_DATE - INTERVAL '80 days'
2057
- AND transaction_date < CURRENT_DATE - INTERVAL '40 days'
2058
- `
2059
- .replace(/\s+/g, ' ')
2060
- .trim();
2061
- const expectedAst = parseSelectSQL(sql, 'postgresql').where;
2062
- expect(ast).toEqual(expectedAst);
2063
- });
2064
- });
2065
- describe('AST to Filter - Date (InThePrevious)', () => {
2066
- it('should convert AST to Filter for date field (Redshift-1) - InThePrevious', () => {
2067
- const sql = `
2068
- SELECT * FROM transactions
2069
- WHERE transaction_date >= DATEADD(day, -180, CURRENT_DATE)
2070
- AND transaction_date < DATEADD(day, -90, CURRENT_DATE)
2071
- `
2072
- .replace(/\s+/g, ' ')
2073
- .trim();
2074
- const ast = parseSelectSQL(sql, 'redshift');
2075
- const filter = astToFilter(ast.where, 'redshift');
2076
- const expectedFilter = {
2077
- field: 'transaction_date',
2078
- name: FilterNames.DateFilter,
2079
- type: FieldTypes.Date,
2080
- operator: DateOperator.InThePrevious,
2081
- value: {
2082
- value: 90,
2083
- unit: TimeUnit.Day,
2084
- },
2085
- };
2086
- expect(filter).toEqual(expectedFilter);
2087
- });
2088
- it('should convert AST to Filter for date field (Redshift-2) - InThePrevious', () => {
2089
- const sql = `
2090
- SELECT * FROM transactions
2091
- WHERE transaction_date >= DATEADD(day, -180, GETDATE())
2092
- AND transaction_date < DATEADD(day, -90, GETDATE())
2093
- `
2094
- .replace(/\s+/g, ' ')
2095
- .trim();
2096
- const ast = parseSelectSQL(sql, 'redshift');
2097
- const filter = astToFilter(ast.where, 'redshift');
2098
- const expectedFilter = {
2099
- field: 'transaction_date',
2100
- name: FilterNames.DateFilter,
2101
- type: FieldTypes.Date,
2102
- operator: DateOperator.InThePrevious,
2103
- value: {
2104
- value: 90,
2105
- unit: TimeUnit.Day,
2106
- },
2107
- };
2108
- expect(filter).toEqual(expectedFilter);
2109
- });
2110
- it('should convert AST to Filter for date field (Snowflake-1) - InThePrevious', () => {
2111
- const sql = `
2112
- SELECT * FROM transactions
2113
- WHERE transaction_date >= CURRENT_DATE() - INTERVAL '2 YEARS'
2114
- AND transaction_date < CURRENT_DATE() - INTERVAL '1 YEAR'
2115
- `
2116
- .replace(/\s+/g, ' ')
2117
- .trim();
2118
- const ast = parseSelectSQL(sql, 'snowflake');
2119
- const filter = astToFilter(ast.where, 'snowflake');
2120
- const expectedFilter = {
2121
- field: 'transaction_date',
2122
- name: FilterNames.DateFilter,
2123
- type: FieldTypes.Date,
2124
- operator: DateOperator.InThePrevious,
2125
- value: {
2126
- value: 1,
2127
- unit: TimeUnit.Year,
2128
- },
2129
- };
2130
- expect(filter).toEqual(expectedFilter);
2131
- });
2132
- it('should convert AST to Filter for date field (Snowflake-2) - InThePrevious', () => {
2133
- const sql = `
2134
- SELECT * FROM transactions
2135
- WHERE transaction_date >= DATEADD(YEAR, -2, CURRENT_DATE())
2136
- AND transaction_date < DATEADD(YEAR, -1, CURRENT_DATE())
2137
- `
2138
- .replace(/\s+/g, ' ')
2139
- .trim();
2140
- const ast = parseSelectSQL(sql, 'snowflake');
2141
- const filter = astToFilter(ast.where, 'snowflake');
2142
- const expectedFilter = {
2143
- field: 'transaction_date',
2144
- name: FilterNames.DateFilter,
2145
- type: FieldTypes.Date,
2146
- operator: DateOperator.InThePrevious,
2147
- value: {
2148
- value: 1,
2149
- unit: TimeUnit.Year,
2150
- },
2151
- };
2152
- expect(filter).toEqual(expectedFilter);
2153
- });
2154
- it('should convert AST to Filter for date field (BigQuery) - InThePrevious', () => {
2155
- const sql = `
2156
- SELECT * FROM transactions
2157
- WHERE transaction_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 180 DAY)
2158
- AND transaction_date < DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
2159
- `
2160
- .replace(/\s+/g, ' ')
2161
- .trim();
2162
- const ast = parseSelectSQL(sql, 'bigquery');
2163
- const filter = astToFilter(ast.where, 'bigquery');
2164
- const expectedFilter = {
2165
- field: 'transaction_date',
2166
- name: FilterNames.DateFilter,
2167
- type: FieldTypes.Date,
2168
- operator: DateOperator.InThePrevious,
2169
- value: {
2170
- value: 90,
2171
- unit: TimeUnit.Day,
2172
- },
2173
- };
2174
- expect(filter).toEqual(expectedFilter);
2175
- });
2176
- it('should convert AST to Filter for date field (MySQL-1) - InThePrevious', () => {
2177
- const sql = `
2178
- SELECT * FROM transactions
2179
- WHERE transaction_date >= CURDATE() - INTERVAL 2 MONTH
2180
- AND transaction_date < CURDATE() - INTERVAL 1 MONTH
2181
- `
2182
- .replace(/\s+/g, ' ')
2183
- .trim();
2184
- const ast = parseSelectSQL(sql, 'mysql');
2185
- const filter = astToFilter(ast.where, 'mysql');
2186
- const expectedFilter = {
2187
- field: 'transaction_date',
2188
- name: FilterNames.DateFilter,
2189
- type: FieldTypes.Date,
2190
- operator: DateOperator.InThePrevious,
2191
- value: {
2192
- value: 1,
2193
- unit: TimeUnit.Month,
2194
- },
2195
- };
2196
- expect(filter).toEqual(expectedFilter);
2197
- });
2198
- it('should convert AST to Filter for date field (MySQL-2) - InThePrevious', () => {
2199
- const sql = `
2200
- SELECT * FROM transactions
2201
- WHERE transaction_date >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)
2202
- AND transaction_date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
2203
- `
2204
- .replace(/\s+/g, ' ')
2205
- .trim();
2206
- const ast = parseSelectSQL(sql, 'mysql');
2207
- const filter = astToFilter(ast.where, 'mysql');
2208
- const expectedFilter = {
2209
- field: 'transaction_date',
2210
- name: FilterNames.DateFilter,
2211
- type: FieldTypes.Date,
2212
- operator: DateOperator.InThePrevious,
2213
- value: {
2214
- value: 1,
2215
- unit: TimeUnit.Month,
2216
- },
2217
- };
2218
- expect(filter).toEqual(expectedFilter);
2219
- });
2220
- it('should convert AST to Filter for date field (MySQL-3) - InThePrevious', () => {
2221
- const sql = `
2222
- SELECT * FROM transactions
2223
- WHERE transaction_date >= DATE_SUB(NOW(), INTERVAL 2 MONTH)
2224
- AND transaction_date < DATE_SUB(NOW(), INTERVAL 1 MONTH)
2225
- `
2226
- .replace(/\s+/g, ' ')
2227
- .trim();
2228
- const ast = parseSelectSQL(sql, 'mysql');
2229
- const filter = astToFilter(ast.where, 'mysql');
2230
- const expectedFilter = {
2231
- field: 'transaction_date',
2232
- name: FilterNames.DateFilter,
2233
- type: FieldTypes.Date,
2234
- operator: DateOperator.InThePrevious,
2235
- value: {
2236
- value: 1,
2237
- unit: TimeUnit.Month,
2238
- },
2239
- };
2240
- expect(filter).toEqual(expectedFilter);
2241
- });
2242
- it('should convert AST to Filter for date field (Postgres) - InThePrevious', () => {
2243
- const sql = `
2244
- SELECT * FROM transactions
2245
- WHERE transaction_date >= CURRENT_DATE - INTERVAL 2 month
2246
- AND transaction_date < CURRENT_DATE - INTERVAL 1 month
2247
- `
2248
- .replace(/\s+/g, ' ')
2249
- .trim();
2250
- const ast = parseSelectSQL(sql, 'postgresql');
2251
- const filter = astToFilter(ast.where, 'postgresql');
2252
- const expectedFilter = {
2253
- field: 'transaction_date',
2254
- name: FilterNames.DateFilter,
2255
- type: FieldTypes.Date,
2256
- operator: DateOperator.InThePrevious,
2257
- value: {
2258
- value: 1,
2259
- unit: TimeUnit.Month,
2260
- },
2261
- };
2262
- expect(filter).toEqual(expectedFilter);
2263
- });
2264
- });
2265
- describe('AST to Filter - Date (InThePrevious Custom Cases)', () => {
2266
- it('should convert AST to Filter for date field (Redshift-1) - InThePrevious Custom', () => {
2267
- const sql = `
2268
- SELECT * FROM transactions
2269
- WHERE transaction_date >= DATEADD(day, -200, CURRENT_DATE)
2270
- AND transaction_date < DATEADD(day, -90, CURRENT_DATE)
2271
- `
2272
- .replace(/\s+/g, ' ')
2273
- .trim();
2274
- const ast = parseSelectSQL(sql, 'redshift');
2275
- const filter = astToFilter(ast.where, 'redshift');
2276
- const currentDate = new Date();
2277
- const dateMinus200Days = subDays(currentDate, 200);
2278
- const dateMinus90Days = subDays(currentDate, 90);
2279
- const formattedStartDate = format(dateMinus200Days, 'yyyy-MM-dd');
2280
- const formattedEndDate = format(dateMinus90Days, 'yyyy-MM-dd');
2281
- const expectedFilter = {
2282
- field: 'transaction_date',
2283
- name: FilterNames.DateCustomFilter,
2284
- type: FieldTypes.Date,
2285
- operator: DateOperator.Custom,
2286
- value: {
2287
- startDate: formattedStartDate,
2288
- endDate: formattedEndDate,
2289
- },
2290
- };
2291
- expect(filter).toEqual(expectedFilter);
2292
- });
2293
- it('should convert AST to Filter for date field (Redshift-2) - InThePrevious Custom', () => {
2294
- const sql = `
2295
- SELECT * FROM transactions
2296
- WHERE transaction_date >= DATEADD(day, -200, GETDATE())
2297
- AND transaction_date < DATEADD(day, -90, GETDATE())
2298
- `
2299
- .replace(/\s+/g, ' ')
2300
- .trim();
2301
- const ast = parseSelectSQL(sql, 'redshift');
2302
- const filter = astToFilter(ast.where, 'redshift');
2303
- const currentDate = new Date();
2304
- const dateMinus200Days = subDays(currentDate, 200);
2305
- const dateMinus90Days = subDays(currentDate, 90);
2306
- const formattedStartDate = format(dateMinus200Days, 'yyyy-MM-dd');
2307
- const formattedEndDate = format(dateMinus90Days, 'yyyy-MM-dd');
2308
- const expectedFilter = {
2309
- field: 'transaction_date',
2310
- name: FilterNames.DateCustomFilter,
2311
- type: FieldTypes.Date,
2312
- operator: DateOperator.Custom,
2313
- value: {
2314
- startDate: formattedStartDate,
2315
- endDate: formattedEndDate,
2316
- },
2317
- };
2318
- expect(filter).toEqual(expectedFilter);
2319
- });
2320
- it('should convert AST to Filter for date field (Snowflake-1) - InThePrevious Custom', () => {
2321
- const sql = `
2322
- SELECT * FROM transactions
2323
- WHERE transaction_date >= CURRENT_DATE() - INTERVAL '4 YEARS'
2324
- AND transaction_date < CURRENT_DATE() - INTERVAL '1 YEAR'
2325
- `
2326
- .replace(/\s+/g, ' ')
2327
- .trim();
2328
- const ast = parseSelectSQL(sql, 'snowflake');
2329
- const filter = astToFilter(ast.where, 'snowflake');
2330
- const currentDate = new Date();
2331
- const dateMinus4Years = subYears(currentDate, 4);
2332
- const dateMinus1Year = subYears(currentDate, 1);
2333
- const formattedStartDate = format(dateMinus4Years, 'yyyy-MM-dd');
2334
- const formattedEndDate = format(dateMinus1Year, 'yyyy-MM-dd');
2335
- const expectedFilter = {
2336
- field: 'transaction_date',
2337
- name: FilterNames.DateCustomFilter,
2338
- type: FieldTypes.Date,
2339
- operator: DateOperator.Custom,
2340
- value: {
2341
- startDate: formattedStartDate,
2342
- endDate: formattedEndDate,
2343
- },
2344
- };
2345
- expect(filter).toEqual(expectedFilter);
2346
- });
2347
- it('should convert AST to Filter for date field (Snowflake-2) - InThePrevious Custom', () => {
2348
- const sql = `
2349
- SELECT * FROM transactions
2350
- WHERE transaction_date >= DATEADD(YEAR, -4, CURRENT_DATE())
2351
- AND transaction_date < DATEADD(YEAR, -1, CURRENT_DATE())
2352
- `
2353
- .replace(/\s+/g, ' ')
2354
- .trim();
2355
- const ast = parseSelectSQL(sql, 'snowflake');
2356
- const filter = astToFilter(ast.where, 'snowflake');
2357
- const currentDate = new Date();
2358
- const dateMinus4Years = subYears(currentDate, 4);
2359
- const dateMinus1Year = subYears(currentDate, 1);
2360
- const formattedStartDate = format(dateMinus4Years, 'yyyy-MM-dd');
2361
- const formattedEndDate = format(dateMinus1Year, 'yyyy-MM-dd');
2362
- const expectedFilter = {
2363
- field: 'transaction_date',
2364
- name: FilterNames.DateCustomFilter,
2365
- type: FieldTypes.Date,
2366
- operator: DateOperator.Custom,
2367
- value: {
2368
- startDate: formattedStartDate,
2369
- endDate: formattedEndDate,
2370
- },
2371
- };
2372
- expect(filter).toEqual(expectedFilter);
2373
- });
2374
- it('should convert AST to Filter for date field (BigQuery) - InThePrevious Custom', () => {
2375
- const sql = `
2376
- SELECT * FROM transactions
2377
- WHERE transaction_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 200 DAY)
2378
- AND transaction_date < DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
2379
- `
2380
- .replace(/\s+/g, ' ')
2381
- .trim();
2382
- const ast = parseSelectSQL(sql, 'bigquery');
2383
- const filter = astToFilter(ast.where, 'bigquery');
2384
- const currentDate = new Date();
2385
- const dateMinus200Days = subDays(currentDate, 200);
2386
- const dateMinus90Days = subDays(currentDate, 90);
2387
- const formattedStartDate = format(dateMinus200Days, 'yyyy-MM-dd');
2388
- const formattedEndDate = format(dateMinus90Days, 'yyyy-MM-dd');
2389
- const expectedFilter = {
2390
- field: 'transaction_date',
2391
- name: FilterNames.DateCustomFilter,
2392
- type: FieldTypes.Date,
2393
- operator: DateOperator.Custom,
2394
- value: {
2395
- startDate: formattedStartDate,
2396
- endDate: formattedEndDate,
2397
- },
2398
- };
2399
- expect(filter).toEqual(expectedFilter);
2400
- });
2401
- it('should convert AST to Filter for date field (MySQL-1) - InThePrevious Custom', () => {
2402
- const sql = `
2403
- SELECT * FROM transactions
2404
- WHERE transaction_date >= CURDATE() - INTERVAL 3 MONTH
2405
- AND transaction_date < CURDATE() - INTERVAL 1 MONTH
2406
- `
2407
- .replace(/\s+/g, ' ')
2408
- .trim();
2409
- const ast = parseSelectSQL(sql, 'mysql');
2410
- const filter = astToFilter(ast.where, 'mysql');
2411
- const currentDate = new Date();
2412
- const dateMinus3Months = subMonths(currentDate, 3);
2413
- const dateMinus1Month = subMonths(currentDate, 1);
2414
- const formattedStartDate = format(dateMinus3Months, 'yyyy-MM-dd');
2415
- const formattedEndDate = format(dateMinus1Month, 'yyyy-MM-dd');
2416
- const expectedFilter = {
2417
- field: 'transaction_date',
2418
- name: FilterNames.DateCustomFilter,
2419
- type: FieldTypes.Date,
2420
- operator: DateOperator.Custom,
2421
- value: {
2422
- startDate: formattedStartDate,
2423
- endDate: formattedEndDate,
2424
- },
2425
- };
2426
- expect(filter).toEqual(expectedFilter);
2427
- });
2428
- it('should convert AST to Filter for date field (MySQL-2) - InThePrevious Custom', () => {
2429
- const sql = `
2430
- SELECT * FROM transactions
2431
- WHERE transaction_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH)
2432
- AND transaction_date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
2433
- `
2434
- .replace(/\s+/g, ' ')
2435
- .trim();
2436
- const ast = parseSelectSQL(sql, 'mysql');
2437
- const filter = astToFilter(ast.where, 'mysql');
2438
- const currentDate = new Date();
2439
- const dateMinus3Months = subMonths(currentDate, 3);
2440
- const dateMinus1Month = subMonths(currentDate, 1);
2441
- const formattedStartDate = format(dateMinus3Months, 'yyyy-MM-dd');
2442
- const formattedEndDate = format(dateMinus1Month, 'yyyy-MM-dd');
2443
- const expectedFilter = {
2444
- field: 'transaction_date',
2445
- name: FilterNames.DateCustomFilter,
2446
- type: FieldTypes.Date,
2447
- operator: DateOperator.Custom,
2448
- value: {
2449
- startDate: formattedStartDate,
2450
- endDate: formattedEndDate,
2451
- },
2452
- };
2453
- expect(filter).toEqual(expectedFilter);
2454
- });
2455
- it('should convert AST to Filter for date field (MySQL-3) - InThePrevious Custom', () => {
2456
- const sql = `
2457
- SELECT * FROM transactions
2458
- WHERE transaction_date >= DATE_SUB(NOW(), INTERVAL 3 MONTH)
2459
- AND transaction_date < DATE_SUB(NOW(), INTERVAL 1 MONTH)
2460
- `
2461
- .replace(/\s+/g, ' ')
2462
- .trim();
2463
- const ast = parseSelectSQL(sql, 'mysql');
2464
- const filter = astToFilter(ast.where, 'mysql');
2465
- const currentDate = new Date();
2466
- const dateMinus3Months = subMonths(currentDate, 3);
2467
- const dateMinus1Month = subMonths(currentDate, 1);
2468
- const formattedStartDate = format(dateMinus3Months, 'yyyy-MM-dd');
2469
- const formattedEndDate = format(dateMinus1Month, 'yyyy-MM-dd');
2470
- const expectedFilter = {
2471
- field: 'transaction_date',
2472
- name: FilterNames.DateCustomFilter,
2473
- type: FieldTypes.Date,
2474
- operator: DateOperator.Custom,
2475
- value: {
2476
- startDate: formattedStartDate,
2477
- endDate: formattedEndDate,
2478
- },
2479
- };
2480
- expect(filter).toEqual(expectedFilter);
2481
- });
2482
- it('should convert AST to Filter for date field (Postgres) - InThePrevious Custom', () => {
2483
- const sql = `
2484
- SELECT * FROM transactions
2485
- WHERE transaction_date >= CURRENT_DATE - INTERVAL 3 month
2486
- AND transaction_date < CURRENT_DATE - INTERVAL 1 month
2487
- `
2488
- .replace(/\s+/g, ' ')
2489
- .trim();
2490
- const ast = parseSelectSQL(sql, 'postgresql');
2491
- const filter = astToFilter(ast.where, 'postgresql');
2492
- const currentDate = new Date();
2493
- const dateMinus3Months = subMonths(currentDate, 3);
2494
- const dateMinus1Month = subMonths(currentDate, 1);
2495
- const formattedStartDate = format(dateMinus3Months, 'yyyy-MM-dd');
2496
- const formattedEndDate = format(dateMinus1Month, 'yyyy-MM-dd');
2497
- const expectedFilter = {
2498
- field: 'transaction_date',
2499
- name: FilterNames.DateCustomFilter,
2500
- type: FieldTypes.Date,
2501
- operator: DateOperator.Custom,
2502
- value: {
2503
- startDate: formattedStartDate,
2504
- endDate: formattedEndDate,
2505
- },
2506
- };
2507
- expect(filter).toEqual(expectedFilter);
2508
- });
2509
- });
2510
- describe('Filter to AST - Date (Date Comparison Operators)', () => {
2511
- it('should convert Filter to AST for date field - EqualTo', () => {
2512
- const filter = {
2513
- field: 'transaction_date',
2514
- name: FilterNames.DateComparisonFilter,
2515
- type: FieldTypes.Date,
2516
- operator: DateOperator.EqualTo,
2517
- value: '2023-10-21',
2518
- };
2519
- const ast = filterToAst(filter, 'mysql');
2520
- const sql = `
2521
- SELECT * FROM transactions
2522
- WHERE transaction_date = '2023-10-21'
2523
- `
2524
- .replace(/\s+/g, ' ')
2525
- .trim();
2526
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
2527
- expect(ast).toEqual(expectedAst);
2528
- });
2529
- it('should convert Filter to AST for date field - NotEqualTo', () => {
2530
- const filter = {
2531
- field: 'transaction_date',
2532
- name: FilterNames.DateComparisonFilter,
2533
- type: FieldTypes.Date,
2534
- operator: DateOperator.NotEqualTo,
2535
- value: '2023-10-21',
2536
- };
2537
- const ast = filterToAst(filter, 'mysql');
2538
- const sql = `
2539
- SELECT * FROM transactions
2540
- WHERE transaction_date <> '2023-10-21'
2541
- `
2542
- .replace(/\s+/g, ' ')
2543
- .trim();
2544
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
2545
- expect(ast).toEqual(expectedAst);
2546
- });
2547
- it('should convert Filter to AST for date field - LessThan', () => {
2548
- const filter = {
2549
- field: 'transaction_date',
2550
- name: FilterNames.DateComparisonFilter,
2551
- type: FieldTypes.Date,
2552
- operator: DateOperator.LessThan,
2553
- value: '2023-10-21',
2554
- };
2555
- const ast = filterToAst(filter, 'mysql');
2556
- const sql = `
2557
- SELECT * FROM transactions
2558
- WHERE transaction_date < '2023-10-21'
2559
- `
2560
- .replace(/\s+/g, ' ')
2561
- .trim();
2562
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
2563
- expect(ast).toEqual(expectedAst);
2564
- });
2565
- it('should convert Filter to AST for date field - LessThanOrEqualTo', () => {
2566
- const filter = {
2567
- field: 'transaction_date',
2568
- name: FilterNames.DateComparisonFilter,
2569
- type: FieldTypes.Date,
2570
- operator: DateOperator.LessThanOrEqualTo,
2571
- value: '2023-10-21',
2572
- };
2573
- const ast = filterToAst(filter, 'mysql');
2574
- const sql = `
2575
- SELECT * FROM transactions
2576
- WHERE transaction_date <= '2023-10-21'
2577
- `
2578
- .replace(/\s+/g, ' ')
2579
- .trim();
2580
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
2581
- expect(ast).toEqual(expectedAst);
2582
- });
2583
- it('should convert Filter to AST for date field - GreaterThan', () => {
2584
- const filter = {
2585
- field: 'transaction_date',
2586
- name: FilterNames.DateComparisonFilter,
2587
- type: FieldTypes.Date,
2588
- operator: DateOperator.GreaterThan,
2589
- value: '2023-10-21',
2590
- };
2591
- const ast = filterToAst(filter, 'mysql');
2592
- const sql = `
2593
- SELECT * FROM transactions
2594
- WHERE transaction_date > '2023-10-21'
2595
- `
2596
- .replace(/\s+/g, ' ')
2597
- .trim();
2598
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
2599
- expect(ast).toEqual(expectedAst);
2600
- });
2601
- it('should convert Filter to AST for date field - GreaterThanOrEqualTo', () => {
2602
- const filter = {
2603
- field: 'transaction_date',
2604
- name: FilterNames.DateComparisonFilter,
2605
- type: FieldTypes.Date,
2606
- operator: DateOperator.GreaterThanOrEqualTo,
2607
- value: '2023-10-21',
2608
- };
2609
- const ast = filterToAst(filter, 'mysql');
2610
- const sql = `
2611
- SELECT * FROM transactions
2612
- WHERE transaction_date >= '2023-10-21'
2613
- `
2614
- .replace(/\s+/g, ' ')
2615
- .trim();
2616
- const expectedAst = parseSelectSQL(sql, 'mysql').where;
2617
- expect(ast).toEqual(expectedAst);
2618
- });
2619
- });
2620
- describe('AST to Filter - Date (Date Comparison Operators)', () => {
2621
- it('should convert AST to Filter for date field - EqualTo', () => {
2622
- const sql = `
2623
- SELECT * FROM transactions
2624
- WHERE transaction_date = '2023-10-21'
2625
- `
2626
- .replace(/\s+/g, ' ')
2627
- .trim();
2628
- const ast = parseSelectSQL(sql, 'postgresql');
2629
- const filter = astToFilter(ast.where, 'postgresql');
2630
- const expectedFilter = {
2631
- field: 'transaction_date',
2632
- name: FilterNames.DateCustomFilter,
2633
- type: FieldTypes.Date,
2634
- operator: DateOperator.Custom,
2635
- value: { startDate: '2023-10-21', endDate: '2023-10-21' },
2636
- };
2637
- expect(filter).toEqual(expectedFilter);
2638
- });
2639
- it('should convert AST to Filter for date field - NotEqualTo', () => {
2640
- const sql = `
2641
- SELECT * FROM transactions
2642
- WHERE transaction_date <> '2023-10-21'
2643
- `
2644
- .replace(/\s+/g, ' ')
2645
- .trim();
2646
- const ast = parseSelectSQL(sql, 'postgresql');
2647
- const filter = astToFilter(ast.where, 'postgresql');
2648
- const expectedFilter = {
2649
- field: 'transaction_date',
2650
- name: FilterNames.DateComparisonFilter,
2651
- type: FieldTypes.Date,
2652
- operator: DateOperator.NotEqualTo,
2653
- value: '2023-10-21',
2654
- };
2655
- expect(filter).toEqual(expectedFilter);
2656
- });
2657
- it('should convert AST to Filter for date field - LessThan', () => {
2658
- const sql = `
2659
- SELECT * FROM transactions
2660
- WHERE transaction_date < '2023-10-21'
2661
- `
2662
- .replace(/\s+/g, ' ')
2663
- .trim();
2664
- const ast = parseSelectSQL(sql, 'postgresql');
2665
- const filter = astToFilter(ast.where, 'postgresql');
2666
- const expectedFilter = {
2667
- field: 'transaction_date',
2668
- name: FilterNames.DateComparisonFilter,
2669
- type: FieldTypes.Date,
2670
- operator: DateOperator.LessThan,
2671
- value: '2023-10-21',
2672
- };
2673
- expect(filter).toEqual(expectedFilter);
2674
- });
2675
- it('should convert AST to Filter for date field - LessThanOrEqualTo', () => {
2676
- const sql = `
2677
- SELECT * FROM transactions
2678
- WHERE transaction_date <= '2023-10-21'
2679
- `
2680
- .replace(/\s+/g, ' ')
2681
- .trim();
2682
- const ast = parseSelectSQL(sql, 'postgresql');
2683
- const filter = astToFilter(ast.where, 'postgresql');
2684
- const expectedFilter = {
2685
- field: 'transaction_date',
2686
- name: FilterNames.DateComparisonFilter,
2687
- type: FieldTypes.Date,
2688
- operator: DateOperator.LessThanOrEqualTo,
2689
- value: '2023-10-21',
2690
- };
2691
- expect(filter).toEqual(expectedFilter);
2692
- });
2693
- it('should convert AST to Filter for date field - GreaterThan', () => {
2694
- const sql = `
2695
- SELECT * FROM transactions
2696
- WHERE transaction_date > '2023-10-21'
2697
- `
2698
- .replace(/\s+/g, ' ')
2699
- .trim();
2700
- const ast = parseSelectSQL(sql, 'postgresql');
2701
- const filter = astToFilter(ast.where, 'postgresql');
2702
- const expectedFilter = {
2703
- field: 'transaction_date',
2704
- name: FilterNames.DateComparisonFilter,
2705
- type: FieldTypes.Date,
2706
- operator: DateOperator.GreaterThan,
2707
- value: '2023-10-21',
2708
- };
2709
- expect(filter).toEqual(expectedFilter);
2710
- });
2711
- it('should convert AST to Filter for date field - GreaterThanOrEqualTo', () => {
2712
- const sql = `
2713
- SELECT * FROM transactions
2714
- WHERE transaction_date >= '2023-10-21'
2715
- `
2716
- .replace(/\s+/g, ' ')
2717
- .trim();
2718
- const ast = parseSelectSQL(sql, 'postgresql');
2719
- const filter = astToFilter(ast.where, 'postgresql');
2720
- const expectedFilter = {
2721
- field: 'transaction_date',
2722
- name: FilterNames.DateComparisonFilter,
2723
- type: FieldTypes.Date,
2724
- operator: DateOperator.GreaterThanOrEqualTo,
2725
- value: '2023-10-21',
2726
- };
2727
- expect(filter).toEqual(expectedFilter);
2728
- });
2729
- });
2730
- describe('Filter to AST - Bool', () => {
2731
- it('should convert Filter to AST for boolean field - IsTrue', () => {
2732
- const filter = {
2733
- field: 'is_something',
2734
- name: FilterNames.BooleanFilter,
2735
- type: FieldTypes.Boolean,
2736
- operator: BoolOperator.EqualTo,
2737
- value: true,
2738
- };
2739
- const ast = filterToAst(filter, 'mysql');
2740
- const sql = `
2741
- SELECT * FROM transactions
2742
- WHERE is_something = TRUE
2743
- `
2744
- .replace(/\s+/g, ' ')
2745
- .trim();
2746
- const expectedAst = parseSelectSQL(sql).where;
2747
- expect(ast).toEqual(expectedAst);
2748
- });
2749
- it('should convert Filter to AST for boolean field - IsFalse', () => {
2750
- const filter = {
2751
- field: 'is_something',
2752
- name: FilterNames.BooleanFilter,
2753
- type: FieldTypes.Boolean,
2754
- operator: BoolOperator.EqualTo,
2755
- value: false,
2756
- };
2757
- const ast = filterToAst(filter, 'mysql');
2758
- const sql = `
2759
- SELECT * FROM transactions
2760
- WHERE is_something = FALSE
2761
- `
2762
- .replace(/\s+/g, ' ')
2763
- .trim();
2764
- const expectedAst = parseSelectSQL(sql).where;
2765
- expect(ast).toEqual(expectedAst);
2766
- });
2767
- it('should convert Filter to AST for boolean field - IsNotTrue', () => {
2768
- const filter = {
2769
- field: 'is_something',
2770
- name: FilterNames.BooleanFilter,
2771
- type: FieldTypes.Boolean,
2772
- operator: BoolOperator.NotEqualTo,
2773
- value: true,
2774
- };
2775
- const ast = filterToAst(filter, 'mysql');
2776
- const sql = `
2777
- SELECT * FROM transactions
2778
- WHERE is_something <> TRUE
2779
- `
2780
- .replace(/\s+/g, ' ')
2781
- .trim();
2782
- const expectedAst = parseSelectSQL(sql).where;
2783
- expect(ast).toEqual(expectedAst);
2784
- });
2785
- it('should convert Filter to AST for boolean field - IsNotFalse', () => {
2786
- const filter = {
2787
- field: 'is_something',
2788
- name: FilterNames.BooleanFilter,
2789
- type: FieldTypes.Boolean,
2790
- operator: BoolOperator.NotEqualTo,
2791
- value: false,
2792
- };
2793
- const ast = filterToAst(filter, 'mysql');
2794
- const sql = `
2795
- SELECT * FROM transactions
2796
- WHERE is_something <> FALSE
2797
- `
2798
- .replace(/\s+/g, ' ')
2799
- .trim();
2800
- const expectedAst = parseSelectSQL(sql).where;
2801
- expect(ast).toEqual(expectedAst);
2802
- });
2803
- });
2804
- describe('AST to Filter - Bool', () => {
2805
- it('should convert AST to Filter for boolean field - IsTrue', () => {
2806
- const sql = `
2807
- SELECT * FROM transactions
2808
- WHERE is_something = TRUE
2809
- `
2810
- .replace(/\s+/g, ' ')
2811
- .trim();
2812
- const ast = parseSelectSQL(sql);
2813
- const filter = astToFilter(ast.where, 'postgresql');
2814
- const expectedFilter = {
2815
- field: 'is_something',
2816
- name: FilterNames.BooleanFilter,
2817
- type: FieldTypes.Boolean,
2818
- operator: BoolOperator.EqualTo,
2819
- value: true,
2820
- };
2821
- expect(filter).toEqual(expectedFilter);
2822
- });
2823
- it('should convert AST to Filter for boolean field - IsFalse', () => {
2824
- const sql = `
2825
- SELECT * FROM transactions
2826
- WHERE is_something = FALSE
2827
- `
2828
- .replace(/\s+/g, ' ')
2829
- .trim();
2830
- const ast = parseSelectSQL(sql);
2831
- const filter = astToFilter(ast.where, 'postgresql');
2832
- const expectedFilter = {
2833
- field: 'is_something',
2834
- name: FilterNames.BooleanFilter,
2835
- type: FieldTypes.Boolean,
2836
- operator: BoolOperator.EqualTo,
2837
- value: false,
2838
- };
2839
- expect(filter).toEqual(expectedFilter);
2840
- });
2841
- it('should convert AST to Filter for boolean field - IsNotTrue', () => {
2842
- const sql = `
2843
- SELECT * FROM transactions
2844
- WHERE is_something <> TRUE
2845
- `
2846
- .replace(/\s+/g, ' ')
2847
- .trim();
2848
- const ast = parseSelectSQL(sql);
2849
- const filter = astToFilter(ast.where, 'postgresql');
2850
- const expectedFilter = {
2851
- field: 'is_something',
2852
- name: FilterNames.BooleanFilter,
2853
- type: FieldTypes.Boolean,
2854
- operator: BoolOperator.NotEqualTo,
2855
- value: true,
2856
- };
2857
- expect(filter).toEqual(expectedFilter);
2858
- });
2859
- it('should convert AST to Filter for boolean field - IsNotFalse', () => {
2860
- const sql = `
2861
- SELECT * FROM transactions
2862
- WHERE is_something <> FALSE
2863
- `
2864
- .replace(/\s+/g, ' ')
2865
- .trim();
2866
- const ast = parseSelectSQL(sql);
2867
- const filter = astToFilter(ast.where, 'postgresql');
2868
- const expectedFilter = {
2869
- field: 'is_something',
2870
- name: FilterNames.BooleanFilter,
2871
- type: FieldTypes.Boolean,
2872
- operator: BoolOperator.NotEqualTo,
2873
- value: false,
2874
- };
2875
- expect(filter).toEqual(expectedFilter);
2876
- });
2877
- });