Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dt-sql-parser",
"version": "4.5.1",
"version": "4.5.2-beta.0",
"authors": "DTStack Corporation",
"description": "SQL Parsers for BigData, built with antlr4",
"keywords": [
Expand Down
10 changes: 7 additions & 3 deletions src/grammar/generic/GenericSql.g4
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ withClause
;

namedQuery
: name=identifier KW_AS '(' queryStatement ')'
: name=identifier cteColumnList? KW_AS '(' queryStatement ')'
;

cteColumnList
: '(' identifier (',' identifier)* ')'
;

queryNoWith
Expand All @@ -82,7 +86,7 @@ setQuantifier
;

selectItem
: expression (KW_AS? identifier)?
: expression (KW_AS? alias=identifier)?
| qualifiedName '.' ASTERISK
| ASTERISK
;
Expand All @@ -105,7 +109,7 @@ joinType
;

aliasedRelation
: relationPrimary (KW_AS? identifier)?
: relationPrimary (KW_AS? alias=identifier)?
;

relationPrimary
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/mysql/MySqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ joinPart
;

joinSpec
: (KW_ON (expression | columnNamePathAllowEmpty))
: (KW_ON ( expression | columnNamePathAllowEmpty (EQUAL_SYMBOL columnNamePathAllowEmpty)?))
| KW_USING '(' columnNames ')'
;

Expand Down
17 changes: 14 additions & 3 deletions src/grammar/postgresql/PostgreSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -2128,12 +2128,12 @@ tableRef
| OPEN_PAREN tableRef (
KW_CROSS KW_JOIN tableRef
| KW_NATURAL joinType? KW_JOIN tableRef
| joinType? KW_JOIN tableRef joinQual
| joinType? KW_JOIN tableRef joinCondition
)? CLOSE_PAREN aliasClause?
) (
KW_CROSS KW_JOIN tableRef
| KW_NATURAL joinType? KW_JOIN tableRef
| joinType? KW_JOIN tableRef joinQual
| joinType? KW_JOIN tableRef joinCondition
)*
;

Expand All @@ -2156,9 +2156,20 @@ joinType
: (KW_FULL | KW_LEFT | KW_RIGHT | KW_INNER) KW_OUTER?
;

// A finished JOIN needs ON or USING. The empty alternative is only for a
// caret sitting after the joined table, so validation still rejects `JOIN b`.
joinCondition
: joinQual
| {this.caretTokenIndex >= 0 && this.shouldMatchEmpty()}? emptyColumn
;

joinQual
: KW_USING optColumnList
| KW_ON expression
| KW_ON (
expression
| columnNamePath (EQUAL columnNamePath)?
| {this.shouldMatchEmpty()}? emptyColumn
)
;

relationExpr
Expand Down
1 change: 1 addition & 0 deletions src/grammar/trino/TrinoSql.g4
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ primaryExpression
| value=primaryExpression '[' index=valueExpression ']' # subscript
| columnName # columnReference
| base=primaryExpression '.' fieldName=identifier # dereference
| base=primaryExpression '.' {this.caretTokenIndex >= 0 && this.shouldMatchEmpty()}? emptyColumn # dereference
| name=KW_CURRENT_DATE # currentDate
| name=KW_CURRENT_TIME ('(' precision=INTEGER_VALUE ')')? # currentTime
| name=KW_CURRENT_TIMESTAMP ('(' precision=INTEGER_VALUE ')')? # currentTimestamp
Expand Down
3 changes: 2 additions & 1 deletion src/lib/generic/GenericSql.interp

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/lib/generic/GenericSqlListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { DropTableContext } from "./GenericSqlParser.js";
import { QueryStatementContext } from "./GenericSqlParser.js";
import { WithClauseContext } from "./GenericSqlParser.js";
import { NamedQueryContext } from "./GenericSqlParser.js";
import { CteColumnListContext } from "./GenericSqlParser.js";
import { QueryNoWithContext } from "./GenericSqlParser.js";
import { QueryTermContext } from "./GenericSqlParser.js";
import { QueryPrimaryContext } from "./GenericSqlParser.js";
Expand Down Expand Up @@ -249,6 +250,16 @@ export class GenericSqlListener implements ParseTreeListener {
* @param ctx the parse tree
*/
exitNamedQuery?: (ctx: NamedQueryContext) => void;
/**
* Enter a parse tree produced by `GenericSqlParser.cteColumnList`.
* @param ctx the parse tree
*/
enterCteColumnList?: (ctx: CteColumnListContext) => void;
/**
* Exit a parse tree produced by `GenericSqlParser.cteColumnList`.
* @param ctx the parse tree
*/
exitCteColumnList?: (ctx: CteColumnListContext) => void;
/**
* Enter a parse tree produced by `GenericSqlParser.queryNoWith`.
* @param ctx the parse tree
Expand Down
Loading
Loading