Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ingestion/powerbi): support multiple tables as upstream in native SQL parsing #8592

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

import sqlparse

import datahub.utilities.sqlglot_lineage as sqlglot_l
from datahub.ingestion.api.common import PipelineContext
from datahub.utilities.sqlglot_lineage import (
SchemaResolver,
SqlParsingResult,
sqlglot_lineage,
)
from datahub.utilities.sqlglot_lineage import SqlParsingResult

SPECIAL_CHARACTERS = ["#(lf)", "(lf)"]

Expand Down Expand Up @@ -67,33 +64,15 @@ def parse_custom_sql(
logger.debug("Using sqlglot_lineage to parse custom sql")

sql_query = remove_special_characters(query)

logger.debug(f"Parsing sql={sql_query}")

parsed_result: Optional["SqlParsingResult"] = None
try:
schema_resolver = (
ctx.graph._make_schema_resolver(
platform=platform,
platform_instance=platform_instance,
env=env,
)
if ctx.graph is not None
else SchemaResolver(
platform=platform,
platform_instance=platform_instance,
env=env,
graph=None,
)
)

parsed_result = sqlglot_lineage(
sql_query,
schema_resolver=schema_resolver,
default_db=database,
default_schema=schema,
)
except Exception as e:
logger.debug(f"Fail to prase query {query}", exc_info=e)
logger.warning("Fail to parse custom SQL")

return parsed_result
return sqlglot_l.create_lineage_sql_parsed_result(
query=sql_query,
schema=schema,
database=database,
platform=platform,
platform_instance=platform_instance,
env=env,
graph=ctx.graph,
)
40 changes: 40 additions & 0 deletions metadata-ingestion/src/datahub/utilities/sqlglot_lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,3 +825,43 @@ def sqlglot_lineage(
table_error=e,
),
)


def create_lineage_sql_parsed_result(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also refactor tableau to use this method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

query: str,
schema: Optional[str],
database: Optional[str],
platform: str,
platform_instance: Optional[str],
env: str,
graph: Optional[DataHubGraph] = None,
) -> Optional["SqlParsingResult"]:

parsed_result: Optional["SqlParsingResult"] = None
try:
schema_resolver = (
graph._make_schema_resolver(
platform=platform,
platform_instance=platform_instance,
env=env,
)
if graph is not None
else SchemaResolver(
platform=platform,
platform_instance=platform_instance,
env=env,
graph=None,
)
)

parsed_result = sqlglot_lineage(
query,
schema_resolver=schema_resolver,
default_db=database,
default_schema=schema,
)
except Exception as e:
logger.debug(f"Fail to prase query {query}", exc_info=e)
logger.warning("Fail to parse custom SQL")

return parsed_result