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
TSQL: fix statement delimitation #1612
TSQL: fix statement delimitation #1612
Conversation
…Delimitation # Conflicts: # test/fixtures/dialects/tsql/begin_end_no_semicolon.sql # test/fixtures/dialects/tsql/begin_end_no_semicolon.yml
Codecov Report
@@ Coverage Diff @@
## main #1612 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 131 131
Lines 9184 9208 +24
=========================================
+ Hits 9184 9208 +24
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. One suggestion.
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
* Fix Statement Delimitation Issue * Fix Statement Delimitation Issue * Fix Statement Delimitation Issue * Fix Statement Delimitation Issue * Fix Statement Delimitation Issue * black * Fix Statement Delimitation Issue * Fix Statement Delimitation Issue * black * Fix Statement Delimitation Issue * Fix Statement Delimitation Issue * Fix Statement Delimitation Issue * Fix Statement Delimitation Issue * Update src/sqlfluff/dialects/dialect_tsql.py Co-authored-by: Barry Pollard <barry_pollard@hotmail.com> * Fix Statement Delimitation Issue * Fix Statement Delimitation Issue * Fix Statement Delimitation Issue * Apply suggestions from code review Co-authored-by: Barry Pollard <barry_pollard@hotmail.com> * Fix Statement Delimitation Issue Co-authored-by: jpersons <jpersons@iuhealth.org> Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Fixes #1581
Fixes #1555
The TSQL dialect allows for optional semicolon delimiters between statements. Since they are optional, we cannot rely on them to delimit the codebase. This code change removes all places where we assume semicolons will delimit and replaces them with optional references.
As part of this I discovered a bug with MetaSegment. If a MetaSegment leads a Sequence (as in FromExpressionSegment) it might be queried as to whether it is simple. The simple() function calls match() by default, which does not exist for MetaSegment. I added a simple() function override in MetaSegment which returns None.
TSQL changes:
+SelectClauseSegmentGrammar to override ANSI standard and remove delimitation logic that assumes the statements have been delimited
+SelectClauseElementSegment to override ANSI standard and remove GreedyUntil that assumes the statements have been delimited
+SelectClauseSegment to override ANSI standard and remove StartsWith logic that assumes the statements have been delimited
+DeleteStatementSegment to override ANSI standard and remove StartsWith logic that assumes the statements have been delimited
+FromClauseSegment to override ANSI standard and remove Delimited logic that assumes the statements have been delimited
+OrderByClauseSegment to override ANSI standard and remove StartsWith logic that assumes the statements have been delimited
Adjust SelectStatementSegment to allow for an optional semi-colon instead of an expected one.
Adjust CreateIndexStatementSegment to allow for an optional semi-colon instead of an expected one.
Adjust PivotUnpivotStatementSegment to remove StartsWith logic that assumes the statements have been delimited
Adjust CreateProcedureStatementSegment to remove StartsWith logic that assumes the statements have been delimited
Adjust CreateViewStatementSegment to allow for an optional semi-colon instead of an expected one.
Adjust CreateTableStatementSegment to allow for an optional semi-colon instead of an expected one.
Adjust TransactionStatementSegment to allow for an optional semi-colon instead of an expected one.
Adjust BatchSegment to clearly delineate logic between statements which can be bundled and statements which can't
Adjust BeginEndSegment to only include statements which can be bundled. As a result, we remove the reference to BatchSegment
+begin_end_no_semicolon test case to confirm that statements are parsed properly without semicolons
Adjust various test case YML scripts to reflect the changes above
meta.py changes:
import ParseContext, Optional, and List
Override simple() to return None instead of attempting to call match()