22 * Licensed under the Apache License, Version 2.0 (the "License");
33 * you may not use this file except in compliance with the License.
44 * You may obtain a copy of the License at
5+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6+ * in compliance with the License. You may obtain a copy of the License at
7+ *
58 *
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.
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software distributed under the License
12+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13+ * or implied. See the License for the specific language governing permissions and limitations under
14+ * the License.
1315 */
1416
1517/* *
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
18+ * This file is an adaptation of trino's
19+ * trino/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4 grammar. Reference:
20+ * https://github.com/trinodb/trino/blob/385/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4
1821 * current version 450
1922 */
2023
@@ -282,19 +285,25 @@ sortItem
282285querySpecification
283286 : KW_SELECT setQuantifier? selectItem (' ,' selectItem)* (KW_FROM relation (' ,' relation)*)? (
284287 whereClause
285- )? (KW_GROUP KW_BY groupBy)? (KW_HAVING having=booleanExpression)? (
286- KW_WINDOW windowDefinition (' ,' windowDefinition)*
287- )?
288+ )? (KW_GROUP KW_BY groupBy)? (havingClause)? (KW_WINDOW windowDefinition (' ,' windowDefinition)*)?
288289 ;
289290
290291whereClause
291292 : KW_WHERE where=booleanExpression
292293 ;
293294
295+ havingClause
296+ : KW_HAVING having=booleanExpression
297+ ;
298+
294299groupBy
295300 : setQuantifier? groupingElement (' ,' groupingElement)*
296301 ;
297302
303+ partitionBy
304+ : expression (' ,' expression)*
305+ ;
306+
298307groupingElement
299308 : groupingSet # singleGroupingSet
300309 | KW_ROLLUP ' (' (groupingSet (' ,' groupingSet)*)? ' )' # rollup
@@ -317,9 +326,9 @@ windowDefinition
317326 ;
318327
319328windowSpecification
320- : (existingWindowName=identifier)? (
321- KW_PARTITION KW_BY partition+=expression (' ,' partition+=expression )*
322- )? ( KW_ORDER KW_BY sortItem ( ' , ' sortItem)*)? windowFrame?
329+ : (existingWindowName=identifier)? (KW_PARTITION KW_BY partitionBy)? (
330+ KW_ORDER KW_BY sortItem (' ,' sortItem )*
331+ )? windowFrame?
323332 ;
324333
325334namedQuery
@@ -385,11 +394,11 @@ listaggCountIndication
385394
386395patternRecognition
387396 : aliasedRelation (
388- KW_MATCH_RECOGNIZE ' (' (
389- KW_PARTITION KW_BY partition+=expression (' ,' partition+=expression )*
390- )? (KW_ORDER KW_BY sortItem (' ,' sortItem )*)? (
391- KW_MEASURES measureDefinition ( ' , ' measureDefinition)*
392- )? rowsPerMatch? ( KW_AFTER KW_MATCH skipTo)? (KW_INITIAL | KW_SEEK )? KW_PATTERN ' (' rowPattern ' )' (
397+ KW_MATCH_RECOGNIZE ' (' (KW_PARTITION KW_BY partitionBy)? (
398+ KW_ORDER KW_BY sortItem (' ,' sortItem )*
399+ )? (KW_MEASURES measureDefinition (' ,' measureDefinition )*)? rowsPerMatch ? (
400+ KW_AFTER KW_MATCH skipTo
401+ )? (KW_INITIAL | KW_SEEK )? KW_PATTERN ' (' rowPattern ' )' (
393402 KW_SUBSET subsetDefinition (' ,' subsetDefinition)*
394403 )? KW_DEFINE variableDefinition (' ,' variableDefinition)* ' )' (KW_AS ? identifier columnAliases?)?
395404 )?
@@ -504,7 +513,7 @@ tableFunctionArgument
504513 ;
505514
506515tableArgument
507- : tableArgumentRelation (KW_PARTITION KW_BY (' (' (expression ( ' , ' expression)*) ? ' )' | expression))? (
516+ : tableArgumentRelation (KW_PARTITION KW_BY (' (' partitionBy ? ' )' | expression))? (
508517 KW_PRUNE KW_WHEN KW_EMPTY
509518 | KW_KEEP KW_WHEN KW_EMPTY
510519 )? (KW_ORDER KW_BY (' (' sortItem (' ,' sortItem)* ' )' | sortItem))?
0 commit comments