Skip to content

Commit

Permalink
feat(ingest): add entity_supports_aspect helper (#9120)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored Oct 30, 2023
1 parent 51d6d1f commit 0bd2d9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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)

0 comments on commit 0bd2d9a

Please sign in to comment.