Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MySql] Synchronize grammar and tests; remove Mariadb grammars #4377

Merged
merged 2 commits into from
Jan 17, 2025
Merged
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
4 changes: 4 additions & 0 deletions sql/mariadb/MariaDBLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ STACKED : 'STACKED';
STARTING : 'STARTING';
STATEMENT : 'STATEMENT';
STRAIGHT_JOIN : 'STRAIGHT_JOIN';
SYSTEM : 'SYSTEM';
SYSTEM_TIME : 'SYSTEM_TIME';
TABLE : 'TABLE';
TERMINATED : 'TERMINATED';
THEN : 'THEN';
Expand All @@ -232,6 +234,7 @@ USAGE : 'USAGE';
USE : 'USE';
USING : 'USING';
VALUES : 'VALUES';
VERSIONING : 'VERSIONING';
WHEN : 'WHEN';
WHERE : 'WHERE';
WHILE : 'WHILE';
Expand Down Expand Up @@ -403,6 +406,7 @@ AT : 'AT';
AUTHORS : 'AUTHORS';
AUTOCOMMIT : 'AUTOCOMMIT';
AUTOEXTEND_SIZE : 'AUTOEXTEND_SIZE';
AUTO : 'AUTO';
AUTO_INCREMENT : 'AUTO_INCREMENT';
AVG_ROW_LENGTH : 'AVG_ROW_LENGTH';
BEGIN : 'BEGIN';
Expand Down
27 changes: 24 additions & 3 deletions sql/mariadb/MariaDBParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ tableOption
| tablespaceStorage # tableOptionTablespace
| TRANSACTIONAL '='? ('0' | '1') # tableOptionTransactional
| UNION '='? '(' tables ')' # tableOptionUnion
| WITH SYSTEM VERSIONING # tableOptionWithSystemVersioning // MariaDB-specific only
;

tableType
Expand All @@ -595,6 +596,19 @@ partitionFunctionDefinition
| LINEAR? KEY (ALGORITHM '=' algType = ('1' | '2'))? '(' uidList ')' # partitionFunctionKey
| RANGE ('(' expression ')' | COLUMNS '(' uidList ')') # partitionFunctionRange
| LIST ('(' expression ')' | COLUMNS '(' uidList ')') # partitionFunctionList
| SYSTEM_TIME (expression | LIMIT expression) (
STARTS (TIMESTAMP timestampValue | timestampValue)
)? AUTO? partitionSystemVersionDefinitions? # partitionSystemVersion // MariaDB-specific
;

// MariaDB-specific
partitionSystemVersionDefinitions
: '(' partitionSystemVersionDefinition (',' partitionSystemVersionDefinition)* ')'
;

// MariaDB-specific
partitionSystemVersionDefinition
: PARTITION uid (HISTORY | CURRENT)
;

subpartitionFunctionDefinition
Expand Down Expand Up @@ -709,7 +723,8 @@ alterSpecification
| ADD indexFormat = (INDEX | KEY) ifNotExists? uid? indexType? // here ifNotExists is MariaDB-specific only
indexColumnNames indexOption* # alterByAddIndex
| ADD (CONSTRAINT name = uid?)? PRIMARY KEY index = uid? indexType? indexColumnNames indexOption* # alterByAddPrimaryKey
| ADD (CONSTRAINT name = uid?)? UNIQUE indexFormat = (INDEX | KEY)? ifNotExists? indexName = uid? indexType? indexColumnNames indexOption* #alterByAddUniqueKey
| ADD (CONSTRAINT name = uid?)? UNIQUE indexFormat = (INDEX | KEY)? ifNotExists? indexName = uid? indexType? indexColumnNames indexOption* #
alterByAddUniqueKey
| ADD keyType = (FULLTEXT | SPATIAL) indexFormat = (INDEX | KEY)? uid? indexColumnNames indexOption* # alterByAddSpecialIndex
| ADD (CONSTRAINT name = uid?)? FOREIGN KEY ifNotExists? // here ifNotExists is MariaDB-specific only
indexName = uid? indexColumnNames referenceDefinition # alterByAddForeignKey
Expand Down Expand Up @@ -1662,7 +1677,7 @@ privilege
: ALL PRIVILEGES?
| ALTER ROUTINE?
| CREATE (TEMPORARY TABLES | ROUTINE | VIEW | USER | TABLESPACE | ROLE)?
| DELETE
| DELETE (HISTORY)? // HISTORY is MariaDB-specific
| DROP (ROLE)?
| EVENT
| EXECUTE
Expand Down Expand Up @@ -2304,10 +2319,15 @@ dataType
) # spatialDataType
| typeName = LONG VARCHAR? BINARY? (charSet charsetName)? (COLLATE collationName)? # longVarcharDataType // LONG VARCHAR is the same as LONG
| LONG VARBINARY # longVarbinaryDataType
| UUID # uuidDataType // MariaDB-specific only
;

collectionOptions
: '(' STRING_LITERAL (',' STRING_LITERAL)* ')'
: '(' collectionOption (',' collectionOption)* ')'
;

collectionOption
: STRING_LITERAL
;

convertedDataType
Expand Down Expand Up @@ -3227,6 +3247,7 @@ keywordsCanBeId
| SETVAL
| SKIP_
| STATEMENT
| UUID
| VIA
| MONITOR
| READ_ONLY
Expand Down
9 changes: 5 additions & 4 deletions sql/mysql/Positive-Technologies/MySqlLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ COMMIT : 'COMMIT';
COMPACT : 'COMPACT';
COMPLETION : 'COMPLETION';
COMPRESSED : 'COMPRESSED';
COMPRESSION : 'COMPRESSION';
COMPRESSION : 'COMPRESSION' | QUOTE_SYMB? 'COMPRESSION' QUOTE_SYMB?;
CONCURRENT : 'CONCURRENT';
CONNECT : 'CONNECT';
CONNECTION : 'CONNECTION';
Expand Down Expand Up @@ -1169,6 +1169,7 @@ SUBSTRING_INDEX : 'SUBSTRING_INDEX';
SUBTIME : 'SUBTIME';
SYSTEM_USER : 'SYSTEM_USER';
TAN : 'TAN';
TELEMETRY_LOG_ADMIN : 'TELEMETRY_LOG_ADMIN';
TIMEDIFF : 'TIMEDIFF';
TIMESTAMPADD : 'TIMESTAMPADD';
TIMESTAMPDIFF : 'TIMESTAMPDIFF';
Expand Down Expand Up @@ -1272,9 +1273,9 @@ DECIMAL_LITERAL : DEC_DIGIT+;
HEXADECIMAL_LITERAL : 'X' '\'' (HEX_DIGIT HEX_DIGIT)+ '\'' | '0X' HEX_DIGIT+;

REAL_LITERAL:
DEC_DIGIT* '.' DEC_DIGIT+
(DEC_DIGIT+)? '.' DEC_DIGIT*
| DEC_DIGIT+ '.' EXPONENT_NUM_PART
| DEC_DIGIT* '.' (DEC_DIGIT+ EXPONENT_NUM_PART)
| (DEC_DIGIT+)? '.' (DEC_DIGIT+ EXPONENT_NUM_PART)
| DEC_DIGIT+ EXPONENT_NUM_PART
;
NULL_SPEC_LITERAL : '\\' 'N';
Expand Down Expand Up @@ -1354,4 +1355,4 @@ fragment IP_ADDRESS : [0-9]+ '.' [0-9.]+ | [0-9A-F]* ':' [0-9A-F]* ':' [0

// Last tokens must generate Errors

ERROR_RECONGNIGION: . -> channel(ERRORCHANNEL);
ERROR_RECONGNIGION: . -> channel(ERRORCHANNEL);
82 changes: 47 additions & 35 deletions sql/mysql/Positive-Technologies/MySqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ createLogfileGroup
;

createProcedure
: CREATE ownerStatement? PROCEDURE fullId '(' procedureParameter? (',' procedureParameter)* ')' routineOption* routineBody
: CREATE ownerStatement? PROCEDURE ifNotExists? fullId '(' procedureParameter? (',' procedureParameter)* ')' routineOption* routineBody
;

createFunction
Expand Down Expand Up @@ -286,11 +286,12 @@ createTablespaceNdb
;

createTrigger
: CREATE ownerStatement? TRIGGER ifNotExists? thisTrigger = fullId triggerTime = (BEFORE | AFTER) triggerEvent = (
INSERT
| UPDATE
| DELETE
) ON tableName FOR EACH ROW (triggerPlace = (FOLLOWS | PRECEDES) otherTrigger = fullId)? routineBody
: CREATE ownerStatement? TRIGGER ifNotExists? thisTrigger = fullId triggerTime = (
BEFORE
| AFTER
) triggerEvent = (INSERT | UPDATE | DELETE) ON tableName FOR EACH ROW (
triggerPlace = (FOLLOWS | PRECEDES) otherTrigger = fullId
)? routineBody
;

withClause
Expand Down Expand Up @@ -632,7 +633,7 @@ alterServer
;

alterTable
: ALTER intimeAction = (ONLINE | OFFLINE)? IGNORE? TABLE tableName waitNowaitClause? (
: ALTER intimeAction = (ONLINE | OFFLINE)? IGNORE? TABLE tableName (
alterSpecification (',' alterSpecification)*
)? partitionDefinitions?
;
Expand Down Expand Up @@ -685,7 +686,7 @@ alterSpecification
| DROP DEFAULT
) # alterByAlterColumnDefault
| ALTER INDEX uid (VISIBLE | INVISIBLE) # alterByAlterIndexVisibility
| DROP FOREIGN KEY uid # alterByDropForeignKey
| DROP FOREIGN KEY uid dottedId? # alterByDropForeignKey
| DISABLE KEYS # alterByDisableKeys
| ENABLE KEYS # alterByEnableKeys
| RENAME renameFormat = (TO | AS)? (uid | fullId) # alterByRename
Expand Down Expand Up @@ -939,7 +940,7 @@ handlerCloseStatement
;

singleUpdateStatement
: UPDATE priority = LOW_PRIORITY? IGNORE? tableName (AS? uid)? SET updatedElement (
: UPDATE priority = LOW_PRIORITY? IGNORE? tableSources (AS? uid)? SET updatedElement (
',' updatedElement
)* (WHERE expression)? orderByClause? limitClause?
;
Expand Down Expand Up @@ -1011,12 +1012,12 @@ queryExpressionNointo
;

querySpecification
: SELECT selectSpec* selectElements selectIntoExpression? fromClause groupByClause? havingClause? windowClause? orderByClause? limitClause?
| SELECT selectSpec* selectElements fromClause groupByClause? havingClause? windowClause? orderByClause? limitClause? selectIntoExpression?
: SELECT selectSpec* selectElements selectIntoExpression? fromClause? groupByClause? havingClause? windowClause? orderByClause? limitClause?
| SELECT selectSpec* selectElements fromClause? groupByClause? havingClause? windowClause? orderByClause? limitClause? selectIntoExpression?
;

querySpecificationNointo
: SELECT selectSpec* selectElements fromClause groupByClause? havingClause? windowClause? orderByClause? limitClause? unionStatement?
: SELECT selectSpec* selectElements fromClause? groupByClause? havingClause? windowClause? orderByClause? limitClause? unionStatement?
;

unionParenthesis
Expand All @@ -1039,7 +1040,7 @@ lateralStatement

// https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
jsonTable
: JSON_TABLE '(' STRING_LITERAL ',' STRING_LITERAL COLUMNS '(' jsonColumnList ')' ')' (AS? uid)?
: JSON_TABLE '(' expression ',' STRING_LITERAL COLUMNS '(' jsonColumnList ')' ')' (AS? uid)?
;

jsonColumnList
Expand Down Expand Up @@ -1171,7 +1172,7 @@ releaseStatement
;

lockTables
: LOCK (TABLE | TABLES) lockTableElement (',' lockTableElement)* waitNowaitClause?
: LOCK (TABLE | TABLES) lockTableElement (',' lockTableElement)*
;

unlockTables
Expand Down Expand Up @@ -1541,16 +1542,17 @@ renameUser
;

revokeStatement
: REVOKE ifExists? (privelegeClause | uid) (',' privelegeClause | uid)*
ON
privilegeObject=(TABLE | FUNCTION | PROCEDURE)?
privilegeLevel
FROM userName (',' userName)* (IGNORE UNKNOWN USER)? #detailRevoke
| REVOKE ifExists? ALL PRIVILEGES? ',' GRANT OPTION
FROM userName (',' userName)* (IGNORE UNKNOWN USER)? #shortRevoke
| REVOKE ifExists? (userName | uid) (',' (userName | uid))*
FROM (userName | uid) (',' (userName | uid))*
(IGNORE UNKNOWN USER)? #roleRevoke
: REVOKE ifExists? (privelegeClause | uid) (',' privelegeClause | uid)* ON privilegeObject = (
TABLE
| FUNCTION
| PROCEDURE
)? privilegeLevel FROM userName (',' userName)* (IGNORE UNKNOWN USER)? # detailRevoke
| REVOKE ifExists? ALL PRIVILEGES? ',' GRANT OPTION FROM userName (',' userName)* (
IGNORE UNKNOWN USER
)? # shortRevoke
| REVOKE ifExists? (userName | uid) (',' (userName | uid))* FROM (userName | uid) (
',' (userName | uid)
)* (IGNORE UNKNOWN USER)? # roleRevoke
;

revokeProxy
Expand Down Expand Up @@ -1681,6 +1683,7 @@ privilege
| SYSTEM_USER
| SYSTEM_VARIABLES_ADMIN
| TABLE_ENCRYPTION_ADMIN
| TELEMETRY_LOG_ADMIN
| TP_CONNECTION_ADMIN
| VERSION_TOKEN_ADMIN
| XA_RECOVER_ADMIN
Expand Down Expand Up @@ -2222,10 +2225,10 @@ dataType
SIGNED
| UNSIGNED
| ZEROFILL
)* # dimensionDataType
| typeName = (DATE | TINYBLOB | MEDIUMBLOB | LONGBLOB | BOOL | BOOLEAN | SERIAL) # simpleDataType
)* # dimensionDataType
| typeName = (DATE | TINYBLOB | MEDIUMBLOB | LONGBLOB | BOOL | BOOLEAN | SERIAL) # simpleDataType
| typeName = (BIT | TIME | TIMESTAMP | DATETIME | BINARY | VARBINARY | BLOB | YEAR | VECTOR) lengthOneDimension? # dimensionDataType
| typeName = (ENUM | SET) collectionOptions BINARY? (charSet charsetName)? # collectionDataType
| typeName = (ENUM | SET) collectionOptions BINARY? (charSet charsetName)? # collectionDataType
| typeName = (
GEOMETRYCOLLECTION
| GEOMCOLLECTION
Expand All @@ -2243,7 +2246,11 @@ dataType
;

collectionOptions
: '(' STRING_LITERAL (',' STRING_LITERAL)* ')'
: '(' collectionOption (',' collectionOption)* ')'
;

collectionOption
: STRING_LITERAL
;

convertedDataType
Expand Down Expand Up @@ -2341,11 +2348,6 @@ orReplace
: OR REPLACE
;

waitNowaitClause
: WAIT decimalLiteral
| NOWAIT
;

// Functions

functionCall
Expand Down Expand Up @@ -2439,7 +2441,7 @@ nonAggregateWindowedFunction
;

overClause
: OVER ('(' windowSpec ')' | windowName)
: OVER ('(' windowSpec? ')' | windowName)
;

windowSpec
Expand Down Expand Up @@ -2715,6 +2717,7 @@ keywordsCanBeId
| AGGREGATE
| ALGORITHM
| ANY
| APPLICATION_PASSWORD_ADMIN
| ARRAY
| AT
| AUDIT_ADMIN
Expand Down Expand Up @@ -2838,11 +2841,16 @@ keywordsCanBeId
| FIRST
| FIXED
| FLUSH
| FLUSH_OPTIMIZER_COSTS
| FLUSH_STATUS
| FLUSH_TABLES
| FLUSH_USER_RESOURCES
| FOLLOWS
| FOUND
| FULL
| FUNCTION
| GENERAL
| GEOMETRY
| GLOBAL
| GRANTS
| GROUP
Expand All @@ -2862,6 +2870,7 @@ keywordsCanBeId
| INDEXES
| INITIAL_SIZE
| INNODB_REDO_LOG_ARCHIVE
| INNODB_REDO_LOG_ENABLE
| INPLACE
| INSERT_METHOD
| INSTALL
Expand Down Expand Up @@ -2934,6 +2943,7 @@ keywordsCanBeId
| MYSQL_ERRNO
| NAME
| NAMES
| NATIONAL
| NCHAR
| NDB_STORED_USER
| NESTED
Expand Down Expand Up @@ -3082,10 +3092,12 @@ keywordsCanBeId
| SWAPS
| SWITCHES
| SYSTEM_VARIABLES_ADMIN
| SYSTEM_USER
| TABLE_NAME
| TABLESPACE
| TABLE_ENCRYPTION_ADMIN
| TABLE_TYPE
| TELEMETRY_LOG_ADMIN
| TEMPORARY
| TEMPTABLE
| THAN
Expand Down Expand Up @@ -3497,4 +3509,4 @@ functionNameBase
| JSON_ARRAYAGG
| JSON_OBJECTAGG
| STATEMENT
;
;
Loading
Loading