Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/grammar/trino/TrinoSql.g4
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/**
* This file is an adaptation of trino's trino/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4 grammar.
* Reference: https://github.com/trinodb/trino/blob/385/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4
* This file is an adaptation of trino's
* trino/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4 grammar. Reference:
* https://github.com/trinodb/trino/blob/385/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4
* current version 450
*/

Expand Down Expand Up @@ -330,9 +330,9 @@ setQuantifier
;

selectItem
: (columnRef | expression) (KW_AS? alias=identifier)? # selectSingle
: ASTERISK # selectAll
| primaryExpression '.' ASTERISK (KW_AS columnAliases)? # selectAll
| ASTERISK # selectAll
| (columnRef | expression) (KW_AS? alias=identifier)? # selectSingle
;

relation
Expand Down Expand Up @@ -561,7 +561,7 @@ valueExpression
primaryExpression
: KW_NULL # nullLiteral
| interval # intervalLiteral
| identifier string # typeConstructor
| columnName string # typeConstructor
| KW_DOUBLE KW_PRECISION string # typeConstructor
| number # numericLiteral
| booleanValue # booleanLiteral
Expand Down Expand Up @@ -590,7 +590,7 @@ primaryExpression
| KW_TRY_CAST '(' expression KW_AS type ')' # cast
| KW_ARRAY '[' (expression (',' expression)*)? ']' # arrayConstructor
| value=primaryExpression '[' index=valueExpression ']' # subscript
| identifier # columnReference
| columnName # columnReference
| base=primaryExpression '.' fieldName=identifier # dereference
| name=KW_CURRENT_DATE # currentDate
| name=KW_CURRENT_TIME ('(' precision=INTEGER_VALUE ')')? # currentTime
Expand Down Expand Up @@ -1008,6 +1008,10 @@ columnRef
| {this.shouldMatchEmpty()}?
;

columnName
: qualifiedName
;

columnNameCreate
: identifier
;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/trino/TrinoSql.interp

Large diffs are not rendered by default.

29 changes: 20 additions & 9 deletions src/lib/trino/TrinoSqlListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ import { WindowDefinitionContext } from "./TrinoSqlParser.js";
import { WindowSpecificationContext } from "./TrinoSqlParser.js";
import { NamedQueryContext } from "./TrinoSqlParser.js";
import { SetQuantifierContext } from "./TrinoSqlParser.js";
import { SelectSingleContext } from "./TrinoSqlParser.js";
import { SelectAllContext } from "./TrinoSqlParser.js";
import { SelectSingleContext } from "./TrinoSqlParser.js";
import { RelationDefaultContext } from "./TrinoSqlParser.js";
import { JoinRelationContext } from "./TrinoSqlParser.js";
import { JoinTypeContext } from "./TrinoSqlParser.js";
Expand Down Expand Up @@ -355,6 +355,7 @@ import { CatalogNameCreateContext } from "./TrinoSqlParser.js";
import { FunctionNameContext } from "./TrinoSqlParser.js";
import { FunctionNameCreateContext } from "./TrinoSqlParser.js";
import { ColumnRefContext } from "./TrinoSqlParser.js";
import { ColumnNameContext } from "./TrinoSqlParser.js";
import { ColumnNameCreateContext } from "./TrinoSqlParser.js";
import { QualifiedNameContext } from "./TrinoSqlParser.js";
import { QueryPeriodContext } from "./TrinoSqlParser.js";
Expand Down Expand Up @@ -1839,29 +1840,29 @@ export class TrinoSqlListener implements ParseTreeListener {
*/
exitSetQuantifier?: (ctx: SetQuantifierContext) => void;
/**
* Enter a parse tree produced by the `selectSingle`
* Enter a parse tree produced by the `selectAll`
* labeled alternative in `TrinoSqlParser.selectItem`.
* @param ctx the parse tree
*/
enterSelectSingle?: (ctx: SelectSingleContext) => void;
enterSelectAll?: (ctx: SelectAllContext) => void;
/**
* Exit a parse tree produced by the `selectSingle`
* Exit a parse tree produced by the `selectAll`
* labeled alternative in `TrinoSqlParser.selectItem`.
* @param ctx the parse tree
*/
exitSelectSingle?: (ctx: SelectSingleContext) => void;
exitSelectAll?: (ctx: SelectAllContext) => void;
/**
* Enter a parse tree produced by the `selectAll`
* Enter a parse tree produced by the `selectSingle`
* labeled alternative in `TrinoSqlParser.selectItem`.
* @param ctx the parse tree
*/
enterSelectAll?: (ctx: SelectAllContext) => void;
enterSelectSingle?: (ctx: SelectSingleContext) => void;
/**
* Exit a parse tree produced by the `selectAll`
* Exit a parse tree produced by the `selectSingle`
* labeled alternative in `TrinoSqlParser.selectItem`.
* @param ctx the parse tree
*/
exitSelectAll?: (ctx: SelectAllContext) => void;
exitSelectSingle?: (ctx: SelectSingleContext) => void;
/**
* Enter a parse tree produced by the `relationDefault`
* labeled alternative in `TrinoSqlParser.relation`.
Expand Down Expand Up @@ -4332,6 +4333,16 @@ export class TrinoSqlListener implements ParseTreeListener {
* @param ctx the parse tree
*/
exitColumnRef?: (ctx: ColumnRefContext) => void;
/**
* Enter a parse tree produced by `TrinoSqlParser.columnName`.
* @param ctx the parse tree
*/
enterColumnName?: (ctx: ColumnNameContext) => void;
/**
* Exit a parse tree produced by `TrinoSqlParser.columnName`.
* @param ctx the parse tree
*/
exitColumnName?: (ctx: ColumnNameContext) => void;
/**
* Enter a parse tree produced by `TrinoSqlParser.columnNameCreate`.
* @param ctx the parse tree
Expand Down
Loading