feat(ingest): generate urn types for all entities (#11676)

This commit is contained in:
Harshal Sheth 2024-10-22 11:49:20 -07:00 committed by GitHub
parent cdb23ac5d6
commit 7f6f18cf77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 20 deletions

View File

@ -361,9 +361,6 @@ deprecated = functools.partial(_sphinx_deprecated, version="0.12.0.2")
for aspect in key_aspects:
entity_type = aspect["Aspect"]["keyForEntity"]
if aspect["Aspect"]["entityCategory"] == "internal":
continue
code += generate_urn_class(entity_type, aspect)
(urn_dir / "urn_defs.py").write_text(code)

View File

@ -14,7 +14,12 @@ from datahub.emitter.mce_builder import (
from datahub.emitter.mcp import MetadataChangeProposalWrapper
from datahub.emitter.mcp_builder import DatahubKey
from datahub.ingestion.graph.client import DataHubGraph
from datahub.metadata.urns import DataPlatformUrn, PlatformResourceUrn, Urn
from datahub.metadata.urns import (
DataPlatformInstanceUrn,
DataPlatformUrn,
PlatformResourceUrn,
Urn,
)
from datahub.utilities.openapi_utils import OpenAPIGraphClient
from datahub.utilities.search_utils import (
ElasticDocumentQuery,
@ -76,21 +81,6 @@ class PlatformResourceInfo(BaseModel):
)
class DataPlatformInstanceUrn:
"""
A simple implementation of a URN class for DataPlatformInstance.
Since this is not present in the URN registry, we need to implement it here.
"""
@staticmethod
def create_from_id(platform_instance_urn: str) -> Urn:
if platform_instance_urn.startswith("urn:li:platformInstance:"):
string_urn = platform_instance_urn
else:
string_urn = f"urn:li:platformInstance:{platform_instance_urn}"
return Urn.from_string(string_urn)
class UrnSearchField(SearchField):
"""
A search field that supports URN values.
@ -130,7 +120,7 @@ class PlatformResourceSearchFields:
PLATFORM_INSTANCE = PlatformResourceSearchField.from_search_field(
UrnSearchField(
field_name="platformInstance.keyword",
urn_value_extractor=DataPlatformInstanceUrn.create_from_id,
urn_value_extractor=DataPlatformInstanceUrn.from_string,
)
)