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

Fix #13692 - table_usage pydantic validation & unbound var #13691

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all 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
17 changes: 12 additions & 5 deletions ingestion/src/metadata/ingestion/stage/table_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import shutil
import traceback
from pathlib import Path
from typing import Iterable, List, Tuple
from typing import Iterable, List, Optional, Tuple

from metadata.config.common import ConfigModel
from metadata.generated.schema.api.data.createQuery import CreateQueryRequest
Expand Down Expand Up @@ -78,12 +78,19 @@ def init_location(self) -> None:
logger.info(f"Creating the directory to store staging data in {location}")
location.mkdir(parents=True, exist_ok=True)

def _get_user_entity(self, username: str) -> Tuple[List[str], List[str]]:
def _get_user_entity(
self, username: str
) -> Tuple[Optional[List[str]], Optional[List[str]]]:
"""
From the user received in the query history call - who executed the query in the db -
return if we find any users in OM that match, plus the user that we found in the db record.
"""
if username:
user = self.metadata.get_by_name(entity=User, fqn=username)
if user:
return [user.fullyQualifiedName.__root__], []
return [], [username]
return [user.fullyQualifiedName.__root__], [username]
return None, [username]
return None, None

def _add_sql_query(self, record, table):
users, used_by = self._get_user_entity(record.userName)
Expand Down Expand Up @@ -139,6 +146,7 @@ def _handle_table_usage(
sqlQueries=[],
databaseSchema=parsed_data.databaseSchema,
)
self.table_usage[(table, parsed_data.date)] = table_usage_count

except Exception as exc:
yield Either(
Expand All @@ -148,7 +156,6 @@ def _handle_table_usage(
stack_trace=traceback.format_exc(),
)
)
self.table_usage[(table, parsed_data.date)] = table_usage_count
yield Either(right=table)

def _run(self, record: QueryParserData) -> Iterable[Either[str]]:
Expand Down
Loading