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(ingest): add entity_supports_aspect helper #9120

Merged
merged 1 commit into from
Oct 30, 2023
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: 12 additions & 1 deletion metadata-ingestion/src/datahub/emitter/mcp_builder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Dict, Iterable, List, Optional, TypeVar
from typing import Dict, Iterable, List, Optional, Type, TypeVar

from pydantic.fields import Field
from pydantic.main import BaseModel

from datahub.emitter.mce_builder import (
Aspect,
datahub_guid,
make_container_urn,
make_data_platform_urn,
Expand All @@ -18,6 +19,7 @@
)
from datahub.metadata.com.linkedin.pegasus2avro.container import ContainerProperties
from datahub.metadata.schema_classes import (
KEY_ASPECTS,
ContainerClass,
DomainsClass,
EmbedClass,
Expand Down Expand Up @@ -306,3 +308,12 @@ def create_embed_mcp(urn: str, embed_url: str) -> MetadataChangeProposalWrapper:
entityUrn=urn,
aspect=EmbedClass(renderUrl=embed_url),
)


def entity_supports_aspect(entity_type: str, aspect_type: Type[Aspect]) -> bool:
entity_key_aspect = KEY_ASPECTS[entity_type]
aspect_name = aspect_type.get_aspect_name()

supported_aspects = entity_key_aspect.ASPECT_INFO["entityAspects"]

return aspect_name in supported_aspects
9 changes: 9 additions & 0 deletions metadata-ingestion/tests/unit/test_mcp_builder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datahub.emitter.mcp_builder as builder
from datahub.metadata.schema_classes import StatusClass, TelemetryClientIdClass


def test_guid_generator():
Expand Down Expand Up @@ -83,3 +84,11 @@ def test_guid_generators():

guid = key.guid()
assert guid == guid_datahub


def test_entity_supports_aspect():
assert builder.entity_supports_aspect("dataset", StatusClass)
assert not builder.entity_supports_aspect("telemetry", StatusClass)

assert not builder.entity_supports_aspect("dataset", TelemetryClientIdClass)
assert builder.entity_supports_aspect("telemetry", TelemetryClientIdClass)
Loading