Repository: reata/sqllineage (python)

Issue:
Tsql table names with square brackets are not resolved correctly
Tsql:
When the same table name or column name has square brackets, the parsing result is considered to be two different objects, but it should actually be the same object.
Is there any configuration where I find that mysql backquotes can be parsed correctly

当相同的表名或列名有方括号时，解析结果认为是两个不同的对象，实际应该为同一个对象。
是有什么配置吗，我发现mysql的反引号是可以正确解析的

**SQL**
```sql
insert into [t1] select id from user_tab;
insert into t2 select id from t1
```

**shell**
```shell
sqllineage -e "insert into [t1] select id from user_tab;insert into t2 select id from t1" -d tsql
```

Current parsing
```
Statements(#): 2
Source Tables:
    <default>.t1
    <default>.user_tab
Target Tables:
    <default>.[t1]
    <default>.t2
```

Correct parsing
```
Statements(#): 2
Source Tables:
    <default>.user_tab
Target Tables:
    <default>.t2
Intermediate Tables:
    <default>.t1
```

**Python version (available via `python --version`)**
 - 3.12.1

**SQLLineage version (available via `sqllineage --version`):**
 - 1.5.1


Pull request:
fix: allow tsql identifier enclosed in brackets
Closes #583 

Patch:
diff --git a/sqllineage/utils/helpers.py b/sqllineage/utils/helpers.py
index e403ba7..df9c3ed 100644
--- a/sqllineage/utils/helpers.py
+++ b/sqllineage/utils/helpers.py
@@ -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()
 


Test patch:
diff --git a/tests/sql/table/test_select_dialect_specific.py b/tests/sql/table/test_select_dialect_specific.py
index 9755fa5..c53fc34 100644
--- a/tests/sql/table/test_select_dialect_specific.py
+++ b/tests/sql/table/test_select_dialect_specific.py
@@ -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(