Skip to content

Commit

Permalink
chore: Add method get_resources_using_table to metadata gremlin_proxy (
Browse files Browse the repository at this point in the history
…#2223)

* Add function get_resources_using_table to metadata gremlin_proxy

Signed-off-by: sihaotan4 <[email protected]>

* Added function docstring for get_resources_using_table

Signed-off-by: sihaotan4 <[email protected]>

---------

Signed-off-by: sihaotan4 <[email protected]>
  • Loading branch information
sihaotan4 authored Dec 20, 2023
1 parent ae5fb6d commit 505a840
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion metadata/metadata_service/proxy/gremlin_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,36 @@ def put_dashboard_description(self, *,
def get_resources_using_table(self, *,
id: str,
resource_type: ResourceType) -> Dict[str, List[DashboardSummary]]:
pass
"""
Retrieves the dashboards that are using a specific table, in the form of DashboardSummary objects.
:param id: The unique identifier of the table.
:param resource_type: The type of the resource. Only ResourceType.Dashboard is supported.
:return: A dictionary with a single key 'dashboards' that maps to a list of DashboardSummary objects.
Each DashboardSummary object represents a dashboard that uses the table.
:raises NotImplementedError: If the resource_type is not ResourceType.Dashboard.
"""
if resource_type != ResourceType.Dashboard:
raise NotImplementedError(f'{resource_type} is not supported')

resources_using_table_query = self.g.V().hasLabel('Table').has('key', id).both('TABLE_OF_DASHBOARD')
resources_using_table_query = resources_using_table_query.valueMap(True).by(__.unfold())
dashboards_list = self.query_executor()(query=resources_using_table_query, get=FromResultSet.toList)
results = []
for dashboard in dashboards_list:
entry = {
'uri': dashboard['key'],
'cluster': dashboard['name'],
'group_name': dashboard['name'],
'group_url': dashboard['dashboard_group_url'],
'product': dashboard['key'].split('_')[0],
'name': dashboard['name'],
'url': dashboard['dashboard_url'],
'last_successful_run_timestamp': dashboard['last_extracted_datetime'].timestamp()
}
results.append(DashboardSummary(**entry))

return {'dashboards': results}

def _get_user_table_relationship_clause(self, *, g: Traversal, relation_type: UserResourceRel,
table_uri: str = None, user_key: str = None) -> GraphTraversal:
Expand Down

0 comments on commit 505a840

Please sign in to comment.