Skip to content

Commit

Permalink
feat: allow tsql identifier enclosed in brackets (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
reata authored May 24, 2024
1 parent 33b36ee commit 6189d31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sqllineage/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def escape_identifier_name(name: str):
for quote_char in quote_chars:
name = name.strip(quote_char)
return name
elif name.startswith("[") and name.endswith("]"):
# tsql allows quoted identifier with square brackets, see reference
# https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers?view=sql-server-ver16#classes-of-identifiers
return name.strip("[]")
else:
return name.lower()

Expand Down
12 changes: 12 additions & 0 deletions tests/sql/table/test_select_dialect_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ def test_select_with_schema_in_backtick(dialect: str):
)


@pytest.mark.parametrize("dialect", ["tsql"])
def test_select_with_table_name_in_bracket(dialect: str):
assert_table_lineage_equal("SELECT * FROM [tab1]", {"tab1"}, dialect=dialect)


@pytest.mark.parametrize("dialect", ["tsql"])
def test_select_with_schema_in_bracket(dialect: str):
assert_table_lineage_equal(
"SELECT * FROM [schema1].[tab1]", {"schema1.tab1"}, dialect=dialect
)


@pytest.mark.parametrize("dialect", ["databricks", "hive", "sparksql"])
def test_select_left_semi_join(dialect: str):
assert_table_lineage_equal(
Expand Down

0 comments on commit 6189d31

Please sign in to comment.