Skip to content

Commit

Permalink
[sc-28036] Oracle query logs need to have _id and sql_hash (#945)
Browse files Browse the repository at this point in the history
* [sc-28036] Oracle query logs need to have _id and sql_hash

* bump version
  • Loading branch information
usefulalgorithm authored Aug 8, 2024
1 parent 3a8b233 commit f1e62e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions metaphor/oracle/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from metaphor.common.entity_id import dataset_normalized_name
from metaphor.common.event_util import ENTITY_TYPES
from metaphor.common.logger import get_logger
from metaphor.common.utils import start_of_day, to_utc_time
from metaphor.common.utils import md5_digest, start_of_day, to_utc_time
from metaphor.database.extractor import GenericDatabaseExtractor
from metaphor.models.crawler_run_metadata import Platform
from metaphor.models.metadata_change_event import (
Expand Down Expand Up @@ -202,12 +202,14 @@ def _extract_query_logs(self, inspector: Inspector, excluded_users: List[str]):
"""

cursor = connection.execute(text(sql))
for user, query, start, duration, sql_id in cursor:
for user, query, start, duration, query_id in cursor:
yield QueryLog(
query_id=sql_id,
id=f"{DataPlatform.ORACLE.name}:{query_id}",
query_id=query_id,
platform=DataPlatform.ORACLE,
user_id=user,
sql=query,
sql_hash=md5_digest(query.encode("utf-8")),
duration=float(duration),
start_time=to_utc_time(start),
)
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.14.73"
version = "0.14.74"
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
2 changes: 2 additions & 0 deletions tests/oracle/expected_query_logs.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[
{
"_id": "ORACLE:sql-id",
"duration": 10.0,
"platform": "ORACLE",
"queryId": "sql-id",
"sql": "SELECT...",
"startTime": "2024-07-30T15:31:33+00:00",
"sqlHash": "191df6d782898cbb739c413fa5868422",
"userId": "DEV"
}
]

0 comments on commit f1e62e0

Please sign in to comment.