Repository: reata/sqllineage
Pull request #457 (2023-09-26 04:16:14)

add versioning of package to cli
I think this is the primary need for sqllineage package.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/reata/sqllineage/pull/457?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#457](https://app.codecov.io/gh/reata/sqllineage/pull/457?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (41a6a60) into [master](https://app.codecov.io/gh/reata/sqllineage/commit/db2405455b68ee72354e048bad37f1ff429563f4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (db24054) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff           @@
##           master     #457   +/-   ##
=======================================
  Coverage   99.54%   99.54%           
=======================================
  Files          38       38           
  Lines        1986     1987    +1     
=======================================
+ Hits         1977     1978    +1     
  Misses          9        9           
```


| [Files](https://app.codecov.io/gh/reata/sqllineage/pull/457?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [sqllineage/cli.py](https://app.codecov.io/gh/reata/sqllineage/pull/457?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3FsbGluZWFnZS9jbGkucHk=) | `97.56% <100.00%> (+0.06%)` | :arrow_up: |



Patch:
diff --git a/sqllineage/cli.py b/sqllineage/cli.py
index 20a580e..89ca6da 100644
--- a/sqllineage/cli.py
+++ b/sqllineage/cli.py
@@ -3,7 +3,14 @@ import logging
 import logging.config
 import warnings
 
-from sqllineage import DEFAULT_DIALECT, DEFAULT_HOST, DEFAULT_LOGGING, DEFAULT_PORT
+from sqllineage import (
+    DEFAULT_DIALECT,
+    DEFAULT_HOST,
+    DEFAULT_LOGGING,
+    DEFAULT_PORT,
+    NAME as MAIN_NAME,
+    VERSION as MAIN_VERSION,
+)
 from sqllineage.drawing import draw_lineage_graph
 from sqllineage.runner import LineageRunner
 from sqllineage.utils.constant import LineageLevel
@@ -23,6 +30,9 @@ def main(args=None) -> None:
     parser = argparse.ArgumentParser(
         prog="sqllineage", description="SQL Lineage Parser."
     )
+    parser.add_argument(
+        "--version", action="version", version="%s %s" % (MAIN_NAME, MAIN_VERSION)
+    )
     parser.add_argument(
         "-e", metavar="<quoted-query-string>", help="SQL from command line"
     )
diff --git a/sqllineage/core/parser/sqlfluff/extractors/drop.py b/sqllineage/core/parser/sqlfluff/extractors/drop.py
index a254b52..541b416 100644
--- a/sqllineage/core/parser/sqlfluff/extractors/drop.py
+++ b/sqllineage/core/parser/sqlfluff/extractors/drop.py
@@ -11,7 +11,7 @@ class DropExtractor(BaseExtractor):
     Drop statement lineage extractor
     """
 
-    SUPPORTED_STMT_TYPES = ["drop_table_statement"]
+    SUPPORTED_STMT_TYPES = ["drop_table_statement", "drop_view_statement"]
 
     def extract(
         self,
@@ -23,7 +23,7 @@ class DropExtractor(BaseExtractor):
         for segment in list_child_segments(statement):
             if (
                 segment.type == "keyword"
-                and segment.raw_upper == "TABLE"
+                and segment.raw_upper in ["TABLE", "VIEW"]
                 or (drop_flag is True and segment.raw_upper in ["IF", "EXISTS"])
             ):
                 drop_flag = True


Test patch:
diff --git a/tests/sql/table/other_single_statement/test_other_without_lineage.py b/tests/sql/table/other_single_statement/test_other_without_lineage.py
index ae91b16..4e746ee 100644
--- a/tests/sql/table/other_single_statement/test_other_without_lineage.py
+++ b/tests/sql/table/other_single_statement/test_other_without_lineage.py
@@ -16,6 +16,10 @@ DROP TABLE IF EXISTS tab1"""
     )
 
 
+def test_drop_view():
+    assert_table_lineage_equal("DROP VIEW IF EXISTS view1")
+
+
 def test_alter_table_rename():
     assert_table_lineage_equal("ALTER TABLE tab1 rename TO tab2")