Skip to content

Commit

Permalink
add back additional ddl g4 rules
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangfengcdt committed Sep 18, 2023
1 parent 3f235b0 commit 4ac2749
Showing 1 changed file with 1 addition and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

grammar DDLStatement;

import BaseRule, DCLStatement;
import BaseRule, DCLStatement, DMLStatement;

createTable
: CREATE createTableSpecification TABLE tableName createSharingClause createDefinitionClause createMemOptimizeClause createParentClause
Expand Down Expand Up @@ -3234,389 +3234,6 @@ materializedViewUsingClause
: ( USING INDEX ( (physicalAttributesClause | TABLESPACE tablespaceName)+ )* | USING NO INDEX)
;

rowLimitingClause
: (OFFSET offset (ROW | ROWS))? (FETCH (FIRST | NEXT) (rowcount | percent PERCENT)? (ROW | ROWS) (ONLY | WITH TIES))?
;

selectSubquery
: (queryBlock | parenthesisSelectSubquery | selectCombineClause) orderByClause? rowLimitingClause
;

selectCombineClause
: ((queryBlock | parenthesisSelectSubquery) orderByClause? rowLimitingClause) ((UNION ALL? | INTERSECT | MINUS) selectSubquery)+
;

parenthesisSelectSubquery
: LP_ selectSubquery RP_
;

queryBlock
: withClause? SELECT duplicateSpecification? selectList selectIntoClause? selectFromClause whereClause? hierarchicalQueryClause? groupByClause? modelClause?
;

selectFromClause
: FROM fromClauseList
;

fromClauseList
: fromClauseOption (COMMA_ fromClauseOption)*
;

fromClauseOption
: joinClause
| LP_ joinClause RP_
| selectTableReference
| inlineAnalyticView
| xmlTable
;

xmlTable
: xmlTableFunction xmlTableFunctionAlias?
;

xmlTableFunctionAlias
: alias
;

inlineAnalyticView
: ANALYTIC VIEW LP_ subavClause RP_ (AS? alias)?
;

subavClause
: USING baseAvName hierarchiesClause? filterClauses? addCalcsClause?
;

addCalcsClause
: ADD MEASURES LP_ calcMeasClause (COMMA_ calcMeasClause)* RP_
;

calcMeasClause
: measName AS LP_ calcMeasExpression RP_
;

calcMeasExpression
: expr
;

hierarchiesClause
: HIERARCHIES LP_ ((alias DOT_)? alias (COMMA_ (alias DOT_)? alias)*)? RP_
;

filterClauses
: FILTER FACT LP_ filterClause (COMMA_ filterClause)* RP_
;

filterClause
: (MEASURES | (alias DOT_)? alias) TO predicate
;

selectIntoClause
: (BULK COLLECT)? INTO variableNames
;

variableNames
: variableName (COMMA_ variableName)*
;

variableName
: identifier | stringLiterals
;

subavFactoringClause
: subavName ANALYTIC VIEW AS LP_ subavClause RP_
;

withClause
: WITH plsqlDeclarations? (subavFactoringClause (COMMA_ subavFactoringClause)*)?
;

plsqlDeclarations
: (functionDeclaration | procedureDeclaration)+
;

functionDeclaration
: functionHeading ((DETERMINISTIC | PIPELINED | PARALLEL_ENABLE | RESULT_CACHE)+)?
;

functionHeading
: FUNCTION functionName (LP_ parameterDeclaration (SQ_ parameterDeclaration)* RP_)? RETURN dataType
;

procedureDeclaration
: procedureHeading procedureProperties
;

procedureHeading
: PROCEDURE procedureName (LP_ parameterDeclaration (SQ_ parameterDeclaration)* RP_)?
;

procedureProperties
: (accessibleByClause | defaultCollationClause | invokerRightsClause)*
;

unqualifiedShorthand
: ASTERISK_
;

selectList
: (unqualifiedShorthand | selectProjection) (COMMA_ selectProjection)*
;

selectProjection
: (queryName | (tableName | viewName | materializedViewName) | alias) DOT_ASTERISK_
| selectProjectionExprClause
;

selectProjectionExprClause
: expr (AS? alias)?
;

hierarchicalQueryClause
: CONNECT BY NOCYCLE? expr (START WITH expr)?
| START WITH expr CONNECT BY NOCYCLE? expr
;

groupByClause
: GROUP BY groupByItem (COMMA_ groupByItem)* havingClause?
;

havingClause
: HAVING expr
;

groupByItem
: rollupCubeClause | groupingSetsClause | expr
;

groupingSetsClause
: GROUPING SETS LP_ (rollupCubeClause | groupingExprList) (COMMA_ (rollupCubeClause | groupingExprList))* RP_
;

groupingExprList
: expressionList (COMMA_ expressionList)*
;

rollupCubeClause
: (ROLLUP | CUBE) LP_ groupingExprList RP_
;

modelClause
: MODEL cellReferenceOptions? returnRowsClause? referenceModel* mainModel
;

returnRowsClause
: RETURN (UPDATED | ALL) ROWS
;

referenceModel
: REFERENCE referenceModelName ON LP_ selectSubquery RP_ modelColumnClauses cellReferenceOptions?
;

mainModel
: (MAIN mainModelName)? modelColumnClauses cellReferenceOptions? modelRulesClause
;

modelColumnClauses
: (PARTITION BY LP_ expr alias? (COMMA_ expr alias?)* RP_)?
DIMENSION BY LP_ expr alias? (COMMA_ expr alias?)* RP_ MEASURES LP_ expr alias? (COMMA_ expr alias?)* RP_
;

modelRulesClause
: (RULES (UPDATE | UPSERT ALL?)? ((AUTOMATIC | SEQUENTIAL) ORDER)? modelIterateClause?)?
LP_ (UPDATE | UPSERT ALL?)? cellAssignment orderByClause? EQ_ modelExpr (COMMA_ (UPDATE | UPSERT ALL?)? cellAssignment orderByClause? EQ_ modelExpr)* RP_
;

modelExpr
: (numberLiterals ASTERISK_)? ((measureColumn LBT_ (condition | expr) (COMMA_ (condition | expr))* RBT_)
| (aggregationFunction LBT_ (((condition | expr) (COMMA_ (condition | expr))*) | (singleColumnForLoop (COMMA_ singleColumnForLoop)*) | multiColumnForLoop) RBT_)
| analyticFunction) (PLUS_ modelExpr | ASTERISK_ numberLiterals (ASTERISK_ modelExpr)?)?
;

cellAssignment
: measureColumn LBT_ (((condition | expr | singleColumnForLoop) (COMMA_ (condition | expr | singleColumnForLoop))*) | multiColumnForLoop) RBT_
;

singleColumnForLoop
: FOR dimensionColumn ((IN LP_ ((literals (COMMA_ literals)*) | selectSubquery) RP_)
| ((LIKE pattern)? FROM literals TO literals (INCREMENT | DECREMENT) literals))
;

multiColumnForLoop
: FOR LP_ dimensionColumn (COMMA_ dimensionColumn)* RP_ IN LP_ (selectSubquery
| LP_ literals (COMMA_ literals)* RP_ (COMMA_ LP_ literals (COMMA_ literals)* RP_)*) RP_
;

modelIterateClause
: ITERATE LP_ numberLiterals RP_ (UNTIL LP_ condition RP_)?
;

cellReferenceOptions
: ((IGNORE | KEEP) NAV)? (UNIQUE (DIMENSION | SINGLE REFERENCE))?
;

joinClause
: selectTableReference selectJoinOption+
;

selectTableReference
: (queryTableExprClause | containersClause | shardsClause) alias?
;

shardsClause
: SHARDS LP_ (tableName | viewName) RP_
;

queryTableExprClause
: (ONLY LP_ queryTableExpr RP_ | queryTableExpr) flashbackQueryClause? (pivotClause | unpivotClause)?
;

pivotClause
: PIVOT XML?
LP_ aggregationFunctionName LP_ expr RP_ (AS? alias)? (COMMA_ aggregationFunctionName LP_ expr RP_ (AS? alias)?)* pivotForClause pivotInClause RP_
;

pivotForClause
: FOR (columnName | columnNames)
;

pivotInClause
: IN LP_ ((expr | exprList) (AS? alias)? (COMMA_ (expr | exprList) (AS? alias)?)*
| selectSubquery
| ANY (COMMA_ ANY)*) RP_
;

unpivotClause
: UNPIVOT ((INCLUDE | EXCLUDE) NULLS)? LP_ (columnName | columnNames) pivotForClause unpivotInClause RP_
;

unpivotInClause
: IN LP_ (columnName | columnNames) (AS (literals | LP_ literals (COMMA_ literals)* RP_))? (COMMA_ (columnName | columnNames) (AS (literals | LP_ literals (COMMA_ literals)* RP_))?)* RP_
;

flashbackQueryClause
: VERSIONS (BETWEEN (SCN | TIMESTAMP) | PERIOD FOR validTimeColumn BETWEEN) (expr | MINVALUE) AND (expr | MAXVALUE)
| AS OF ((SCN | TIMESTAMP) (expr | intervalExprClause) | PERIOD FOR validTimeColumn expr)
;

intervalExprClause
: LP_ SYSTIMESTAMP (PLUS_ | MINUS_) INTERVAL (INTEGER_ | STRING_) (HOUR | MINUTE | SECOND) RP_
;

queryTableExpr
: queryTableExprSampleClause
| queryName
| lateralClause
| tableCollectionExpr
;

tableCollectionExpr
: TABLE LP_ collectionExpr RP_ (LP_ PLUS_ RP_)?
;

collectionExpr
: selectSubquery | columnName | functionCall | expr
;

lateralClause
: LATERAL? LP_ selectSubquery subqueryRestrictionClause? RP_
;

subqueryRestrictionClause
: WITH (READ ONLY | CHECK OPTION) (CONSTRAINT constraintName)?
;

queryTableExprSampleClause
: (queryTableExprTableClause
| queryTableExprViewClause
| hierarchyName
| queryTableExprAnalyticClause
| (owner DOT_)? inlineExternalTable) sampleClause?
;

sampleClause
: SAMPLE BLOCK? LP_ samplePercent RP_ (SEED LP_ seedValue RP_)?
;

inlineExternalTable
: EXTERNAL LP_ LP_ columnDefinition (COMMA_ columnDefinition)* RP_ inlineExternalTableProperties RP_
;

inlineExternalTableProperties
: (TYPE accessDriverType)? externalTableDataProperties (REJECT LIMIT (INTEGER_ | UNLIMITED))?
;

externalTableDataProperties
: (DEFAULT DIRECTORY directoryName)? (ACCESS PARAMETERS ((opaqueFormatSpec) | USING CLOB subquery))?
(LOCATION LP_ (directoryName COLON_)? locationSpecifier (COMMA_ (directoryName COLON_)? locationSpecifier)+ RP_)?
;

queryTableExprTableClause
: tableName (mofifiedExternalTable | partitionExtClause | AT_ dbLink)?
;

partitionExtClause
: PARTITION (LP_ partitionName RP_ | FOR LP_ partitionKeyValue (COMMA_ partitionKeyValue) RP_)
| SUBPARTITION (LP_ subpartitionName RP_ | FOR LP_ subpartitionKeyValue (COMMA_ subpartitionKeyValue) RP_)
;

mofifiedExternalTable
: EXTERNAL MODIFY modifyExternalTableProperties
;

modifyExternalTableProperties
: (DEFAULT DIRECTORY directoryName)? (LOCATION LP_ (directoryName COLON_)? SQ_ locationSpecifier SQ_ (COMMA_ (directoryName COLON_)? SQ_ locationSpecifier SQ_)* RP_)?
(ACCESS PARAMETERS (BADFILE fileName | LOGFILE fileName | DISCARDFILE fileName))? (REJECT LIMIT (INTEGER_ | UNLIMITED))?
;

queryTableExprViewClause
: (viewName | materializedViewName) (AT_ dbLink)?
;

queryTableExprAnalyticClause
: analyticViewName (HIERARCHIES LP_ ((attrDim DOT_)? hierarchyName (COMMA_ (attrDim DOT_)? hierarchyName)*)? RP_)?
;

selectJoinOption
: innerCrossJoinClause
| outerJoinClause
| crossOuterApplyClause
;

innerCrossJoinClause
: INNER? JOIN selectTableReference selectJoinSpecification
| (CROSS | NATURAL INNER?) JOIN selectTableReference
;

selectJoinSpecification
: ON expr | USING columnNames
;

outerJoinClause
: queryPartitionClause? NATURAL? outerJoinType JOIN
selectTableReference queryPartitionClause? selectJoinSpecification?
;

queryPartitionClause
: PARTITION BY (exprs | exprList)
;

outerJoinType
: (FULL | LEFT | RIGHT) OUTER?
;

crossOuterApplyClause
: (CROSS | OUTER) APPLY (selectTableReference | collectionExpr)
;

duplicateSpecification
: (DISTINCT | UNIQUE) | ALL
;

searchClause
: SEARCH (DEPTH | BREADTH) FIRST BY (alias (ASC | DESC)? (NULLS FIRST | NULLS LAST)?) (COMMA_ (alias (ASC | DESC)? (NULLS FIRST | NULLS LAST)?))*
SET orderingColumn
;

mvColumnAlias
: (identifier | quotedString) (ENCRYPT encryptionSpecification)?
;
Expand Down

0 comments on commit 4ac2749

Please sign in to comment.