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: MCE validation error #974

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions metaphor/common/sql/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import List

from metaphor.models.metadata_change_event import QueriedDataset


def is_valid_queried_datasets(datasets: List[QueriedDataset]) -> bool:
"""
database and schema must exist and not an empty string
"""
for dataset in datasets:
if not dataset.database or not dataset.schema or not dataset.table:
return False

Check warning on line 12 in metaphor/common/sql/utils.py

View check run for this annotation

Codecov / codecov/patch

metaphor/common/sql/utils.py#L12

Added line #L12 was not covered by tests
return True
20 changes: 13 additions & 7 deletions metaphor/postgresql/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
from datetime import datetime, timezone
from typing import Collection, Dict, Iterator, List, Optional, Tuple

from metaphor.common.fieldpath import build_schema_field
from metaphor.common.sql.process_query.process_query import process_query
from metaphor.common.sql.table_level_lineage.table_level_lineage import (
extract_table_level_lineage,
)
from metaphor.common.utils import md5_digest, safe_float, start_of_day

try:
import asyncpg
import boto3
Expand All @@ -19,8 +12,15 @@
from metaphor.common.base_extractor import BaseExtractor
from metaphor.common.entity_id import dataset_normalized_name
from metaphor.common.event_util import ENTITY_TYPES
from metaphor.common.fieldpath import build_schema_field
from metaphor.common.logger import get_logger
from metaphor.common.models import to_dataset_statistics
from metaphor.common.sql.process_query.process_query import process_query
from metaphor.common.sql.table_level_lineage.table_level_lineage import (
extract_table_level_lineage,
)
from metaphor.common.sql.utils import is_valid_queried_datasets
from metaphor.common.utils import 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 @@ -483,6 +483,12 @@
if not tll.sources and not tll.targets:
return None

# Skip if parsed sources or targets has invalid data.
if not is_valid_queried_datasets(tll.sources) or not is_valid_queried_datasets(
tll.targets
):
return None

Check warning on line 490 in metaphor/postgresql/extractor.py

View check run for this annotation

Codecov / codecov/patch

metaphor/postgresql/extractor.py#L490

Added line #L490 was not covered by tests

sql_hash = md5_digest(query.encode("utf-8"))
sql: Optional[str] = query

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.14.97"
version = "0.14.98"
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
Loading