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

TSQL PRINT statement parsing #1648

Merged
merged 1 commit into from
Oct 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/sqlfluff/dialects/dialect_tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class StatementSegment(ansi_dialect.get_segment("StatementSegment")): # type: i
Ref("DeclareStatementSegment"),
Ref("SetStatementSegment"),
Ref("AlterTableSwitchStatementSegment"),
Ref("PrintStatementSegment"),
Ref(
"CreateTableAsSelectStatementSegment"
), # Azure Synapse Analytics specific
Expand Down Expand Up @@ -1476,3 +1477,15 @@ class DatePartFunctionNameSegment(BaseSegment):

type = "function_name"
match_grammar = OneOf("DATEADD", "DATEDIFF", "DATEDIFF_BIG", "DATENAME")


@tsql_dialect.segment()
class PrintStatementSegment(BaseSegment):
"""PRINT statement segment."""

type = "print_statement"
match_grammar = Sequence(
"PRINT",
Ref("ExpressionSegment"),
Ref("DelimiterSegment", optional=True),
)
8 changes: 8 additions & 0 deletions test/fixtures/dialects/tsql/print.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DECLARE @TestVal VARCHAR(20) = 'Test Print'


PRINT '#Dates'

PRINT CAST(GETDATE() AS VARCHAR(50));

PRINT @TestVal
58 changes: 58 additions & 0 deletions test/fixtures/dialects/tsql/print.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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: ae5fdbfdc047812dbf5359045d2a417e4e7c09cbe83683737b5e96d1900da119
file:
batch:
- statement:
declare_segment:
keyword: DECLARE
parameter: '@TestVal'
data_type:
identifier: VARCHAR
bracketed:
start_bracket: (
expression:
literal: '20'
end_bracket: )
comparison_operator: '='
literal: "'Test Print'"
- statement:
print_statement:
keyword: PRINT
expression:
literal: "'#Dates'"
- statement:
print_statement:
keyword: PRINT
expression:
function:
function_name:
keyword: CAST
bracketed:
start_bracket: (
expression:
function:
function_name:
function_name_identifier: GETDATE
bracketed:
start_bracket: (
end_bracket: )
keyword: AS
data_type:
identifier: VARCHAR
bracketed:
start_bracket: (
expression:
literal: '50'
end_bracket: )
end_bracket: )
statement_terminator: ;
- statement:
print_statement:
keyword: PRINT
expression:
column_reference:
parameter: '@TestVal'