Repository: reata/sqllineage
Pull request #533 (2024-01-07 05:51:32)

feat: set sqlalchemy_url through CLI option
making progress in #477 

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/reata/sqllineage/pull/533?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`b83aaf6`)](https://app.codecov.io/gh/reata/sqllineage/commit/b83aaf671fa0895dcf7df96ecfd229594b624364?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) 99.49% compared to head [(`dc9dfe1`)](https://app.codecov.io/gh/reata/sqllineage/pull/533?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) 99.49%.


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #533   +/-   ##
=======================================
  Coverage   99.49%   99.49%           
=======================================
  Files          41       41           
  Lines        2193     2196    +3     
=======================================
+ Hits         2182     2185    +3     
  Misses         11       11           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/reata/sqllineage/pull/533?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).


Patch:
diff --git a/sqllineage/cli.py b/sqllineage/cli.py
index 6fd95c8..87104bb 100644
--- a/sqllineage/cli.py
+++ b/sqllineage/cli.py
@@ -11,6 +11,8 @@ from sqllineage import (
     NAME as MAIN_NAME,
     VERSION as MAIN_VERSION,
 )
+from sqllineage.core.metadata.dummy import DummyMetaDataProvider
+from sqllineage.core.metadata.sqlalchemy import SQLAlchemyMetaDataProvider
 from sqllineage.drawing import draw_lineage_graph
 from sqllineage.runner import LineageRunner
 from sqllineage.utils.constant import LineageLevel
@@ -91,6 +93,11 @@ def main(args=None) -> None:
         help="skip unsupported statements",
         action="store_true",
     )
+    parser.add_argument(
+        "--sqlalchemy_url",
+        help="sqlalchemy url to provide metadata for lineage analysis",
+        type=str,
+    )
     args = parser.parse_args(args)
     if args.e and args.f:
         warnings.warn("Both -e and -f options are specified. -e option will be ignored")
@@ -99,6 +106,9 @@ def main(args=None) -> None:
         runner = LineageRunner(
             sql,
             dialect=args.dialect,
+            metadata_provider=SQLAlchemyMetaDataProvider(args.sqlalchemy_url)
+            if args.sqlalchemy_url
+            else DummyMetaDataProvider(),
             verbose=args.verbose,
             draw_options={
                 "host": args.host,


Test patch:
diff --git a/tests/core/test_cli.py b/tests/core/test_cli.py
index 0752dd7..eb1a2be 100644
--- a/tests/core/test_cli.py
+++ b/tests/core/test_cli.py
@@ -19,6 +19,8 @@ def test_cli_dummy(_):
             main(["-f", sql_file])
             main(["-e", "select * from dual", "-f", sql_file])
             main(["-f", sql_file, "-g"])
+            main(["-f", sql_file, "--silent_mode"])
+            main(["-f", sql_file, "--sqlalchemy_url=sqlite:///:memory:"])
             break
     main(["-g"])
     main(["-ds"])