Skip to content

Commit

Permalink
Merge branch 'main' into snowflake_transaction_statements
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb committed Dec 26, 2021
2 parents 963f006 + 909bd57 commit 3894b03
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/sqlfluff/dialects/dialect_mysql.py
Expand Up @@ -99,6 +99,7 @@
"NONE",
"SHARED",
"EXCLUSIVE",
"MASTER",
]
)

Expand Down Expand Up @@ -134,6 +135,22 @@
Ref("LocalVariableNameSegment"),
]
),
DateTimeLiteralGrammar=Sequence(
# MySQL does not require the keyword to be specified:
# https://dev.mysql.com/doc/refman/8.0/en/date-and-time-literals.html
OneOf(
"DATE",
"TIME",
"TIMESTAMP",
"DATETIME",
"INTERVAL",
optional=True,
),
OneOf(
Ref("QuotedLiteralSegment"),
Ref("NumericLiteralSegment"),
),
),
)

mysql_dialect.add(
Expand Down Expand Up @@ -434,6 +451,9 @@ class StatementSegment(ansi_dialect.get_segment("StatementSegment")): # type: i
Ref("CursorOpenCloseSegment"),
Ref("CursorFetchSegment"),
Ref("AlterTableStatementSegment"),
Ref("RenameTableStatementSegment"),
Ref("ResetMasterStatementSegment"),
Ref("PurgeBinaryLogsStatementSegment"),
Ref("HelpStatementSegment"),
],
)
Expand Down Expand Up @@ -1323,6 +1343,72 @@ class DropIndexStatementSegment(BaseSegment):
)


@mysql_dialect.segment()
class RenameTableStatementSegment(BaseSegment):
"""A `RENAME TABLE` statement.
https://dev.mysql.com/doc/refman/8.0/en/rename-table.html
"""

type = "rename_table_statement"
match_grammar = Sequence(
"RENAME",
"TABLE",
Delimited(
Sequence(
Ref("TableReferenceSegment"),
"TO",
Ref("TableReferenceSegment"),
),
),
)


@mysql_dialect.segment()
class ResetMasterStatementSegment(BaseSegment):
"""A `RESET MASTER` statement.
https://dev.mysql.com/doc/refman/8.0/en/reset-master.html
"""

type = "reset_master_statement"
match_grammar = Sequence(
"RESET",
"MASTER",
Sequence("TO", Ref("NumericLiteralSegment"), optional=True),
)


@mysql_dialect.segment()
class PurgeBinaryLogsStatementSegment(BaseSegment):
"""A `PURGE BINARY LOGS` statement.
https://dev.mysql.com/doc/refman/8.0/en/purge-binary-logs.html
"""

type = "purge_binary_logs_statement"
match_grammar = Sequence(
"PURGE",
OneOf(
"BINARY",
"MASTER",
),
"LOGS",
OneOf(
Sequence(
"TO",
Ref("QuotedLiteralSegment"),
),
Sequence(
"BEFORE",
OneOf(
Ref("DateTimeLiteralGrammar"),
),
),
),
)


@mysql_dialect.segment()
class HelpStatementSegment(BaseSegment):
"""A `HELP` statement.
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/dialects/mysql/purge_binary_logs.sql
@@ -0,0 +1,9 @@
PURGE BINARY LOGS TO 'mysql-bin.010';

PURGE BINARY LOGS BEFORE '2019-04-02 22:46:26';
PURGE BINARY LOGS BEFORE DATETIME '2019-04-02 22:46:26';
PURGE BINARY LOGS BEFORE TIMESTAMP '2019-04-02 22:46:26';

PURGE BINARY LOGS BEFORE 19830905132800;
PURGE BINARY LOGS BEFORE DATETIME 19830905132800;
PURGE BINARY LOGS BEFORE TIMESTAMP 19830905132800;
67 changes: 67 additions & 0 deletions test/fixtures/dialects/mysql/purge_binary_logs.yml
@@ -0,0 +1,67 @@
# YML test files are auto-generated from SQL files and should not be edited by
# hand. To help enforce this, the "hash" field in the file must match a hash
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: fd25d700f1df99b7fc2fb7ee7027f66c180d3cfe7723d0c80eddec684c8eb0f1
file:
- statement:
purge_binary_logs_statement:
- keyword: PURGE
- keyword: BINARY
- keyword: LOGS
- keyword: TO
- literal: "'mysql-bin.010'"
- statement_terminator: ;
- statement:
purge_binary_logs_statement:
- keyword: PURGE
- keyword: BINARY
- keyword: LOGS
- keyword: BEFORE
- literal: "'2019-04-02 22:46:26'"
- statement_terminator: ;
- statement:
purge_binary_logs_statement:
- keyword: PURGE
- keyword: BINARY
- keyword: LOGS
- keyword: BEFORE
- keyword: DATETIME
- literal: "'2019-04-02 22:46:26'"
- statement_terminator: ;
- statement:
purge_binary_logs_statement:
- keyword: PURGE
- keyword: BINARY
- keyword: LOGS
- keyword: BEFORE
- keyword: TIMESTAMP
- literal: "'2019-04-02 22:46:26'"
- statement_terminator: ;
- statement:
purge_binary_logs_statement:
- keyword: PURGE
- keyword: BINARY
- keyword: LOGS
- keyword: BEFORE
- literal: '19830905132800'
- statement_terminator: ;
- statement:
purge_binary_logs_statement:
- keyword: PURGE
- keyword: BINARY
- keyword: LOGS
- keyword: BEFORE
- keyword: DATETIME
- literal: '19830905132800'
- statement_terminator: ;
- statement:
purge_binary_logs_statement:
- keyword: PURGE
- keyword: BINARY
- keyword: LOGS
- keyword: BEFORE
- keyword: TIMESTAMP
- literal: '19830905132800'
- statement_terminator: ;
2 changes: 2 additions & 0 deletions test/fixtures/dialects/mysql/rename_table.sql
@@ -0,0 +1,2 @@
RENAME TABLE old_table TO new_table;
RENAME TABLE old_table1 TO new_table1, old_table2 TO new_table2;
33 changes: 33 additions & 0 deletions test/fixtures/dialects/mysql/rename_table.yml
@@ -0,0 +1,33 @@
# YML test files are auto-generated from SQL files and should not be edited by
# hand. To help enforce this, the "hash" field in the file must match a hash
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: 35d8fe3a09bff9c94b970575e42ed1151b0da0a2c8627f21a8d98725ffebc9dd
file:
- statement:
rename_table_statement:
- keyword: RENAME
- keyword: TABLE
- table_reference:
identifier: old_table
- keyword: TO
- table_reference:
identifier: new_table
- statement_terminator: ;
- statement:
rename_table_statement:
- keyword: RENAME
- keyword: TABLE
- table_reference:
identifier: old_table1
- keyword: TO
- table_reference:
identifier: new_table1
- comma: ','
- table_reference:
identifier: old_table2
- keyword: TO
- table_reference:
identifier: new_table2
- statement_terminator: ;
2 changes: 2 additions & 0 deletions test/fixtures/dialects/mysql/reset_master.sql
@@ -0,0 +1,2 @@
RESET MASTER;
RESET MASTER TO 1234;
19 changes: 19 additions & 0 deletions test/fixtures/dialects/mysql/reset_master.yml
@@ -0,0 +1,19 @@
# YML test files are auto-generated from SQL files and should not be edited by
# hand. To help enforce this, the "hash" field in the file must match a hash
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: ac03a8182b993644c46f57e6bd10e8f4ff6d161b4af6f8b47bbd89629afe67a7
file:
- statement:
reset_master_statement:
- keyword: RESET
- keyword: MASTER
- statement_terminator: ;
- statement:
reset_master_statement:
- keyword: RESET
- keyword: MASTER
- keyword: TO
- literal: '1234'
- statement_terminator: ;

0 comments on commit 3894b03

Please sign in to comment.