Repository: reata/sqllineage

Issue:
Support declare statement in tsql dialect
I have a valid tsql script which doesn't work with **tsql** dialect but work with **non-validating** dialect. 

```
from sqllineage.runner import LineageRunner

sql = """

DECLARE @age int = 10;

SELECT Name,@age 
FROM People;

"""

lineage = LineageRunner(sql,dialect="tsql")

print(lineage)

```

The error message shown is 

```
UnsupportedStatementException: SQLLineage doesn't support analyzing statement type [declare_segment] for SQL:DECLARE @age int = 10;
```

It look like the **DECLARE** statement is not supported.  Is there a reason why the **DECLARE** statement is not supported?

When I run the above code in **non-validating** , it work

```
from sqllineage.runner import LineageRunner

sql = """

DECLARE @age int = 10;

SELECT Name,@age 
FROM People;

"""

lineage = LineageRunner(sql,dialect = "non-validating")

print(lineage)

```

Output 

```
Statements(#): 2
Source Tables:
    <default>.people
Target Tables:
```

Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/reata/sqllineage/pull/402?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#402](https://app.codecov.io/gh/reata/sqllineage/pull/402?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (f6404f1) into [master](https://app.codecov.io/gh/reata/sqllineage/commit/c562cceb6054fe0aa065e40da2fac30836dd8b77?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (c562cce) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master     #402   +/-   ##
=======================================
  Coverage   99.40%   99.40%           
=======================================
  Files          42       42           
  Lines        2013     2013           
=======================================
  Hits         2001     2001           
  Misses         12       12           
```


| [Impacted Files](https://app.codecov.io/gh/reata/sqllineage/pull/402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [.../core/parser/sqlfluff/extractors/noop\_extractor.py](https://app.codecov.io/gh/reata/sqllineage/pull/402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3FsbGluZWFnZS9jb3JlL3BhcnNlci9zcWxmbHVmZi9leHRyYWN0b3JzL25vb3BfZXh0cmFjdG9yLnB5) | `100.00% <ø> (ø)` | |
| [sqllineage/core/parser/sqlparse/handlers/source.py](https://app.codecov.io/gh/reata/sqllineage/pull/402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3FsbGluZWFnZS9jb3JlL3BhcnNlci9zcWxwYXJzZS9oYW5kbGVycy9zb3VyY2UucHk=) | `100.00% <ø> (ø)` | |



Patch:
diff --git a/sqllineage/core/parser/sqlfluff/extractors/noop_extractor.py b/sqllineage/core/parser/sqlfluff/extractors/noop_extractor.py
index 3d85024..8db874a 100644
--- a/sqllineage/core/parser/sqlfluff/extractors/noop_extractor.py
+++ b/sqllineage/core/parser/sqlfluff/extractors/noop_extractor.py
@@ -20,6 +20,7 @@ class NoopExtractor(LineageHolderExtractor):
         "uncache_table",
         "show_statement",
         "use_statement",
+        "declare_segment",
     ]
 
     def __init__(self, dialect: str):
diff --git a/sqllineage/core/parser/sqlparse/handlers/source.py b/sqllineage/core/parser/sqlparse/handlers/source.py
index cdec7cd..3b467d7 100644
--- a/sqllineage/core/parser/sqlparse/handlers/source.py
+++ b/sqllineage/core/parser/sqlparse/handlers/source.py
@@ -104,6 +104,8 @@ class SourceHandler(SourceHandlerMixin, NextTokenBaseHandler):
                 sub_token
                 for sub_token in token.tokens
                 if isinstance(sub_token, column_token_types)
+                and not sub_token.value.startswith("@")
+                # ignore tsql variable column starts with @
             ]
         else:
             # SELECT constant value will end up here


Test patch:
diff --git a/tests/test_others_dialect_specific.py b/tests/test_others_dialect_specific.py
index c7185f3..1d8c00e 100644
--- a/tests/test_others_dialect_specific.py
+++ b/tests/test_others_dialect_specific.py
@@ -186,3 +186,15 @@ UPDATE SET t.col = s.col"""
         {"tgt"},
         dialect=dialect,
     )
+
+
+@pytest.mark.parametrize("dialect", ["tsql"])
+def test_tsql_declare(dialect: str):
+    """
+    https://learn.microsoft.com/en-us/sql/t-sql/language-elements/declare-local-variable-transact-sql?view=sql-server-ver16
+    """
+    sql = """DECLARE @age int = 10;
+INSERT INTO tgt
+SELECT Name,@age
+FROM People;"""
+    assert_table_lineage_equal(sql, {"People"}, {"tgt"}, dialect=dialect)