@m6d/cortex-cli 0.1.0

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