Skip to content

Commit

Permalink
fix: pass metadata provider to frontend visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
reata committed May 20, 2024
1 parent f03a015 commit c12d660
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
19 changes: 13 additions & 6 deletions sqllineage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,19 @@ def main(args=None) -> None:
type=str,
)
args = parser.parse_args(args)
metadata_provider = (
SQLAlchemyMetaDataProvider(args.sqlalchemy_url)
if args.sqlalchemy_url
else DummyMetaDataProvider()
)
if args.e and args.f:
warnings.warn("Both -e and -f options are specified. -e option will be ignored")
if args.f or args.e:
sql = extract_sql_from_args(args)
runner = LineageRunner(
sql,
dialect=args.dialect,
metadata_provider=(
SQLAlchemyMetaDataProvider(args.sqlalchemy_url)
if args.sqlalchemy_url
else DummyMetaDataProvider()
),
metadata_provider=metadata_provider,
verbose=args.verbose,
draw_options={
"host": args.host,
Expand All @@ -126,7 +127,13 @@ def main(args=None) -> None:
else:
runner.print_table_lineage()
elif args.graph_visualization:
return draw_lineage_graph(**{"host": args.host, "port": args.port})
return draw_lineage_graph(
**{
"host": args.host,
"port": args.port,
"metadata_provider": metadata_provider,
}
)
elif args.dialects:
dialects = []
for _, supported_dialects in LineageRunner.supported_dialects().items():
Expand Down
12 changes: 9 additions & 3 deletions sqllineage/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from sqllineage import DEFAULT_DIALECT, DEFAULT_HOST, DEFAULT_PORT, STATIC_FOLDER
from sqllineage.config import SQLLineageConfig
from sqllineage.core.metadata.dummy import DummyMetaDataProvider
from sqllineage.exceptions import SQLLineageException
from sqllineage.utils.constant import LineageLevel
from sqllineage.utils.helpers import extract_sql_from_args
Expand All @@ -30,6 +31,7 @@ class SQLLineageApp:
def __init__(self) -> None:
self.routes: Dict[str, Callable[[Dict[str, Any]], Dict[str, Any]]] = {}
self.root_path = Path(SQLLineageConfig.DIRECTORY)
self.metadata_provider = DummyMetaDataProvider()

def route(self, path: str):
def wrapper(handler):
Expand Down Expand Up @@ -165,7 +167,9 @@ def lineage(payload):
req_args = Namespace(**payload)
sql = extract_sql_from_args(req_args)
dialect = getattr(req_args, "dialect", DEFAULT_DIALECT)
lr = LineageRunner(sql, dialect=dialect, verbose=True)
lr = LineageRunner(
sql, dialect=dialect, verbose=True, metadata_provider=app.metadata_provider
)
data = {
"verbose": str(lr),
"dag": lr.to_cytoscape(),
Expand Down Expand Up @@ -206,8 +210,10 @@ def draw_lineage_graph(**kwargs) -> None:
port = kwargs.pop("port", DEFAULT_PORT)
querystring = urlencode({k: v for k, v in kwargs.items() if v})
path = f"/?{querystring}" if querystring else "/"
if "f" in kwargs:
app.root_path = Path(kwargs["f"]).parent
if f := kwargs.get("f"):
app.root_path = Path(f).parent
if metadata_provider := kwargs.get("metadata_provider"):
app.metadata_provider = metadata_provider

Check warning on line 216 in sqllineage/drawing.py

View check run for this annotation

Codecov / codecov/patch

sqllineage/drawing.py#L216

Added line #L216 was not covered by tests
with make_server(host, port, app) as httpd:
print(f" * SQLLineage Running on http://{host}:{port}{path}")
httpd.serve_forever()
5 changes: 3 additions & 2 deletions sqllineage/runner.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import warnings
from collections import OrderedDict
from typing import Dict, List, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple

from sqllineage import DEFAULT_DIALECT, SQLPARSE_DIALECT
from sqllineage.config import SQLLineageConfig
Expand Down Expand Up @@ -41,7 +41,7 @@ def __init__(
metadata_provider: MetaDataProvider = DummyMetaDataProvider(),
verbose: bool = False,
silent_mode: bool = False,
draw_options: Optional[Dict[str, str]] = None,
draw_options: Optional[Dict[str, Any]] = None,
):
"""
The entry point of SQLLineage after command line options are parsed.
Expand Down Expand Up @@ -120,6 +120,7 @@ def draw(self) -> None:
draw_options.pop("f", None)
draw_options["e"] = self._sql
draw_options["dialect"] = self._dialect
draw_options["metadata_provider"] = self._metadata_provider
return draw_lineage_graph(**draw_options)

@lazy_method
Expand Down

0 comments on commit c12d660

Please sign in to comment.