Skip to content

Commit

Permalink
minor changes + change deprecated fields in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
anshbansal committed Sep 4, 2023
1 parent 4219a73 commit a91413d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/how/add-custom-data-platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ datahub put platform --name MyCustomDataPlatform --display_name "My Custom Data
source:
type: "file"
config:
filename: "./my-custom-data-platform.json"
path: "./my-custom-data-platform.json"
# see https://datahubproject.io/docs/metadata-ingestion/sink_docs/datahub for complete documentation
sink:
Expand Down
2 changes: 1 addition & 1 deletion docs/how/add-user-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Define an [ingestion recipe](https://datahubproject.io/docs/metadata-ingestion/#
source:
type: "file"
config:
filename: "./my-user.json"
path: "./my-user.json"
# see https://datahubproject.io/docs/metadata-ingestion/sink_docs/datahub for complete documentation
sink:
Expand Down
2 changes: 1 addition & 1 deletion docs/ownership/ownership-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ source:
type: "file"
config:
# path to json file
filename: "metadata-ingestion/examples/ownership/ownership_type.json"
path: "metadata-ingestion/examples/ownership/ownership_type.json"

# see https://datahubproject.io/docs/metadata-ingestion/sink_docs/datahub for complete documentation
sink:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,25 @@ def create(
config = ExtractOwnersFromTagsConfig.parse_obj(config_dict)
return cls(config, ctx)

def get_owner_urn(self, owner_str: str):
if self.config.email_domain is not None:
return owner_str + "@" + self.config.email_domain
return owner_str

def transform_aspect(
self, entity_urn: str, aspect_name: str, aspect: Optional[Aspect]
) -> Optional[Aspect]:
in_tags_aspect: Optional[GlobalTagsClass] = cast(GlobalTagsClass, aspect)
if in_tags_aspect is None:
return None
tags_str = in_tags_aspect.tags
tags = in_tags_aspect.tags
owners: List[OwnerClass] = []
for tag in tags_str:
tag_urn = TagUrn.create_from_string(tag)
for tag_class in tags:
tag_urn = TagUrn.create_from_string(tag_class.tag)
tag_str = tag_urn.get_entity_id()[0]
if tag_str.startswith(self.config.tag_prefix):
owner_str = tag_str[len(self.config.tag_prefix) :]
if self.config.email_domain is not None:
owner_urn_str = owner_str + "@" + self.config.email_domain
else:
owner_urn_str = owner_str
owner_urn_str = self.get_owner_urn(owner_str)
if self.config.is_user:
owner_urn = CorpuserUrn.create_from_id(owner_urn_str)
else:
Expand Down
18 changes: 12 additions & 6 deletions metadata-ingestion/tests/unit/test_transform_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,13 @@ def _test_owner(
expected_owner: str,
expected_owner_type: Optional[OwnershipTypeClass] = None,
) -> None:
dataset = make_generic_dataset(aspects=[models.GlobalTagsClass(tags=[tag])])
dataset = make_generic_dataset(
aspects=[
models.GlobalTagsClass(
tags=[TagAssociationClass(tag=builder.make_tag_urn(tag))]
)
]
)
transformer = ExtractOwnersFromTagsTransformer.create(
config,
PipelineContext(run_id="test"),
Expand All @@ -617,30 +623,30 @@ def _test_owner(
assert owner.owner == expected_owner

_test_owner(
tag="urn:li:tag:owner:foo",
tag="owner:foo",
config={
"tag_prefix": "owner:",
},
expected_owner="urn:li:corpuser:foo",
)
_test_owner(
tag="urn:li:tag:owner:foo",
tag="owner:foo",
config={
"tag_prefix": "owner:",
"is_user": False,
},
expected_owner="urn:li:corpGroup:foo",
)
_test_owner(
tag="urn:li:tag:owner:foo",
tag="owner:foo",
config={
"tag_prefix": "owner:",
"email_domain": "example.com",
},
expected_owner="urn:li:corpuser:[email protected]",
)
_test_owner(
tag="urn:li:tag:owner:foo",
tag="owner:foo",
config={
"tag_prefix": "owner:",
"email_domain": "example.com",
Expand All @@ -650,7 +656,7 @@ def _test_owner(
expected_owner_type=OwnershipTypeClass.TECHNICAL_OWNER,
)
_test_owner(
tag="urn:li:tag:owner:foo",
tag="owner:foo",
config={
"tag_prefix": "owner:",
"email_domain": "example.com",
Expand Down

0 comments on commit a91413d

Please sign in to comment.