-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
70 additions
and
139 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
metadata-ingestion/src/datahub/specific/aspect_helpers/terms.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Union | ||
|
||
from typing_extensions import Self | ||
|
||
from datahub.emitter.mcp_patch_builder import MetadataPatchProposal | ||
from datahub.metadata.schema_classes import ( | ||
GlossaryTermAssociationClass as Term, | ||
GlossaryTermsClass, | ||
) | ||
from datahub.metadata.urns import GlossaryTermUrn, Urn | ||
|
||
|
||
class HasTermsPatch(MetadataPatchProposal): | ||
def add_term(self, term: Term) -> Self: | ||
"""Adds a glossary term to the entity. | ||
Args: | ||
term: The Term object representing the glossary term to be added. | ||
Returns: | ||
The patch builder instance. | ||
""" | ||
# TODO: Make this support raw strings, in addition to Term objects. | ||
self._add_patch( | ||
GlossaryTermsClass.ASPECT_NAME, "add", path=("terms", term.urn), value=term | ||
) | ||
return self | ||
|
||
def remove_term(self, term: Union[str, Urn]) -> Self: | ||
"""Removes a glossary term from the entity. | ||
Args: | ||
term: The term to remove, specified as a string or Urn object. | ||
Returns: | ||
The patch builder instance. | ||
""" | ||
if isinstance(term, str) and not term.startswith("urn:li:glossaryTerm:"): | ||
term = GlossaryTermUrn(term) | ||
self._add_patch( | ||
GlossaryTermsClass.ASPECT_NAME, "remove", path=("terms", term), value={} | ||
) | ||
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters