mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-28 18:38:17 +00:00
docs: add new code examples on creating entities & fix minor typos (#7613)
Co-authored-by: Hyejin Yoon <yoonhyejin@Hyejins-MacBook-Pro.local> Co-authored-by: Hyejin Yoon <yoonhyejin@ip-192-168-0-10.us-west-2.compute.internal>
This commit is contained in:
parent
a84ec0ccf8
commit
38555385e1
@ -62,7 +62,7 @@ Expected Response:
|
||||
## Create Tags With Python SDK
|
||||
|
||||
The following code creates a tag named `Deprecated`.
|
||||
You can refer to the full code in [dataset_add_column_tag.py](https://github.com/datahub-project/datahub/blob/master/metadata-ingestion/examples/library/dataset_add_column_tag.py).
|
||||
You can refer to the full code in [create_tag.py](https://github.com/datahub-project/datahub/blob/master/metadata-ingestion/examples/library/create_tag.py).
|
||||
```python
|
||||
import logging
|
||||
|
||||
@ -76,10 +76,10 @@ from datahub.metadata.schema_classes import TagPropertiesClass
|
||||
log = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
tag_urn = make_tag_urn("customeraccount")
|
||||
tag_urn = make_tag_urn("deprecated")
|
||||
tag_properties_aspect = TagPropertiesClass(
|
||||
name="CustomerAccount",
|
||||
description="This is a test tag."
|
||||
name="Deprecated",
|
||||
description="Having this tag means this column or table is deprecated.",
|
||||
)
|
||||
|
||||
event: MetadataChangeProposalWrapper = MetadataChangeProposalWrapper(
|
||||
|
||||
@ -62,7 +62,7 @@ Expected Response:
|
||||
## Create Terms With Python SDK
|
||||
|
||||
The following code creates a term named `Rate of Return`.
|
||||
You can refer to the full code in [dataset_add_column_term.py](https://github.com/datahub-project/datahub/blob/master/metadata-ingestion/examples/library/dataset_add_column_term.py).
|
||||
You can refer to the full code in [create_term.py](https://github.com/datahub-project/datahub/blob/master/metadata-ingestion/examples/library/create_term.py).
|
||||
```python
|
||||
import logging
|
||||
|
||||
@ -80,7 +80,7 @@ term_urn = make_term_urn("rateofreturn")
|
||||
term_properties_aspect = GlossaryTermInfoClass(
|
||||
definition="A rate of return (RoR) is the net gain or loss of an investment over a specified time period.",
|
||||
name="Rate of Return",
|
||||
termSource=""
|
||||
termSource="",
|
||||
)
|
||||
|
||||
event: MetadataChangeProposalWrapper = MetadataChangeProposalWrapper(
|
||||
|
||||
27
metadata-ingestion/examples/library/create_tag.py
Normal file
27
metadata-ingestion/examples/library/create_tag.py
Normal file
@ -0,0 +1,27 @@
|
||||
import logging
|
||||
|
||||
from datahub.emitter.mce_builder import make_tag_urn
|
||||
from datahub.emitter.mcp import MetadataChangeProposalWrapper
|
||||
from datahub.emitter.rest_emitter import DatahubRestEmitter
|
||||
|
||||
# Imports for metadata model classes
|
||||
from datahub.metadata.schema_classes import TagPropertiesClass
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
tag_urn = make_tag_urn("deprecated")
|
||||
tag_properties_aspect = TagPropertiesClass(
|
||||
name="Deprecated",
|
||||
description="Having this tag means this column or table is deprecated.",
|
||||
)
|
||||
|
||||
event: MetadataChangeProposalWrapper = MetadataChangeProposalWrapper(
|
||||
entityUrn=tag_urn,
|
||||
aspect=tag_properties_aspect,
|
||||
)
|
||||
|
||||
# Create rest emitter
|
||||
rest_emitter = DatahubRestEmitter(gms_server="http://localhost:8080")
|
||||
rest_emitter.emit(event)
|
||||
log.info(f"Created tag {tag_urn}")
|
||||
28
metadata-ingestion/examples/library/create_term.py
Normal file
28
metadata-ingestion/examples/library/create_term.py
Normal file
@ -0,0 +1,28 @@
|
||||
import logging
|
||||
|
||||
from datahub.emitter.mce_builder import make_term_urn
|
||||
from datahub.emitter.mcp import MetadataChangeProposalWrapper
|
||||
from datahub.emitter.rest_emitter import DatahubRestEmitter
|
||||
|
||||
# Imports for metadata model classes
|
||||
from datahub.metadata.schema_classes import GlossaryTermInfoClass
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
term_urn = make_term_urn("rateofreturn")
|
||||
term_properties_aspect = GlossaryTermInfoClass(
|
||||
definition="A rate of return (RoR) is the net gain or loss of an investment over a specified time period.",
|
||||
name="Rate of Return",
|
||||
termSource="",
|
||||
)
|
||||
|
||||
event: MetadataChangeProposalWrapper = MetadataChangeProposalWrapper(
|
||||
entityUrn=term_urn,
|
||||
aspect=term_properties_aspect,
|
||||
)
|
||||
|
||||
# Create rest emitter
|
||||
rest_emitter = DatahubRestEmitter(gms_server="http://localhost:8080")
|
||||
rest_emitter.emit(event)
|
||||
log.info(f"Created term {term_urn}")
|
||||
Loading…
x
Reference in New Issue
Block a user