瀏覽代碼

HUE-3450 [metadata] Revise lineage API to be simpler

Jenny Kim 9 年之前
父節點
當前提交
fc7802b

+ 16 - 1
desktop/libs/metadata/src/metadata/navigator_api.py

@@ -231,7 +231,22 @@ def get_lineage(request):
   if not entity_id:
     raise MetadataApiException("get_lineage requires an 'id' parameter")
 
-  response['lineage'] = api.get_lineage(entity_id)
+  lineage = api.get_lineage(entity_id)
+  entity_name = api.get_entity(entity_id)['originalName'].upper()
+
+  response['id'] = entity_id
+
+  # TODO: This is a cheat way to do to this for demo using filtering but we should really traverse relationships
+  parent_operation = next((entity for entity in lineage['entities'] if entity.get('outputs', []) == [entity_name]), None)
+  if parent_operation:
+    response['inputs'] = parent_operation['inputs']
+    response['source_query'] = parent_operation.get('queryText', '')
+
+  children = [entity for entity in lineage['entities'] if entity.get('inputs') is not None and entity_name in entity.get('inputs')]
+  if children is not None:
+    response['target_queries'] = [child['queryText'] for child in children if child.get('queryText') is not None]
+    response['targets'] = [child['outputs'] for child in children if child.get('outputs') is not None]
+
   response['status'] = 0
 
   return JsonResponse(response)

+ 5 - 0
desktop/libs/metadata/src/metadata/navigator_tests.py

@@ -114,6 +114,11 @@ class TestNavigatorApi(object):
     assert_equal(entity['properties'], json_resp['entity']['properties'])
 
 
+  def test_lineage(self):
+    # TODO: write me
+    pass
+
+
   def _format_json_body(self, post_dict):
     json_dict = {}
     for key, value in post_dict.items():