Skip to content

Commit

Permalink
Handle email-based Snowflake user ID in query logs (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
mars-lan authored Nov 5, 2023
1 parent d873787 commit b9e06fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions metaphor/snowflake/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from metaphor.common.query_history import chunk_query_logs
from metaphor.common.snowflake import normalize_snowflake_account
from metaphor.common.tag_matcher import tag_datasets
from metaphor.common.utils import chunks, md5_digest, safe_float, start_of_day
from metaphor.common.utils import chunks, is_email, md5_digest, safe_float, start_of_day
from metaphor.models.crawler_run_metadata import Platform
from metaphor.models.metadata_change_event import (
DataPlatform,
Expand Down Expand Up @@ -579,6 +579,11 @@ def _parse_query_logs(self, batch_number: str, query_logs: List[Tuple]) -> None:
if len(query_text) >= self._query_log_max_query_size:
continue

# User IDs can be an email address
user_id, email = (
(None, username) if is_email(username) else (username, None)
)

query_log = QueryLog(
id=f"{DataPlatform.SNOWFLAKE.name}:{query_id}",
query_id=query_id,
Expand All @@ -587,7 +592,8 @@ def _parse_query_logs(self, batch_number: str, query_logs: List[Tuple]) -> None:
start_time=start_time,
duration=safe_float(elapsed_time / 1000.0),
cost=safe_float(credit),
user_id=username,
user_id=user_id,
email=email,
default_database=default_database,
default_schema=default_schema,
rows_read=safe_float(rows_produced),
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "metaphor-connectors"
version = "0.13.31"
version = "0.13.32"
license = "Apache-2.0"
description = "A collection of Python-based 'connectors' that extract metadata from various sources to ingest into the Metaphor app."
authors = ["Metaphor <[email protected]>"]
Expand Down

0 comments on commit b9e06fd

Please sign in to comment.