Skip to content

Commit eac9cc9

Browse files
tulikabhattclaude
authored andcommitted
feat(actions): add DomainNameResolver for human-friendly domain names (#14355)
Co-authored-by: Claude <[email protected]>
1 parent 2b94594 commit eac9cc9

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

datahub-actions/src/datahub_actions/utils/name_resolver.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
CorpUserInfoClass,
1010
DashboardInfoClass,
1111
DatasetPropertiesClass,
12+
DomainPropertiesClass,
1213
GlossaryTermInfoClass,
1314
SubTypesClass,
1415
TagPropertiesClass,
@@ -238,6 +239,21 @@ def get_entity_name(
238239
return super().get_entity_name(entity_urn, datahub_graph)
239240

240241

242+
class DomainNameResolver(DefaultNameResolver):
243+
def get_entity_name(
244+
self, entity_urn: Urn, datahub_graph: Optional[DataHubGraph]
245+
) -> str:
246+
if datahub_graph:
247+
domain_properties: Optional[DomainPropertiesClass] = (
248+
datahub_graph.get_aspect(str(entity_urn), DomainPropertiesClass)
249+
)
250+
if domain_properties and domain_properties.name:
251+
return domain_properties.name
252+
253+
# fall-through to default
254+
return super().get_entity_name(entity_urn, datahub_graph)
255+
256+
241257
class NameResolverRegistry:
242258
def __init__(self):
243259
self.registry = {
@@ -250,6 +266,7 @@ def __init__(self):
250266
"container": ContainerNameResolver(),
251267
"dataJob": DataJobNameResolver(),
252268
"dataFlow": DataFlowNameResolver(),
269+
"domain": DomainNameResolver(),
253270
}
254271
self.default_resolver = DefaultNameResolver()
255272

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2021 Acryl Data, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from unittest.mock import Mock
16+
17+
from datahub.metadata.schema_classes import DomainPropertiesClass
18+
from datahub.utilities.urns.urn import Urn
19+
from datahub_actions.utils.name_resolver import DomainNameResolver
20+
21+
22+
def test_domain_name_resolver_without_graph():
23+
# Test DomainNameResolver fallback behavior when DataHubGraph is None
24+
resolver = DomainNameResolver()
25+
domain_urn = Urn.from_string("urn:li:domain:marketing-domain")
26+
entity_name = resolver.get_entity_name(domain_urn, None)
27+
assert entity_name == "marketing-domain"
28+
29+
30+
def test_domain_name_resolver_with_graph():
31+
resolver = DomainNameResolver()
32+
domain_urn = Urn.from_string("urn:li:domain:marketing-domain")
33+
mock_graph = Mock()
34+
35+
# Test scenario 1: Graph available but no properties found
36+
mock_graph.get_aspect.return_value = None
37+
entity_name = resolver.get_entity_name(domain_urn, mock_graph)
38+
mock_graph.get_aspect.assert_called_with(str(domain_urn), DomainPropertiesClass)
39+
assert entity_name == "marketing-domain"
40+
41+
# Reset mock for next scenario
42+
mock_graph.reset_mock()
43+
44+
# Test scenario 2: Graph returns properties with name
45+
mock_properties = DomainPropertiesClass(name="Marketing Domain")
46+
mock_graph.get_aspect.return_value = mock_properties
47+
entity_name = resolver.get_entity_name(domain_urn, mock_graph)
48+
mock_graph.get_aspect.assert_called_with(str(domain_urn), DomainPropertiesClass)
49+
assert entity_name == "Marketing Domain"

0 commit comments

Comments
 (0)