forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): python - add get_aspects_for_entity (datahub-project#5255)
Co-authored-by: Shirshanka Das <[email protected]>
- Loading branch information
1 parent
272e060
commit a151f19
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
metadata-ingestion/examples/library/dataset_query_entity_v2.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,33 @@ | ||
import logging | ||
|
||
from datahub.emitter.mce_builder import make_dataset_urn | ||
|
||
# read-modify-write requires access to the DataHubGraph (RestEmitter is not enough) | ||
from datahub.ingestion.graph.client import DatahubClientConfig, DataHubGraph | ||
|
||
# Imports for metadata model classes | ||
from datahub.metadata.schema_classes import ( | ||
DataPlatformInstanceClass, | ||
DatasetKeyClass, | ||
StatusClass, | ||
) | ||
|
||
log = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
dataset_urn = make_dataset_urn(platform="hive", name="realestate_db.sales", env="PROD") | ||
|
||
gms_endpoint = "http://localhost:8080" | ||
graph = DataHubGraph(DatahubClientConfig(server=gms_endpoint)) | ||
|
||
# Query multiple aspects from entity | ||
result = graph.get_aspects_for_entity( | ||
entity_urn=dataset_urn, | ||
aspects=["status", "dataPlatformInstance", "datasetKey"], | ||
aspect_types=[StatusClass, DataPlatformInstanceClass, DatasetKeyClass], | ||
) | ||
|
||
# result are typed according to their class if exist | ||
if result is not None: | ||
if result["datasetKey"]: | ||
log.info(result["datasetKey"].name) |
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