11/*
2- * Licensed under the Apache License, Version 2.0 (the "License");
3- * you may not use this file except in compliance with the License.
4- * You may obtain a copy of the License at
2+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
3+ * in compliance with the License. You may obtain a copy of the License at
4+ *
55 *
6- * http://www.apache.org/licenses/LICENSE-2.0
7- *
8- * Unless required by applicable law or agreed to in writing, software
9- * distributed under the License is distributed on an "AS IS" BASIS,
10- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11- * See the License for the specific language governing permissions and
12- * limitations under the License.
6+ * http://www.apache.org/licenses/LICENSE-2.0
7+ *
8+ * Unless required by applicable law or agreed to in writing, software distributed under the License
9+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10+ * or implied. See the License for the specific language governing permissions and limitations under
11+ * the License.
1312 */
1413
1514/* *
16- * This file is an adaptation of trino's trino/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4 grammar.
17- * Reference: https://github.com/trinodb/trino/blob/385/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4
15+ * This file is an adaptation of trino's
16+ * trino/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4 grammar. Reference:
17+ * https://github.com/trinodb/trino/blob/385/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4
1818 * current version 450
1919 */
2020
@@ -91,7 +91,7 @@ statement
9191 )* ' )' (KW_COMMENT comment=string)? (KW_WITH properties)? # createTable
9292 | KW_DROP KW_TABLE (KW_IF KW_EXISTS )? tableRef # dropTable
9393 | KW_INSERT KW_INTO tableRef columnList? rootQuery # insertInto
94- | KW_DELETE KW_FROM tableRef (KW_WHERE booleanExpression )? # delete
94+ | KW_DELETE KW_FROM tableRef (KW_WHERE expressionWithCol )? # delete
9595 | KW_TRUNCATE KW_TABLE tableRef # truncateTable
9696 | KW_COMMENT KW_ON KW_TABLE tableRef KW_IS (string | KW_NULL ) # commentTable
9797 | KW_COMMENT KW_ON KW_VIEW viewRef KW_IS (string | KW_NULL ) # commentView
@@ -106,7 +106,7 @@ statement
106106 | KW_ALTER KW_TABLE tableName=tableRef KW_SET KW_PROPERTIES propertyAssignments # setTableProperties
107107 | KW_ALTER KW_TABLE tableName=tableRef KW_EXECUTE procedureName=functionName (
108108 ' (' (callArgument (' ,' callArgument)*)? ' )'
109- )? (KW_WHERE where=booleanExpression )? # tableExecute
109+ )? (KW_WHERE where=expressionWithCol )? # tableExecute
110110 | KW_ANALYZE tableRef (KW_WITH properties)? # analyze
111111 | KW_CREATE (KW_OR KW_REPLACE )? KW_MATERIALIZED KW_VIEW (KW_IF KW_NOT KW_EXISTS )? viewNameCreate (
112112 KW_GRACE KW_PERIOD interval
@@ -185,7 +185,7 @@ statement
185185 | KW_SET KW_PATH pathSpecification # setPath
186186 | KW_SET KW_TIME KW_ZONE ( KW_LOCAL | expression) # setTimeZone
187187 | KW_UPDATE tableRef KW_SET updateAssignment (' ,' updateAssignment)* (
188- KW_WHERE where=booleanExpression
188+ KW_WHERE where=expressionWithCol
189189 )? # update
190190 | KW_MERGE KW_INTO tableRef (KW_AS ? identifier)? KW_USING relation KW_ON expression mergeCase+ # merge
191191 | KW_SHOW KW_COMMENT KW_ON KW_TABLE tableRef # showTableComment // dtstack
@@ -276,14 +276,14 @@ queryPrimary
276276 ;
277277
278278sortItem
279- : (columnRef | expression ) ordering=(KW_ASC | KW_DESC )? (
279+ : (columnRef | expressionWithCol ) ordering=(KW_ASC | KW_DESC )? (
280280 KW_NULLS nullOrdering=(KW_FIRST | KW_LAST )
281281 )?
282282 ;
283283
284284querySpecification
285285 : KW_SELECT setQuantifier? selectItem (' ,' selectItem)* (KW_FROM relation (' ,' relation)*)? (
286- KW_WHERE where=booleanExpression
286+ KW_WHERE where=expressionWithCol
287287 )? (KW_GROUP KW_BY groupBy)? (KW_HAVING having=booleanExpression)? (
288288 KW_WINDOW windowDefinition (' ,' windowDefinition)*
289289 )?
@@ -307,7 +307,7 @@ groupingSet
307307
308308groupingTerm
309309 : columnRef
310- | expression
310+ | expressionWithCol
311311 ;
312312
313313windowDefinition
@@ -526,6 +526,11 @@ copartitionTables
526526 : ' (' qualifiedName ' ,' qualifiedName (' ,' qualifiedName)* ' )'
527527 ;
528528
529+ expressionWithCol
530+ : columnRef
531+ | booleanExpression
532+ ;
533+
529534expression
530535 : booleanExpression
531536 ;
@@ -765,7 +770,7 @@ whenClause
765770 ;
766771
767772filter
768- : KW_FILTER ' (' KW_WHERE booleanExpression ' )'
773+ : KW_FILTER ' (' KW_WHERE expressionWithCol ' )'
769774 ;
770775
771776mergeCase
0 commit comments