@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,191 @@
1
+ import * as AST from "./ast";
2
+ import type { AddUserStatementCstChildren, AdditiveExpressionCstChildren, AlignToClauseCstChildren, AlterGroupStatementCstChildren, AlterMaterializedViewActionCstChildren, AlterMaterializedViewStatementCstChildren, AlterServiceAccountStatementCstChildren, AlterStatementCstChildren, AlterTableActionCstChildren, AlterTableStatementCstChildren, AlterUserActionCstChildren, AlterUserStatementCstChildren, AlterViewStatementCstChildren, AndExpressionCstChildren, ArrayBracketBodyCstChildren, ArrayElementCstChildren, ArrayLiteralCstChildren, ArraySubscriptCstChildren, AssumeServiceAccountStatementCstChildren, BackupStatementCstChildren, BatchClauseCstChildren, BitAndExpressionCstChildren, BitOrExpressionCstChildren, BitXorExpressionCstChildren, BooleanLiteralCstChildren, CancelQueryStatementCstChildren, CaseExpressionCstChildren, CastDefinitionCstChildren, CastExpressionCstChildren, CheckpointStatementCstChildren, ColumnDefinitionCstChildren, ColumnRefCstChildren, CompileViewStatementCstChildren, ConcatExpressionCstChildren, Ipv4ContainmentExpressionCstChildren, ConvertPartitionTargetCstChildren, CopyCancelCstChildren, CopyFromCstChildren, CopyOptionCstChildren, CopyOptionsCstChildren, CopyStatementCstChildren, CopyToCstChildren, CreateGroupStatementCstChildren, CreateMaterializedViewBodyCstChildren, CreateServiceAccountStatementCstChildren, CreateStatementCstChildren, CreateTableBodyCstChildren, CreateUserStatementCstChildren, CreateViewBodyCstChildren, CteDefinitionCstChildren, DataTypeCstChildren, DeclareAssignmentCstChildren, DeclareClauseCstChildren, DedupClauseCstChildren, DropGroupStatementCstChildren, DropMaterializedViewStatementCstChildren, DropServiceAccountStatementCstChildren, DropStatementCstChildren, DropTableStatementCstChildren, DropUserStatementCstChildren, DropViewStatementCstChildren, DurationExpressionCstChildren, EqualityExpressionCstChildren, ExitServiceAccountStatementCstChildren, ExplainStatementCstChildren, ExpressionCstChildren, FillClauseCstChildren, FillValueCstChildren, FromClauseCstChildren, FromToClauseCstChildren, FunctionCallCstChildren, FunctionNameCstChildren, GrantAssumeServiceAccountStatementCstChildren, GrantStatementCstChildren, GrantTableTargetCstChildren, GroupByClauseCstChildren, IdentifierCstChildren, IdentifierExpressionCstChildren, ImplicitSelectBodyCstChildren, ImplicitSelectStatementCstChildren, IndexDefinitionCstChildren, InsertStatementCstChildren, IntervalValueCstChildren, JoinClauseCstChildren, LatestOnClauseCstChildren, LimitClauseCstChildren, LiteralCstChildren, MaterializedViewPartitionCstChildren, MaterializedViewPeriodCstChildren, MaterializedViewRefreshCstChildren, MultiplicativeExpressionCstChildren, NotExpressionCstChildren, OrExpressionCstChildren, OrderByClauseCstChildren, OrderByItemCstChildren, OverClauseCstChildren, PartitionPeriodCstChildren, PermissionListCstChildren, PermissionTokenCstChildren, PivotAggregationCstChildren, PivotBodyCstChildren, PivotForClauseCstChildren, PivotInValueCstChildren, PivotStatementCstChildren, PrimaryExpressionCstChildren, QualifiedNameCstChildren, QualifiedStarCstChildren, ReindexTableStatementCstChildren, RefreshMaterializedViewStatementCstChildren, RelationalExpressionCstChildren, RemoveUserStatementCstChildren, RenameTableStatementCstChildren, ResumeWalStatementCstChildren, RevokeAssumeServiceAccountStatementCstChildren, RevokeStatementCstChildren, SampleByClauseCstChildren, SelectItemCstChildren, SelectListCstChildren, SelectStatementCstChildren, SetClauseCstChildren, SetExpressionCstChildren, SetOperationCstChildren, SetTypeStatementCstChildren, ShowStatementCstChildren, SimpleSelectCstChildren, SnapshotStatementCstChildren, StatementCstChildren, StatementsCstChildren, StringOrIdentifierCstChildren, StringOrQualifiedNameCstChildren, TableFunctionCallCstChildren, TableFunctionNameCstChildren, TableParamCstChildren, TableParamNameCstChildren, TableRefCstChildren, TimeUnitCstChildren, TimeZoneValueCstChildren, TruncateTableStatementCstChildren, TypeCastExpressionCstChildren, UnaryExpressionCstChildren, UpdateStatementCstChildren, VacuumTableStatementCstChildren, ValuesClauseCstChildren, ValuesListCstChildren, WhereClauseCstChildren, WindowFrameBoundCstChildren, WindowFrameClauseCstChildren, WindowJoinBoundCstChildren, WindowPartitionByClauseCstChildren, WithClauseCstChildren, WithStatementCstChildren } from "./cst-types";
3
+ declare const BaseVisitor: new (...args: any[]) => import("chevrotain").ICstVisitor<any, any>;
4
+ declare class QuestDBVisitor extends BaseVisitor {
5
+ constructor();
6
+ private tokenImage;
7
+ statements(ctx: StatementsCstChildren): AST.Statement[];
8
+ statement(ctx: StatementCstChildren): AST.Statement;
9
+ withStatement(ctx: WithStatementCstChildren): AST.Statement;
10
+ selectStatement(ctx: SelectStatementCstChildren): AST.SelectStatement;
11
+ withClause(ctx: WithClauseCstChildren): AST.CTE[];
12
+ cteDefinition(ctx: CteDefinitionCstChildren): AST.CTE;
13
+ simpleSelect(ctx: SimpleSelectCstChildren): AST.SelectStatement;
14
+ setOperation(ctx: SetOperationCstChildren): AST.SetOperation;
15
+ selectList(ctx: SelectListCstChildren): AST.SelectItem[];
16
+ selectItem(ctx: SelectItemCstChildren): AST.SelectItem;
17
+ qualifiedStar(ctx: QualifiedStarCstChildren): AST.QualifiedName;
18
+ fromClause(ctx: FromClauseCstChildren): AST.TableRef[];
19
+ implicitSelectBody(ctx: ImplicitSelectBodyCstChildren): AST.SelectStatement;
20
+ implicitSelectStatement(ctx: ImplicitSelectStatementCstChildren): AST.SelectStatement;
21
+ tableRef(ctx: TableRefCstChildren): AST.TableRef;
22
+ tableFunctionCall(ctx: TableFunctionCallCstChildren): AST.TableFunctionCall;
23
+ tableFunctionName(_ctx: TableFunctionNameCstChildren): string | undefined;
24
+ joinClause(ctx: JoinClauseCstChildren): AST.JoinClause;
25
+ windowJoinBound(ctx: WindowJoinBoundCstChildren): AST.WindowJoinBound;
26
+ durationExpression(ctx: DurationExpressionCstChildren): string;
27
+ whereClause(ctx: WhereClauseCstChildren): AST.Expression;
28
+ sampleByClause(ctx: SampleByClauseCstChildren): AST.SampleByClause;
29
+ fillClause(ctx: FillClauseCstChildren): string[];
30
+ fillValue(ctx: FillValueCstChildren): string;
31
+ alignToClause(ctx: AlignToClauseCstChildren): AST.AlignToClause;
32
+ fromToClause(ctx: FromToClauseCstChildren): {
33
+ from?: AST.Expression;
34
+ to?: AST.Expression;
35
+ };
36
+ latestOnClause(ctx: LatestOnClauseCstChildren): AST.LatestOnClause;
37
+ groupByClause(ctx: GroupByClauseCstChildren): AST.Expression[];
38
+ orderByClause(ctx: OrderByClauseCstChildren): AST.OrderByItem[];
39
+ orderByItem(ctx: OrderByItemCstChildren): AST.OrderByItem;
40
+ limitClause(ctx: LimitClauseCstChildren): AST.LimitClause;
41
+ insertStatement(ctx: InsertStatementCstChildren): AST.InsertStatement;
42
+ valuesClause(ctx: ValuesClauseCstChildren): AST.Expression[][];
43
+ valuesList(ctx: ValuesListCstChildren): AST.Expression[];
44
+ batchClause(ctx: BatchClauseCstChildren): {
45
+ size: number;
46
+ o3MaxLag?: string;
47
+ };
48
+ updateStatement(ctx: UpdateStatementCstChildren): AST.UpdateStatement;
49
+ setClause(ctx: SetClauseCstChildren): AST.SetClause;
50
+ declareClause(ctx: DeclareClauseCstChildren): AST.DeclareClause;
51
+ declareAssignment(ctx: DeclareAssignmentCstChildren): AST.DeclareAssignment;
52
+ createStatement(ctx: CreateStatementCstChildren): AST.Statement;
53
+ createTableBody(ctx: CreateTableBodyCstChildren): AST.CreateTableStatement;
54
+ columnDefinition(ctx: ColumnDefinitionCstChildren): AST.ColumnDefinition;
55
+ castDefinition(ctx: CastDefinitionCstChildren): AST.CastDefinition;
56
+ indexDefinition(ctx: IndexDefinitionCstChildren): AST.IndexDefinition;
57
+ tableParamName(ctx: TableParamNameCstChildren): string;
58
+ tableParam(ctx: TableParamCstChildren): AST.TableParam;
59
+ createViewBody(ctx: CreateViewBodyCstChildren): AST.CreateViewStatement;
60
+ createUserStatement(ctx: CreateUserStatementCstChildren): AST.CreateUserStatement;
61
+ createGroupStatement(ctx: CreateGroupStatementCstChildren): AST.CreateGroupStatement;
62
+ createServiceAccountStatement(ctx: CreateServiceAccountStatementCstChildren): AST.CreateServiceAccountStatement;
63
+ createMaterializedViewBody(ctx: CreateMaterializedViewBodyCstChildren): AST.CreateMaterializedViewStatement;
64
+ materializedViewRefresh(ctx: MaterializedViewRefreshCstChildren): AST.MaterializedViewRefresh;
65
+ materializedViewPeriod(ctx: MaterializedViewPeriodCstChildren): AST.MaterializedViewPeriod;
66
+ materializedViewPartition(ctx: MaterializedViewPartitionCstChildren): {
67
+ partitionBy?: AST.CreateMaterializedViewStatement["partitionBy"];
68
+ ttl?: AST.CreateMaterializedViewStatement["ttl"];
69
+ };
70
+ partitionPeriod(ctx: PartitionPeriodCstChildren): "NONE" | "HOUR" | "DAY" | "WEEK" | "MONTH" | "YEAR";
71
+ timeUnit(ctx: TimeUnitCstChildren): string;
72
+ dedupClause(ctx: DedupClauseCstChildren): string[];
73
+ alterStatement(ctx: AlterStatementCstChildren): AST.Statement;
74
+ alterViewStatement(ctx: AlterViewStatementCstChildren): AST.AlterViewStatement;
75
+ alterGroupStatement(ctx: AlterGroupStatementCstChildren): AST.AlterGroupStatement;
76
+ alterTableStatement(ctx: AlterTableStatementCstChildren): AST.AlterTableStatement;
77
+ alterMaterializedViewStatement(ctx: AlterMaterializedViewStatementCstChildren): AST.AlterMaterializedViewStatement;
78
+ alterMaterializedViewAction(ctx: AlterMaterializedViewActionCstChildren): AST.AlterMaterializedViewAction;
79
+ alterUserStatement(ctx: AlterUserStatementCstChildren): AST.AlterUserStatement;
80
+ alterServiceAccountStatement(ctx: AlterServiceAccountStatementCstChildren): AST.AlterServiceAccountStatement;
81
+ alterUserAction(ctx: AlterUserActionCstChildren): AST.AlterUserAction;
82
+ alterTableAction(ctx: AlterTableActionCstChildren): AST.AlterTableAction;
83
+ dropStatement(ctx: DropStatementCstChildren): AST.Statement;
84
+ dropTableStatement(ctx: DropTableStatementCstChildren): AST.DropTableStatement;
85
+ dropMaterializedViewStatement(ctx: DropMaterializedViewStatementCstChildren): AST.DropMaterializedViewStatement;
86
+ dropViewStatement(ctx: DropViewStatementCstChildren): AST.DropViewStatement;
87
+ dropUserStatement(ctx: DropUserStatementCstChildren): AST.DropUserStatement;
88
+ dropGroupStatement(ctx: DropGroupStatementCstChildren): AST.DropGroupStatement;
89
+ dropServiceAccountStatement(ctx: DropServiceAccountStatementCstChildren): AST.DropServiceAccountStatement;
90
+ truncateTableStatement(ctx: TruncateTableStatementCstChildren): AST.TruncateTableStatement;
91
+ renameTableStatement(ctx: RenameTableStatementCstChildren): AST.RenameTableStatement;
92
+ addUserStatement(ctx: AddUserStatementCstChildren): AST.AddUserStatement;
93
+ removeUserStatement(ctx: RemoveUserStatementCstChildren): AST.RemoveUserStatement;
94
+ assumeServiceAccountStatement(ctx: AssumeServiceAccountStatementCstChildren): AST.AssumeServiceAccountStatement;
95
+ exitServiceAccountStatement(ctx: ExitServiceAccountStatementCstChildren): AST.ExitServiceAccountStatement;
96
+ cancelQueryStatement(ctx: CancelQueryStatementCstChildren): AST.CancelQueryStatement;
97
+ showStatement(ctx: ShowStatementCstChildren): AST.ShowStatement;
98
+ explainStatement(ctx: ExplainStatementCstChildren): AST.ExplainStatement;
99
+ copyStatement(ctx: CopyStatementCstChildren): AST.CopyStatement;
100
+ copyCancel(ctx: CopyCancelCstChildren): AST.CopyCancelStatement;
101
+ copyFrom(ctx: CopyFromCstChildren): AST.CopyFromStatement;
102
+ copyTo(ctx: CopyToCstChildren): AST.CopyToStatement;
103
+ copyOptions(ctx: CopyOptionsCstChildren): AST.CopyOption[];
104
+ copyOption(ctx: CopyOptionCstChildren): AST.CopyOption;
105
+ checkpointStatement(ctx: CheckpointStatementCstChildren): AST.CheckpointStatement;
106
+ snapshotStatement(ctx: SnapshotStatementCstChildren): AST.SnapshotStatement;
107
+ backupStatement(ctx: BackupStatementCstChildren): AST.BackupStatement;
108
+ compileViewStatement(ctx: CompileViewStatementCstChildren): AST.CompileViewStatement;
109
+ convertPartitionTarget(ctx: ConvertPartitionTargetCstChildren): {
110
+ partitions?: string[];
111
+ target: string;
112
+ where?: AST.Expression;
113
+ };
114
+ grantStatement(ctx: GrantStatementCstChildren): AST.GrantStatement;
115
+ revokeStatement(ctx: RevokeStatementCstChildren): AST.RevokeStatement;
116
+ permissionList(ctx: PermissionListCstChildren): string[];
117
+ permissionToken(ctx: PermissionTokenCstChildren): string;
118
+ grantTableTarget(ctx: GrantTableTargetCstChildren): AST.GrantTableTarget;
119
+ grantAssumeServiceAccountStatement(ctx: GrantAssumeServiceAccountStatementCstChildren): AST.GrantAssumeServiceAccountStatement;
120
+ revokeAssumeServiceAccountStatement(ctx: RevokeAssumeServiceAccountStatementCstChildren): AST.RevokeAssumeServiceAccountStatement;
121
+ vacuumTableStatement(ctx: VacuumTableStatementCstChildren): AST.VacuumTableStatement;
122
+ resumeWalStatement(ctx: ResumeWalStatementCstChildren): AST.ResumeWalStatement;
123
+ setTypeStatement(ctx: SetTypeStatementCstChildren): AST.SetTypeStatement;
124
+ reindexTableStatement(ctx: ReindexTableStatementCstChildren): AST.ReindexTableStatement;
125
+ refreshMaterializedViewStatement(ctx: RefreshMaterializedViewStatementCstChildren): AST.RefreshMaterializedViewStatement;
126
+ pivotStatement(ctx: PivotStatementCstChildren): AST.PivotStatement;
127
+ pivotBody(ctx: PivotBodyCstChildren): {
128
+ aggregations: AST.PivotAggregation[];
129
+ pivots: AST.PivotForClause[];
130
+ groupBy?: AST.Expression[];
131
+ };
132
+ pivotAggregation(ctx: PivotAggregationCstChildren): AST.PivotAggregation;
133
+ pivotForClause(ctx: PivotForClauseCstChildren): AST.PivotForClause;
134
+ pivotInValue(ctx: PivotInValueCstChildren): AST.PivotInValue;
135
+ expression(ctx: ExpressionCstChildren): AST.Expression;
136
+ orExpression(ctx: OrExpressionCstChildren): AST.Expression;
137
+ andExpression(ctx: AndExpressionCstChildren): AST.Expression;
138
+ notExpression(ctx: NotExpressionCstChildren): AST.Expression;
139
+ equalityExpression(ctx: EqualityExpressionCstChildren): AST.Expression;
140
+ relationalExpression(ctx: RelationalExpressionCstChildren): AST.Expression;
141
+ setExpression(ctx: SetExpressionCstChildren): AST.Expression;
142
+ bitOrExpression(ctx: BitOrExpressionCstChildren): AST.Expression;
143
+ bitXorExpression(ctx: BitXorExpressionCstChildren): AST.Expression;
144
+ bitAndExpression(ctx: BitAndExpressionCstChildren): AST.Expression;
145
+ concatExpression(ctx: ConcatExpressionCstChildren): AST.Expression;
146
+ ipv4ContainmentExpression(ctx: Ipv4ContainmentExpressionCstChildren): AST.Expression;
147
+ additiveExpression(ctx: AdditiveExpressionCstChildren): AST.Expression;
148
+ multiplicativeExpression(ctx: MultiplicativeExpressionCstChildren): AST.Expression;
149
+ unaryExpression(ctx: UnaryExpressionCstChildren): AST.Expression;
150
+ typeCastExpression(ctx: TypeCastExpressionCstChildren): AST.Expression;
151
+ arraySubscript(ctx: ArraySubscriptCstChildren): AST.Expression | AST.ArraySlice;
152
+ /**
153
+ * Used in implicitSelectBody so that an incomplete clause (e.g. `trades WHERE price >`)
154
+ * doesn't destroy the entire AST. The fromClause visit succeeds and is kept; the
155
+ * whereClause visit throws on the empty expression shell and is discarded.
156
+ * Without this, parseToAst would return ast:[] for any incomplete implicit select.
157
+ *
158
+ * See tests in parser.test.ts
159
+ */
160
+ private visitSafe;
161
+ /** Get the startOffset of the first token in a CstNode */
162
+ private getFirstTokenOffset;
163
+ primaryExpression(ctx: PrimaryExpressionCstChildren): AST.Expression;
164
+ arrayLiteral(ctx: ArrayLiteralCstChildren): AST.ArrayLiteral;
165
+ arrayBracketBody(ctx: ArrayBracketBodyCstChildren): AST.ArrayLiteral;
166
+ arrayElement(ctx: ArrayElementCstChildren): AST.Expression | AST.ArrayLiteral;
167
+ castExpression(ctx: CastExpressionCstChildren): AST.CastExpression;
168
+ dataType(ctx: DataTypeCstChildren): string;
169
+ caseExpression(ctx: CaseExpressionCstChildren): AST.CaseExpression;
170
+ functionName(ctx: FunctionNameCstChildren): string;
171
+ functionCall(ctx: FunctionCallCstChildren): AST.FunctionCall;
172
+ identifierExpression(ctx: IdentifierExpressionCstChildren): AST.Expression;
173
+ overClause(ctx: OverClauseCstChildren): AST.WindowSpecification;
174
+ windowPartitionByClause(ctx: WindowPartitionByClauseCstChildren): AST.Expression[];
175
+ windowFrameClause(ctx: WindowFrameClauseCstChildren): AST.WindowFrame;
176
+ windowFrameBound(ctx: WindowFrameBoundCstChildren): AST.WindowFrameBound;
177
+ literal(ctx: LiteralCstChildren): AST.Literal;
178
+ booleanLiteral(ctx: BooleanLiteralCstChildren): boolean;
179
+ stringOrIdentifier(ctx: StringOrIdentifierCstChildren): string;
180
+ stringOrQualifiedName(ctx: StringOrQualifiedNameCstChildren): AST.QualifiedName;
181
+ intervalValue(ctx: IntervalValueCstChildren): string;
182
+ timeZoneValue(ctx: TimeZoneValueCstChildren): string;
183
+ columnRef(ctx: ColumnRefCstChildren): AST.ColumnRef;
184
+ qualifiedName(ctx: QualifiedNameCstChildren): AST.QualifiedName;
185
+ private extractMaybeString;
186
+ private extractTtl;
187
+ private extractIdentifierName;
188
+ identifier(ctx: IdentifierCstChildren): AST.QualifiedName;
189
+ }
190
+ export declare const visitor: QuestDBVisitor;
191
+ export {};
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@questdb/sql-parser",
3
+ "version": "0.1.0",
4
+ "description": "SQL parser for QuestDB syntax using Chevrotain",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "sideEffects": false,
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.cjs"
19
+ }
20
+ },
21
+ "./grammar": {
22
+ "import": {
23
+ "types": "./dist/grammar/index.d.ts",
24
+ "default": "./dist/grammar/index.js"
25
+ },
26
+ "require": {
27
+ "types": "./dist/grammar/index.d.ts",
28
+ "default": "./dist/grammar/index.cjs"
29
+ }
30
+ }
31
+ },
32
+ "packageManager": "yarn@4.9.1",
33
+ "scripts": {
34
+ "build": "tsup && tsc -p tsconfig.build.json",
35
+ "typecheck": "tsc --noEmit",
36
+ "test": "vitest run",
37
+ "test:watch": "vitest",
38
+ "test:coverage": "vitest run --coverage",
39
+ "generate:cst": "node --import jiti/register scripts/generate-cst-types.ts",
40
+ "clean": "rm -rf dist coverage",
41
+ "lint": "eslint src/ tests/",
42
+ "lint:fix": "eslint src/ tests/ --fix",
43
+ "prepublishOnly": "yarn clean && yarn build"
44
+ },
45
+ "keywords": [
46
+ "questdb",
47
+ "sql",
48
+ "parser",
49
+ "chevrotain",
50
+ "ast"
51
+ ],
52
+ "files": [
53
+ "dist",
54
+ "README.md",
55
+ "CHANGELOG.md",
56
+ "LICENSE"
57
+ ],
58
+ "engines": {
59
+ "node": ">=18.18.0"
60
+ },
61
+ "repository": {
62
+ "type": "git",
63
+ "url": "https://github.com/questdb/sql-parser.git"
64
+ },
65
+ "homepage": "https://github.com/questdb/sql-parser",
66
+ "bugs": {
67
+ "url": "https://github.com/questdb/sql-parser/issues"
68
+ },
69
+ "license": "Apache-2.0",
70
+ "dependencies": {
71
+ "chevrotain": "^11.1.1"
72
+ },
73
+ "devDependencies": {
74
+ "@chevrotain/cst-dts-gen": "^11.1.1",
75
+ "@eslint/js": "^10.0.1",
76
+ "@types/node": "^25.2.0",
77
+ "eslint": "^10.0.0",
78
+ "eslint-config-prettier": "^10.1.8",
79
+ "eslint-plugin-prettier": "^5.5.5",
80
+ "globals": "^17.3.0",
81
+ "jiti": "^2.6.1",
82
+ "prettier": "^3.8.1",
83
+ "tsup": "^8.5.1",
84
+ "typescript": "^5.9.3",
85
+ "typescript-eslint": "^8.55.0",
86
+ "vitest": "^4.0.18"
87
+ }
88
+ }