Skip to content

Commit

Permalink
feat: trigger warning for tsql not using semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
reata committed Aug 13, 2023
1 parent 3c70f29 commit 0162194
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sqllineage/core/parser/sqlfluff/analyzer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

from sqlfluff.core import Linter, SQLLexError, SQLParseError

from sqllineage.core.analyzer import LineageAnalyzer
Expand Down Expand Up @@ -39,7 +41,15 @@ def analyze(self, sql: str) -> StatementLineageHolder:
statement_segment = top_segment.segments[0]
break
elif top_segment.type == "batch":
statement_segment = top_segment.get_child("statement").segments[0]
statements = top_segment.get_children("statement")
if len(statements) > 1:
warnings.warn(
"SQL statements is not split by semicolon. "
"SQLLineage is not guaranteed to generate correct result under this circumstances.",
SyntaxWarning,
stacklevel=2,
)
statement_segment = statements[0].segments[0]
break
if statement_segment is None:
raise UnsupportedStatementException(
Expand Down
11 changes: 11 additions & 0 deletions tests/core/test_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,14 @@ def test_deprecated_warning_in_sqlparse():
LineageRunner("SELECT * FROM DUAL", dialect="non-validating")._eval()
assert len(w) == 1
assert issubclass(w[0].category, DeprecationWarning)


def test_syntax_warning_no_semicolon_in_tsql():
with warnings.catch_warnings(record=True) as w:
LineageRunner(
"""SELECT * FROM foo
SELECT * FROM bar""",
dialect="tsql",
)._eval()
assert len(w) == 1
assert issubclass(w[0].category, SyntaxWarning)

0 comments on commit 0162194

Please sign in to comment.