-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configurably support split tsql without semicolon
- Loading branch information
Showing
10 changed files
with
136 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
|
||
|
||
class _SQLLineageConfigLoader: | ||
""" | ||
Load all configurable items from environment variable, otherwise fallback to default | ||
""" | ||
|
||
# inspired by https://github.com/joke2k/django-environ | ||
config = { | ||
# for frontend directory drawer | ||
"DIRECTORY": (str, os.path.join(os.path.dirname(__file__), "data")), | ||
# to enable tsql no semicolon splitter mode | ||
"TSQL_NO_SEMICOLON": (bool, False), | ||
} | ||
|
||
def __getattr__(self, item): | ||
if item in self.config: | ||
type_, default = self.config[item] | ||
# require SQLLINEAGE_ prefix from environment variable | ||
return type_(os.environ.get("SQLLINEAGE_" + item, default)) | ||
else: | ||
return super().__getattribute__(item) | ||
|
||
|
||
SQLLineageConfig = _SQLLineageConfigLoader() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from tests.helpers import assert_table_lineage_equal | ||
|
||
|
||
@patch("os.environ", {"SQLLINEAGE_TSQL_NO_SEMICOLON": "TRUE"}) | ||
@pytest.mark.parametrize("dialect", ["tsql"]) | ||
def test_tsql_multi_statement_no_semicolon(dialect: str): | ||
""" | ||
tsql multiple statements without explicit semicolon as splitter. | ||
""" | ||
sql = """insert into tab1 select * from foo | ||
insert into tab2 select * from bar""" | ||
assert_table_lineage_equal( | ||
sql, | ||
{"foo", "bar"}, | ||
{"tab1", "tab2"}, | ||
dialect=dialect, | ||
test_sqlparse=False, | ||
) |