Skip to content

Commit

Permalink
Fix mysql g4 file (apache#8446)
Browse files Browse the repository at this point in the history
* fix mysql g4 file

* fix

* add some testcase
  • Loading branch information
jingshanglu authored Dec 1, 2020
1 parent a62d3da commit 6dabf07
Show file tree
Hide file tree
Showing 20 changed files with 271 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ nullValueLiterals
;

collationName
: identifier | STRING_ | BINARY
: textOrIdentifier | BINARY
;

identifier
Expand Down Expand Up @@ -152,6 +152,14 @@ variable
: (AT_? AT_)? scope? DOT_? internalVariableName
;

userVariable
: AT_ textOrIdentifier
;

systemVariable
: AT_ AT_ scope? textOrIdentifier (DOT_ identifier)?
;

scope
: GLOBAL | PERSIST | PERSIST_ONLY | SESSION | LOCAL
;
Expand All @@ -175,7 +183,7 @@ schemaNames
;

charsetName
: identifier | BINARY | DEFAULT
: textOrIdentifier | BINARY
;

schemaPairs
Expand Down Expand Up @@ -245,8 +253,8 @@ name
: identifier
;

tableNames
: LP_? tableName (COMMA_ tableName)* RP_?
tableList
: tableName (COMMA_ tableName)*
;

viewNames
Expand Down Expand Up @@ -317,6 +325,10 @@ triggerTime
: BEFORE | AFTER
;

tableOrTables
: TABLE | TABLES
;

userOrRole
: userName | roleName
;
Expand Down Expand Up @@ -765,11 +777,11 @@ collectionOptions
;

characterSet
: charset EQ_? charsetName
: charset charsetName
;

collateClause
: COLLATE EQ_? collationName
: COLLATE collationName
;

ignoredIdentifier
Expand Down Expand Up @@ -820,3 +832,21 @@ noWriteToBinLog
: LOCAL
| NO_WRITE_TO_BINLOG
;

channelOption
: FOR CHANNEL STRING_
;

preparedStatement
: PREPARE identifier FROM (stringLiterals | userVariable)
| executeStatement
| (DEALLOCATE | DROP) PREPARE identifier
;

executeStatement
: EXECUTE identifier (USING executeVarList)?
;

executeVarList
: userVariable (COMMA_ userVariable)*
;
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ showCreateTable
: SHOW CREATE TABLE tableName
;

showOther
: SHOW
;

fromSchema
: (FROM | IN) schemaName
;
Expand Down Expand Up @@ -239,22 +235,30 @@ setCharacter
;

setName
: SET NAMES (charsetName (COLLATE collationName)? | DEFAULT)
: SET NAMES (EQ_ expr | charsetName collateClause? | DEFAULT)
;

clone
: CLONE cloneAction
;

cloneAction
: LOCAL DATA DIRECTORY EQ_? cloneDir SEMI_
: LOCAL DATA DIRECTORY EQ_? cloneDir
| INSTANCE FROM cloneInstance IDENTIFIED BY STRING_ (DATA DIRECTORY EQ_? cloneDir)? (REQUIRE NO? SSL)?
;

createUdf
: CREATE AGGREGATE? FUNCTION functionName RETURNS (STRING | INTEGER | REAL | DECIMAL) SONAME shardLibraryName
;

install
: installComponent | installPlugin
;

uninstall
:uninstallComponent | uninstallPlugin
;

installComponent
: INSTALL COMPONENT componentName (COMMA_ componentName)*
;
Expand All @@ -272,28 +276,31 @@ uninstallPlugin
;

analyzeTable
: ANALYZE (NO_WRITE_TO_BINLOG | LOCAL)? TABLE (tableNames
| tableName UPDATE HISTOGRAM ON columnNames (WITH NUMBER_ BUCKETS)
| tableName DROP HISTOGRAM ON columnNames)
: ANALYZE (NO_WRITE_TO_BINLOG | LOCAL)? tableOrTables tableList histogram?
;

histogram
: UPDATE HISTOGRAM ON columnNames (WITH NUMBER_ BUCKETS)?
| DROP HISTOGRAM ON columnNames
;

checkTable
: CHECK TABLE tableNames checkTableOption
: CHECK tableOrTables tableList checkTableOption?
;

checkTableOption
: FOR UPGRADE | QUICK | FAST | MEDIUM | EXTENDED | CHANGE
;

checksumTable
: CHECKSUM TABLE tableNames (QUICK | EXTENDED)
: CHECKSUM tableOrTables tableList (QUICK | EXTENDED)?
;
optimizeTable
: OPTIMIZE (NO_WRITE_TO_BINLOG | LOCAL)? TABLE tableNames
: OPTIMIZE (NO_WRITE_TO_BINLOG | LOCAL)? tableOrTables tableList
;

repairTable
: REPAIR (NO_WRITE_TO_BINLOG | LOCAL)? TABLE tableNames QUICK? EXTENDED? USE_FRM?
: REPAIR (NO_WRITE_TO_BINLOG | LOCAL)? tableOrTables tableList QUICK? EXTENDED? USE_FRM?
;

alterResourceGroup
Expand Down Expand Up @@ -358,10 +365,12 @@ loadIndexInfo

resetStatement
: RESET resetOption (COMMA_ resetOption)*
| resetPersist
;

resetOption
: MASTER | SLAVE | QUERY CACHE
: MASTER (TO binaryLogFileIndexNumber)?
| SLAVE ALL? channelOption?
;

resetPersist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import Symbol, Keyword, MySQLKeyword, Literals, BaseRule, DMLStatement, DALState
alterStatement
: alterTable
| alterDatabase
| alterFunction
| alterProcedure
| alterFunction
| alterEvent
| alterView
| alterTablespaceInnodb
| alterTablespaceNdb
| alterLogfileGroup
| alterInstance
| alterServer
Expand Down Expand Up @@ -186,7 +187,7 @@ partitionNames
;

dropTable
: DROP TEMPORARY? (TABLE | TABLES) existClause? tableNames restrict?
: DROP TEMPORARY? tableOrTables existClause? tableList restrict?
;

dropIndex
Expand Down Expand Up @@ -220,9 +221,9 @@ alterDatabase
;

createDatabaseSpecification_
: DEFAULT? characterSet
| DEFAULT? COLLATE EQ_? collationName
| DEFAULT? ENCRYPTION EQ_? y_or_n=STRING_
: defaultCollation
| defaultCollation
| defaultEncryption
;

alterDatabaseSpecification_
Expand Down Expand Up @@ -542,7 +543,7 @@ createTableOption
| option = (CHECKSUM | TABLE_CHECKSUM) EQ_? NUMBER_
| option = DELAY_KEY_WRITE EQ_? NUMBER_
| option = ROW_FORMAT EQ_? format = (DEFAULT | DYNAMIC | FIXED | COMPRESSED | REDUNDANT | COMPACT)
| option = UNION EQ_? LP_ tableNames RP_
| option = UNION EQ_? LP_ tableList RP_
| defaultCharset
| defaultCollation
| option = INSERT_METHOD EQ_? method = (NO| FIRST| LAST)
Expand All @@ -556,6 +557,22 @@ createTableOption
| option = SECONDARY_ENGINE_ATTRIBUTE EQ_ jsonAttribute = STRING_
;

createSRSStatement
: CREATE OR REPLACE SPATIAL REFERENCE SYSTEM NUMBER_ srsAttribute*
| CREATE SPATIAL REFERENCE SYSTEM notExistClause? NUMBER_ srsAttribute*
;

dropSRSStatement
: DROP SPATIAL REFERENCE SYSTEM notExistClause? NUMBER_
;

srsAttribute
: NAME STRING_
| DEFINITION STRING_
| ORGANIZATION STRING_ IDENTIFIED BY NUMBER_
| DESCRIPTION STRING_
;

place
: FIRST | AFTER columnName
;
Expand Down Expand Up @@ -742,9 +759,10 @@ declareHandlerStatement
;

getDiagnosticsStatement
: GET (CURRENT | STACKED)? DIAGNOSTICS
((statementInformationItem (COMMA_ statementInformationItem)*)
| (CONDITION conditionNumber conditionInformationItem (COMMA_ conditionInformationItem)*))
: GET (CURRENT | STACKED)? DIAGNOSTICS (
(statementInformationItem (COMMA_ statementInformationItem)*
| (CONDITION conditionNumber conditionInformationItem (COMMA_ conditionInformationItem)*))
)
;

statementInformationItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ importStatement
: IMPORT TABLE FROM STRING_ (COMMA_ STRING_)?
;

loadStatement
: loadDataStatement | loadXmlStatement
;

loadDataStatement
: LOAD DATA
(LOW_PRIORITY | CONCURRENT)? LOCAL?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ grammar RLStatement;

import Symbol, Keyword, MySQLKeyword, Literals, BaseRule;

change
: changeMasterTo | changeReplicationFilter
;

changeMasterTo
: CHANGE MASTER TO masterDefs channelOption?
;
Expand All @@ -35,6 +39,10 @@ stopSlave
: STOP SLAVE threadTypes channelOption*
;

groupReplication
: startGroupReplication | stopGroupReplication
;

startGroupReplication
: START GROUP_REPLICATION
;
Expand All @@ -47,14 +55,6 @@ purgeBinaryLog
: PURGE (BINARY | MASTER) LOGS (TO logName | BEFORE datetimeExpr)
;

resetMaster
: RESET MASTER (TO binaryLogFileIndexNumber)?
;

resetSlave
: RESET SLAVE ALL? channelOption?
;

threadTypes
: threadType+
;
Expand All @@ -74,10 +74,6 @@ connectionOptions
: (USER EQ_ STRING_)? (PASSWORD EQ_ STRING_)? (DEFAULT_AUTH EQ_ STRING_)? (PLUGIN_DIR EQ_ STRING_)?
;

channelOption
: FOR CHANNEL STRING_
;

masterDefs
: masterDef (COMMA_ masterDef)*
;
Expand Down Expand Up @@ -132,8 +128,8 @@ filterDefs
filterDef
: REPLICATE_DO_DB EQ_ LP_ schemaNames? RP_
| REPLICATE_IGNORE_DB EQ_ LP_ schemaNames? RP_
| REPLICATE_DO_TABLE EQ_ LP_ tableNames? RP_
| REPLICATE_IGNORE_TABLE EQ_ LP_ tableNames? RP_
| REPLICATE_DO_TABLE EQ_ LP_ tableList? RP_
| REPLICATE_IGNORE_TABLE EQ_ LP_ tableList? RP_
| REPLICATE_WILD_DO_TABLE EQ_ LP_ wildTables? RP_
| REPLICATE_WILD_IGNORE_TABLE EQ_ LP_ wildTables? RP_
| REPLICATE_REWRITE_DB EQ_ LP_ schemaPairs? RP_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ beginTransaction
;

commit
: COMMIT optionWork? optionChain? optionRelease?
: COMMIT WORK? optionChain? optionRelease?
;

rollback
: ROLLBACK (optionWork? TO SAVEPOINT? identifier | optionWork? optionChain? optionRelease?)
: ROLLBACK (WORK? TO SAVEPOINT? identifier | WORK? optionChain? optionRelease?)
;

savepoint
: SAVEPOINT identifier
;

begin
: BEGIN optionWork?
: BEGIN WORK?
;

lock
Expand All @@ -64,12 +64,13 @@ releaseSavepoint
;

xa
: (START | BEGIN) xid (JOIN | RESUME)
| END xid (SUSPEND (FOR MIGRATE)?)?
| PREPARE xid
| COMMIT xid (ONE PHASE)?
| ROLLBACK xid
| RECOVER (CONVERT xid)?
: XA ((START | BEGIN) xid (JOIN | RESUME)
| END xid (SUSPEND (FOR MIGRATE)?)?
| PREPARE xid
| COMMIT xid (ONE PHASE)?
| ROLLBACK xid
| RECOVER (CONVERT xid)?
)
;

transactionCharacteristic
Expand All @@ -84,10 +85,6 @@ accessMode
: READ (WRITE | ONLY)
;

optionWork
: WORK
;

optionChain
: AND NO? CHAIN
;
Expand Down
Loading

0 comments on commit 6dabf07

Please sign in to comment.