@questdb/sql-parser 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.
@@ -0,0 +1,794 @@
1
+ export interface AstNode {
2
+ type: string;
3
+ }
4
+ export type Statement = SelectStatement | InsertStatement | UpdateStatement | CreateTableStatement | CreateMaterializedViewStatement | CreateUserStatement | CreateGroupStatement | CreateServiceAccountStatement | AlterTableStatement | AlterMaterializedViewStatement | AlterUserStatement | AlterServiceAccountStatement | CreateViewStatement | AlterViewStatement | DropTableStatement | DropMaterializedViewStatement | DropViewStatement | DropUserStatement | DropGroupStatement | DropServiceAccountStatement | TruncateTableStatement | RenameTableStatement | AddUserStatement | RemoveUserStatement | AssumeServiceAccountStatement | ExitServiceAccountStatement | CancelQueryStatement | ShowStatement | ExplainStatement | CopyStatement | CheckpointStatement | SnapshotStatement | GrantStatement | RevokeStatement | GrantAssumeServiceAccountStatement | RevokeAssumeServiceAccountStatement | VacuumTableStatement | ResumeWalStatement | SetTypeStatement | ReindexTableStatement | RefreshMaterializedViewStatement | PivotStatement | BackupStatement | AlterGroupStatement | CompileViewStatement;
5
+ export interface SelectStatement extends AstNode {
6
+ type: "select";
7
+ /** When true, the original query was an implicit SELECT (e.g., "trades" instead of "SELECT * FROM trades") */
8
+ implicit?: boolean;
9
+ declare?: DeclareClause;
10
+ with?: CTE[];
11
+ distinct?: boolean;
12
+ columns: SelectItem[];
13
+ from?: TableRef[];
14
+ where?: Expression;
15
+ sampleBy?: SampleByClause;
16
+ latestOn?: LatestOnClause;
17
+ groupBy?: Expression[];
18
+ pivot?: PivotClause;
19
+ orderBy?: OrderByItem[];
20
+ limit?: LimitClause;
21
+ setOperations?: SetOperation[];
22
+ }
23
+ export interface CTE extends AstNode {
24
+ type: "cte";
25
+ name: string;
26
+ query: SelectStatement;
27
+ }
28
+ export interface SetOperation extends AstNode {
29
+ type: "setOperation";
30
+ operator: "UNION" | "EXCEPT" | "INTERSECT";
31
+ all?: boolean;
32
+ select: SelectStatement;
33
+ }
34
+ export interface InsertStatement extends AstNode {
35
+ type: "insert";
36
+ table: QualifiedName;
37
+ atomic?: boolean;
38
+ batch?: {
39
+ size: number;
40
+ o3MaxLag?: string;
41
+ };
42
+ with?: CTE[];
43
+ columns?: string[];
44
+ values?: Expression[][];
45
+ select?: SelectStatement;
46
+ }
47
+ export interface UpdateStatement extends AstNode {
48
+ type: "update";
49
+ with?: CTE[];
50
+ table: QualifiedName;
51
+ alias?: string;
52
+ set: SetClause[];
53
+ from?: TableRef;
54
+ joins?: JoinClause[];
55
+ where?: Expression;
56
+ }
57
+ export interface DeclareClause extends AstNode {
58
+ type: "declareClause";
59
+ assignments: DeclareAssignment[];
60
+ }
61
+ export interface DeclareAssignment extends AstNode {
62
+ type: "declareAssignment";
63
+ name: string;
64
+ value: Expression;
65
+ overridable?: boolean;
66
+ }
67
+ export interface CreateTableStatement extends AstNode {
68
+ type: "createTable";
69
+ table: QualifiedName;
70
+ atomic?: boolean;
71
+ batch?: {
72
+ size: number;
73
+ o3MaxLag?: string;
74
+ };
75
+ ifNotExists?: boolean;
76
+ columns?: ColumnDefinition[];
77
+ like?: QualifiedName;
78
+ asSelect?: SelectStatement;
79
+ casts?: CastDefinition[];
80
+ indexes?: IndexDefinition[];
81
+ timestamp?: string;
82
+ partitionBy?: "NONE" | "HOUR" | "DAY" | "WEEK" | "MONTH" | "YEAR";
83
+ wal?: boolean;
84
+ bypassWal?: boolean;
85
+ ttl?: {
86
+ value: number;
87
+ unit: "HOURS" | "DAYS" | "WEEKS" | "MONTHS" | "YEARS";
88
+ };
89
+ withParams?: TableParam[];
90
+ volume?: string;
91
+ ownedBy?: string;
92
+ dedupKeys?: string[];
93
+ }
94
+ export interface TableParam extends AstNode {
95
+ type: "tableParam";
96
+ name: string;
97
+ value?: Expression;
98
+ }
99
+ export interface CastDefinition extends AstNode {
100
+ type: "castDefinition";
101
+ column: QualifiedName;
102
+ dataType: string;
103
+ }
104
+ export interface IndexDefinition extends AstNode {
105
+ type: "indexDefinition";
106
+ column: QualifiedName;
107
+ capacity?: number;
108
+ }
109
+ export interface CreateUserStatement extends AstNode {
110
+ type: "createUser";
111
+ user: QualifiedName;
112
+ ifNotExists?: boolean;
113
+ password?: string;
114
+ noPassword?: boolean;
115
+ }
116
+ export interface CreateGroupStatement extends AstNode {
117
+ type: "createGroup";
118
+ group: QualifiedName;
119
+ ifNotExists?: boolean;
120
+ externalAlias?: string;
121
+ }
122
+ export interface CreateServiceAccountStatement extends AstNode {
123
+ type: "createServiceAccount";
124
+ account: QualifiedName;
125
+ ifNotExists?: boolean;
126
+ password?: string;
127
+ noPassword?: boolean;
128
+ ownedBy?: string;
129
+ }
130
+ export interface CreateMaterializedViewStatement extends AstNode {
131
+ type: "createMaterializedView";
132
+ view: QualifiedName;
133
+ ifNotExists?: boolean;
134
+ baseTable?: QualifiedName;
135
+ refresh?: MaterializedViewRefresh;
136
+ period?: MaterializedViewPeriod;
137
+ query: SelectStatement;
138
+ asParens?: boolean;
139
+ timestamp?: QualifiedName;
140
+ partitionBy?: "YEAR" | "MONTH" | "WEEK" | "DAY" | "HOUR";
141
+ ttl?: {
142
+ value: number;
143
+ unit: "HOURS" | "DAYS" | "WEEKS" | "MONTHS" | "YEARS";
144
+ };
145
+ volume?: string;
146
+ ownedBy?: string;
147
+ }
148
+ export interface MaterializedViewRefresh extends AstNode {
149
+ type: "materializedViewRefresh";
150
+ mode?: "immediate" | "manual";
151
+ every?: string;
152
+ deferred?: boolean;
153
+ start?: string;
154
+ timeZone?: string;
155
+ }
156
+ export interface MaterializedViewPeriod extends AstNode {
157
+ type: "materializedViewPeriod";
158
+ length?: string;
159
+ delay?: string;
160
+ timeZone?: string;
161
+ sampleByInterval?: boolean;
162
+ }
163
+ export interface ColumnDefinition extends AstNode {
164
+ type: "columnDefinition";
165
+ name: string;
166
+ dataType: string;
167
+ /** SYMBOL CAPACITY value */
168
+ symbolCapacity?: number;
169
+ /** SYMBOL CACHE/NOCACHE */
170
+ cache?: boolean;
171
+ /** Whether column is indexed */
172
+ indexed?: boolean;
173
+ /** INDEX CAPACITY value */
174
+ indexCapacity?: number;
175
+ }
176
+ export interface AlterTableStatement extends AstNode {
177
+ type: "alterTable";
178
+ table: QualifiedName;
179
+ action: AlterTableAction;
180
+ }
181
+ export interface AlterMaterializedViewStatement extends AstNode {
182
+ type: "alterMaterializedView";
183
+ view: QualifiedName;
184
+ action: AlterMaterializedViewAction;
185
+ }
186
+ export type AlterMaterializedViewAction = AlterMaterializedViewAddIndex | AlterMaterializedViewDropIndex | AlterMaterializedViewSymbolCapacity | AlterMaterializedViewSetTtl | AlterMaterializedViewSetRefreshLimit | AlterMaterializedViewSetRefresh | AlterMaterializedViewResumeWal | AlterMaterializedViewSuspendWal;
187
+ export interface AlterMaterializedViewAddIndex {
188
+ actionType: "addIndex";
189
+ column: string;
190
+ capacity?: number;
191
+ }
192
+ export interface AlterMaterializedViewSymbolCapacity {
193
+ actionType: "symbolCapacity";
194
+ column: string;
195
+ capacity: number;
196
+ }
197
+ export interface AlterMaterializedViewSetTtl {
198
+ actionType: "setTtl";
199
+ ttl: {
200
+ value: number;
201
+ unit: "HOURS" | "DAYS" | "WEEKS" | "MONTHS" | "YEARS";
202
+ };
203
+ }
204
+ export interface AlterMaterializedViewSetRefreshLimit {
205
+ actionType: "setRefreshLimit";
206
+ limit: {
207
+ value: number;
208
+ unit: "HOURS" | "DAYS" | "WEEKS" | "MONTHS" | "YEARS";
209
+ };
210
+ }
211
+ export interface AlterMaterializedViewSetRefresh {
212
+ actionType: "setRefresh";
213
+ refresh?: MaterializedViewRefresh;
214
+ period?: MaterializedViewPeriod;
215
+ }
216
+ export interface AlterMaterializedViewDropIndex {
217
+ actionType: "dropIndex";
218
+ column: string;
219
+ }
220
+ export interface AlterMaterializedViewResumeWal {
221
+ actionType: "resumeWal";
222
+ fromTxn?: number;
223
+ }
224
+ export interface AlterMaterializedViewSuspendWal {
225
+ actionType: "suspendWal";
226
+ }
227
+ export interface AlterUserStatement extends AstNode {
228
+ type: "alterUser";
229
+ user: QualifiedName;
230
+ action: AlterUserAction;
231
+ }
232
+ export type AlterUserAction = AlterUserEnableAction | AlterUserDisableAction | AlterUserPasswordAction | AlterUserCreateTokenAction | AlterUserDropTokenAction;
233
+ export interface AlterUserEnableAction {
234
+ actionType: "enable";
235
+ }
236
+ export interface AlterUserDisableAction {
237
+ actionType: "disable";
238
+ }
239
+ export interface AlterUserPasswordAction {
240
+ actionType: "password";
241
+ noPassword?: boolean;
242
+ password?: string;
243
+ }
244
+ export interface AlterUserCreateTokenAction {
245
+ actionType: "createToken";
246
+ tokenType: "JWK" | "REST";
247
+ ttl?: string;
248
+ refresh?: boolean;
249
+ transient?: boolean;
250
+ publicKeyX?: string;
251
+ publicKeyY?: string;
252
+ }
253
+ export interface AlterUserDropTokenAction {
254
+ actionType: "dropToken";
255
+ tokenType: "JWK" | "REST";
256
+ token?: string;
257
+ }
258
+ export interface AlterServiceAccountStatement extends AstNode {
259
+ type: "alterServiceAccount";
260
+ account: QualifiedName;
261
+ action: AlterUserAction;
262
+ }
263
+ export type AlterTableAction = AddColumnAction | DropColumnAction | RenameColumnAction | AlterColumnAction | DropPartitionAction | AttachPartitionAction | DetachPartitionAction | SquashPartitionsAction | SetParamAction | SetTtlAction | DedupDisableAction | DedupEnableAction | SetTypeWalAction | SuspendWalAction | ResumeWalAction | ConvertPartitionAction;
264
+ export interface AddColumnAction {
265
+ actionType: "addColumn";
266
+ ifNotExists?: boolean;
267
+ columns: ColumnDefinition[];
268
+ }
269
+ export interface DropColumnAction {
270
+ actionType: "dropColumn";
271
+ columns: string[];
272
+ }
273
+ export interface RenameColumnAction {
274
+ actionType: "renameColumn";
275
+ oldName: string;
276
+ newName: string;
277
+ }
278
+ export interface AlterColumnAction {
279
+ actionType: "alterColumn";
280
+ column: string;
281
+ alterType: "type" | "addIndex" | "dropIndex" | "cache" | "nocache" | "symbolCapacity";
282
+ newType?: string;
283
+ capacity?: number;
284
+ cache?: boolean;
285
+ }
286
+ export interface DropPartitionAction {
287
+ actionType: "dropPartition";
288
+ partitions?: string[];
289
+ where?: Expression;
290
+ }
291
+ export interface AttachPartitionAction {
292
+ actionType: "attachPartition";
293
+ partitions: string[];
294
+ }
295
+ export interface DetachPartitionAction {
296
+ actionType: "detachPartition";
297
+ partitions?: string[];
298
+ where?: Expression;
299
+ }
300
+ export interface SquashPartitionsAction {
301
+ actionType: "squashPartitions";
302
+ }
303
+ export interface SetParamAction {
304
+ actionType: "setParam";
305
+ params: TableParam[];
306
+ }
307
+ export interface SetTtlAction {
308
+ actionType: "setTtl";
309
+ ttl: {
310
+ value: number;
311
+ unit: "HOURS" | "DAYS" | "WEEKS" | "MONTHS" | "YEARS";
312
+ };
313
+ }
314
+ export interface DedupDisableAction {
315
+ actionType: "dedupDisable";
316
+ }
317
+ export interface DedupEnableAction {
318
+ actionType: "dedupEnable";
319
+ keys: string[];
320
+ }
321
+ export interface SetTypeWalAction {
322
+ actionType: "setTypeWal";
323
+ bypass?: boolean;
324
+ }
325
+ export interface SuspendWalAction {
326
+ actionType: "suspendWal";
327
+ code?: number | string;
328
+ message?: string;
329
+ }
330
+ export interface ResumeWalAction {
331
+ actionType: "resumeWal";
332
+ fromTxn?: number;
333
+ fromTransaction?: number;
334
+ }
335
+ export interface ConvertPartitionAction {
336
+ actionType: "convertPartition";
337
+ partitions?: string[];
338
+ target: string;
339
+ where?: Expression;
340
+ }
341
+ export interface DropTableStatement extends AstNode {
342
+ type: "dropTable";
343
+ table?: QualifiedName;
344
+ ifExists?: boolean;
345
+ allTables?: boolean;
346
+ }
347
+ export interface DropMaterializedViewStatement extends AstNode {
348
+ type: "dropMaterializedView";
349
+ view: QualifiedName;
350
+ ifExists?: boolean;
351
+ }
352
+ export interface CreateViewStatement extends AstNode {
353
+ type: "createView";
354
+ view: QualifiedName;
355
+ orReplace?: boolean;
356
+ ifNotExists?: boolean;
357
+ query: SelectStatement;
358
+ asParens?: boolean;
359
+ ownedBy?: string;
360
+ }
361
+ export interface AlterViewStatement extends AstNode {
362
+ type: "alterView";
363
+ view: QualifiedName;
364
+ query: SelectStatement;
365
+ }
366
+ export interface DropViewStatement extends AstNode {
367
+ type: "dropView";
368
+ view: QualifiedName;
369
+ ifExists?: boolean;
370
+ }
371
+ export interface DropUserStatement extends AstNode {
372
+ type: "dropUser";
373
+ user: QualifiedName;
374
+ ifExists?: boolean;
375
+ }
376
+ export interface DropGroupStatement extends AstNode {
377
+ type: "dropGroup";
378
+ group: QualifiedName;
379
+ ifExists?: boolean;
380
+ }
381
+ export interface DropServiceAccountStatement extends AstNode {
382
+ type: "dropServiceAccount";
383
+ account: QualifiedName;
384
+ ifExists?: boolean;
385
+ }
386
+ export interface TruncateTableStatement extends AstNode {
387
+ type: "truncateTable";
388
+ tables: QualifiedName[];
389
+ ifExists?: boolean;
390
+ only?: boolean;
391
+ keepSymbolMaps?: boolean;
392
+ }
393
+ export interface RenameTableStatement extends AstNode {
394
+ type: "renameTable";
395
+ from: QualifiedName;
396
+ to: QualifiedName;
397
+ }
398
+ export interface AddUserStatement extends AstNode {
399
+ type: "addUser";
400
+ user: QualifiedName;
401
+ groups: QualifiedName[];
402
+ }
403
+ export interface RemoveUserStatement extends AstNode {
404
+ type: "removeUser";
405
+ user: QualifiedName;
406
+ groups: QualifiedName[];
407
+ }
408
+ export interface AssumeServiceAccountStatement extends AstNode {
409
+ type: "assumeServiceAccount";
410
+ account: QualifiedName;
411
+ }
412
+ export interface ExitServiceAccountStatement extends AstNode {
413
+ type: "exitServiceAccount";
414
+ account?: QualifiedName;
415
+ }
416
+ export interface CancelQueryStatement extends AstNode {
417
+ type: "cancelQuery";
418
+ queryId: string;
419
+ }
420
+ export interface ShowStatement extends AstNode {
421
+ type: "show";
422
+ showType: "tables" | "columns" | "partitions" | "createTable" | "createView" | "createMaterializedView" | "user" | "users" | "groups" | "serviceAccount" | "serviceAccounts" | "permissions" | "serverVersion" | "parameters" | "transactionIsolationLevel" | "maxIdentifierLength" | "standardConformingStrings" | "searchPath" | "dateStyle" | "timeZone" | "serverVersionNum" | "defaultTransactionReadOnly";
423
+ table?: QualifiedName;
424
+ name?: QualifiedName;
425
+ }
426
+ export interface ExplainStatement extends AstNode {
427
+ type: "explain";
428
+ statement: Statement;
429
+ format?: string;
430
+ }
431
+ export type CopyStatement = CopyCancelStatement | CopyFromStatement | CopyToStatement;
432
+ export interface CopyCancelStatement extends AstNode {
433
+ type: "copyCancel";
434
+ id: string;
435
+ }
436
+ export interface CopyFromStatement extends AstNode {
437
+ type: "copyFrom";
438
+ table: QualifiedName;
439
+ file: string;
440
+ options?: CopyOption[];
441
+ }
442
+ export interface CopyToStatement extends AstNode {
443
+ type: "copyTo";
444
+ source: QualifiedName | SelectStatement;
445
+ destination: string;
446
+ options?: CopyOption[];
447
+ }
448
+ export interface CopyOption extends AstNode {
449
+ type: "copyOption";
450
+ key: string;
451
+ value?: string | number | boolean | string[];
452
+ /** When true, the string value originated from a string literal and should be quoted in toSql. */
453
+ quoted?: boolean;
454
+ }
455
+ export interface CheckpointStatement extends AstNode {
456
+ type: "checkpoint";
457
+ action: "create" | "release";
458
+ }
459
+ export interface SnapshotStatement extends AstNode {
460
+ type: "snapshot";
461
+ action: "prepare" | "complete";
462
+ }
463
+ export interface GrantStatement extends AstNode {
464
+ type: "grant";
465
+ permissions: string[];
466
+ on?: GrantOnTarget;
467
+ to: QualifiedName;
468
+ grantOption?: boolean;
469
+ verification?: boolean;
470
+ }
471
+ export interface RevokeStatement extends AstNode {
472
+ type: "revoke";
473
+ permissions: string[];
474
+ on?: GrantOnTarget;
475
+ from: QualifiedName;
476
+ }
477
+ export interface GrantOnTarget extends AstNode {
478
+ type: "grantOn";
479
+ allTables?: boolean;
480
+ tables?: GrantTableTarget[];
481
+ }
482
+ export interface GrantTableTarget extends AstNode {
483
+ type: "grantTableTarget";
484
+ table: QualifiedName;
485
+ columns?: string[];
486
+ }
487
+ export interface GrantAssumeServiceAccountStatement extends AstNode {
488
+ type: "grantAssumeServiceAccount";
489
+ account: QualifiedName;
490
+ to: QualifiedName;
491
+ grantOption?: boolean;
492
+ }
493
+ export interface RevokeAssumeServiceAccountStatement extends AstNode {
494
+ type: "revokeAssumeServiceAccount";
495
+ account: QualifiedName;
496
+ from: QualifiedName;
497
+ }
498
+ export interface VacuumTableStatement extends AstNode {
499
+ type: "vacuumTable";
500
+ table: QualifiedName;
501
+ }
502
+ export interface ResumeWalStatement extends AstNode {
503
+ type: "resumeWal";
504
+ fromTransaction?: number;
505
+ fromTxn?: number;
506
+ }
507
+ export interface SetTypeStatement extends AstNode {
508
+ type: "setType";
509
+ bypass?: boolean;
510
+ wal: boolean;
511
+ }
512
+ export interface ReindexTableStatement extends AstNode {
513
+ type: "reindexTable";
514
+ table: QualifiedName;
515
+ columns?: string[];
516
+ partitions?: string[];
517
+ lockExclusive?: boolean;
518
+ }
519
+ export interface RefreshMaterializedViewStatement extends AstNode {
520
+ type: "refreshMaterializedView";
521
+ view: QualifiedName;
522
+ mode?: "full" | "incremental" | "range";
523
+ from?: string;
524
+ to?: string;
525
+ }
526
+ export interface BackupStatement extends AstNode {
527
+ type: "backup";
528
+ action: "database" | "table" | "abort";
529
+ table?: QualifiedName;
530
+ }
531
+ export interface AlterGroupStatement extends AstNode {
532
+ type: "alterGroup";
533
+ group: QualifiedName;
534
+ action: "setAlias" | "dropAlias";
535
+ externalAlias: string;
536
+ }
537
+ export interface CompileViewStatement extends AstNode {
538
+ type: "compileView";
539
+ view: QualifiedName;
540
+ }
541
+ export interface PivotStatement extends AstNode {
542
+ type: "pivot";
543
+ source: QualifiedName | SelectStatement;
544
+ where?: Expression;
545
+ aggregations: PivotAggregation[];
546
+ pivots: PivotForClause[];
547
+ groupBy?: Expression[];
548
+ orderBy?: OrderByItem[];
549
+ limit?: LimitClause;
550
+ alias?: string;
551
+ }
552
+ export interface PivotClause extends AstNode {
553
+ type: "pivotClause";
554
+ aggregations: PivotAggregation[];
555
+ pivots: PivotForClause[];
556
+ groupBy?: Expression[];
557
+ }
558
+ export interface PivotAggregation extends AstNode {
559
+ type: "pivotAggregation";
560
+ expression: Expression;
561
+ alias?: string;
562
+ }
563
+ export interface PivotForClause extends AstNode {
564
+ type: "pivotFor";
565
+ expression: Expression;
566
+ in: PivotInSource;
567
+ }
568
+ export interface PivotInValue extends AstNode {
569
+ type: "pivotInValue";
570
+ expression: Expression;
571
+ alias?: string;
572
+ }
573
+ export interface PivotInSource extends AstNode {
574
+ type: "pivotIn";
575
+ values?: PivotInValue[];
576
+ select?: SelectStatement;
577
+ }
578
+ export type SelectItem = StarSelectItem | QualifiedStarSelectItem | ExpressionSelectItem;
579
+ export interface ExpressionSelectItem extends AstNode {
580
+ type: "selectItem";
581
+ expression: Expression;
582
+ alias?: string;
583
+ }
584
+ export interface StarSelectItem extends AstNode {
585
+ type: "star";
586
+ }
587
+ export interface QualifiedStarSelectItem extends AstNode {
588
+ type: "qualifiedStar";
589
+ qualifier: QualifiedName;
590
+ alias?: string;
591
+ }
592
+ export interface TableFunctionCall extends AstNode {
593
+ type: "tableFunctionCall";
594
+ name: string;
595
+ args: Expression[];
596
+ }
597
+ export interface TableRef extends AstNode {
598
+ type: "tableRef";
599
+ table: QualifiedName | SelectStatement | TableFunctionCall | ShowStatement;
600
+ alias?: string;
601
+ joins?: JoinClause[];
602
+ timestampDesignation?: string;
603
+ }
604
+ export interface JoinClause extends AstNode {
605
+ type: "join";
606
+ joinType?: "inner" | "left" | "right" | "full" | "cross" | "asof" | "lt" | "splice" | "window";
607
+ outer?: boolean;
608
+ table: TableRef;
609
+ on?: Expression;
610
+ /** Tolerance interval for ASOF and LT joins (e.g., "1h", "30s") */
611
+ tolerance?: string;
612
+ /** RANGE BETWEEN bounds for WINDOW JOIN */
613
+ range?: {
614
+ start: WindowJoinBound;
615
+ end: WindowJoinBound;
616
+ };
617
+ /** INCLUDE/EXCLUDE PREVAILING clause for WINDOW JOIN */
618
+ prevailing?: "include" | "exclude";
619
+ }
620
+ export interface WindowJoinBound extends AstNode {
621
+ type: "windowJoinBound";
622
+ boundType: "currentRow" | "duration";
623
+ direction?: "preceding" | "following";
624
+ duration?: string;
625
+ }
626
+ export interface SampleByClause extends AstNode {
627
+ type: "sampleBy";
628
+ duration: string;
629
+ fill?: string[];
630
+ alignTo?: AlignToClause;
631
+ from?: Expression;
632
+ to?: Expression;
633
+ }
634
+ export interface AlignToClause extends AstNode {
635
+ type: "alignTo";
636
+ mode: "firstObservation" | "calendar";
637
+ timeZone?: string;
638
+ offset?: string;
639
+ }
640
+ export interface LatestOnClause extends AstNode {
641
+ type: "latestOn";
642
+ timestamp?: QualifiedName;
643
+ partitionBy: QualifiedName[];
644
+ }
645
+ export interface OrderByItem extends AstNode {
646
+ type: "orderByItem";
647
+ expression: Expression;
648
+ direction?: "asc" | "desc";
649
+ }
650
+ export interface LimitClause extends AstNode {
651
+ type: "limit";
652
+ lowerBound: Expression;
653
+ upperBound?: Expression;
654
+ }
655
+ export interface SetClause extends AstNode {
656
+ type: "setClause";
657
+ column: string;
658
+ value: Expression;
659
+ }
660
+ export type Expression = BinaryExpression | UnaryExpression | ColumnRef | VariableRef | Literal | FunctionCall | CaseExpression | CastExpression | TypeCastExpression | InExpression | BetweenExpression | WithinExpression | IsNullExpression | ParenExpression | ArrayLiteral | ArrayAccessExpression | SubqueryExpression;
661
+ export interface BinaryExpression extends AstNode {
662
+ type: "binary";
663
+ operator: string;
664
+ left: Expression;
665
+ right: Expression;
666
+ }
667
+ export interface UnaryExpression extends AstNode {
668
+ type: "unary";
669
+ operator: string;
670
+ operand: Expression;
671
+ }
672
+ export interface ColumnRef extends AstNode {
673
+ type: "column";
674
+ name: QualifiedName;
675
+ }
676
+ export interface QualifiedName extends AstNode {
677
+ type: "qualifiedName";
678
+ parts: string[];
679
+ }
680
+ export interface Literal extends AstNode {
681
+ type: "literal";
682
+ value: string | number | boolean | null;
683
+ literalType: "string" | "number" | "boolean" | "null" | "geohash" | "duration";
684
+ raw?: string;
685
+ }
686
+ export interface FunctionCall extends AstNode {
687
+ type: "function";
688
+ name: string;
689
+ args: Expression[];
690
+ distinct?: boolean;
691
+ star?: boolean;
692
+ /** When true, args are separated by FROM instead of comma (e.g., EXTRACT(YEAR FROM ts)) */
693
+ fromSeparator?: boolean;
694
+ /** IGNORE NULLS modifier (e.g., first_value(x) IGNORE NULLS) */
695
+ ignoreNulls?: boolean;
696
+ /** RESPECT NULLS modifier (e.g., first_value(x) RESPECT NULLS) */
697
+ respectNulls?: boolean;
698
+ /** Subquery as function argument (e.g., touch(SELECT * FROM t)) */
699
+ subquery?: SelectStatement;
700
+ over?: WindowSpecification;
701
+ }
702
+ export interface WindowSpecification extends AstNode {
703
+ type: "windowSpec";
704
+ partitionBy?: Expression[];
705
+ orderBy?: OrderByItem[];
706
+ frame?: WindowFrame;
707
+ }
708
+ export interface WindowFrame extends AstNode {
709
+ type: "windowFrame";
710
+ mode: "rows" | "range" | "cumulative";
711
+ start?: WindowFrameBound;
712
+ end?: WindowFrameBound;
713
+ exclude?: "currentRow" | "noOthers";
714
+ }
715
+ export interface WindowFrameBound extends AstNode {
716
+ type: "windowFrameBound";
717
+ kind: "unboundedPreceding" | "unboundedFollowing" | "currentRow" | "preceding" | "following";
718
+ value?: Expression;
719
+ /** Duration string for time-unit based bounds (e.g., "5 seconds") */
720
+ duration?: string;
721
+ }
722
+ export interface CaseExpression extends AstNode {
723
+ type: "case";
724
+ /** Operand expression for simple CASE: CASE expr WHEN ... */
725
+ operand?: Expression;
726
+ whenClauses: {
727
+ when: Expression;
728
+ then: Expression;
729
+ }[];
730
+ elseClause?: Expression;
731
+ }
732
+ export interface CastExpression extends AstNode {
733
+ type: "cast";
734
+ expression: Expression;
735
+ dataType: string;
736
+ }
737
+ export interface TypeCastExpression extends AstNode {
738
+ type: "typeCast";
739
+ expression: Expression;
740
+ dataType: string;
741
+ }
742
+ export interface InExpression extends AstNode {
743
+ type: "in";
744
+ expression: Expression;
745
+ values: Expression[];
746
+ not?: boolean;
747
+ parenthesized?: boolean;
748
+ }
749
+ export interface BetweenExpression extends AstNode {
750
+ type: "between";
751
+ expression: Expression;
752
+ low: Expression;
753
+ high: Expression;
754
+ not?: boolean;
755
+ }
756
+ export interface WithinExpression extends AstNode {
757
+ type: "within";
758
+ expression: Expression;
759
+ values: Expression[];
760
+ }
761
+ export interface IsNullExpression extends AstNode {
762
+ type: "isNull";
763
+ expression: Expression;
764
+ not?: boolean;
765
+ }
766
+ export interface VariableRef extends AstNode {
767
+ type: "variable";
768
+ name: string;
769
+ }
770
+ export interface ParenExpression extends AstNode {
771
+ type: "paren";
772
+ expression: Expression;
773
+ /** Additional expressions for row/tuple constructors like (col1, col2) */
774
+ additionalExpressions?: Expression[];
775
+ }
776
+ export interface ArrayLiteral extends AstNode {
777
+ type: "arrayLiteral";
778
+ elements: (Expression | ArrayLiteral)[];
779
+ hasArrayKeyword?: boolean;
780
+ }
781
+ export interface ArrayAccessExpression extends AstNode {
782
+ type: "arrayAccess";
783
+ array: Expression;
784
+ subscripts: (Expression | ArraySlice)[];
785
+ }
786
+ export interface ArraySlice extends AstNode {
787
+ type: "arraySlice";
788
+ start?: Expression;
789
+ end?: Expression;
790
+ }
791
+ export interface SubqueryExpression extends AstNode {
792
+ type: "subquery";
793
+ query: SelectStatement;
794
+ }