Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize purview query for getting features #584

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions registry/purview-registry/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,8 @@ def get_project_datasources(project: str) -> list:

@router.get("/projects/{project}/features",tags=["Project"])
def get_project_features(project: str, keyword: Optional[str] = None) -> list:
if keyword is None or keyword.strip()=='':
p = registry.get_entity(project,True)
feature_ids = [s.id for s in p.attributes.anchor_features] + \
[s.id for s in p.attributes.derived_features]
features = registry.get_entities(feature_ids,True)
return list([to_camel(e.to_dict()) for e in features])
else:
efs = registry.search_entity(
keyword, [EntityType.AnchorFeature, EntityType.DerivedFeature],project=project)
feature_ids = [ef.id for ef in efs]
features = registry.get_entities(feature_ids)
return list([to_camel(e.to_dict()) for e in features])
atlasEntities = registry.get_project_features(project, keywords=keyword)
return list([to_camel(e.to_dict()) for e in atlasEntities])


@router.get("/features/{feature}",tags=["Feature"])
Expand Down
24 changes: 21 additions & 3 deletions registry/purview-registry/registry/purview_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,30 @@ def _create_edge_from_process(self, name:str, guid: str) -> Edge:
names = name.split(self.registry_delimiter)
return Edge(guid, names[1], names[2], RelationshipType.new(names[0]))

def get_project_features(self, project:str, keywords:Optional[str] = None) -> list[Entity]:
project_id = self.get_entity_id(project)
if not project_id:
return None
guidAtlasEntityMap = self.purview_client.get_entity_lineage(project_id, depth=1, width=1, direction="OUTPUT")['guidEntityMap']
atlasEntities = []

for entity in guidAtlasEntityMap.values():
type = entity['typeName']
if type != "Process":
type = EntityType.new(type)
if type == EntityType.AnchorFeature or type == EntityType.DerivedFeature:
attributes = entity['attributes']
if not keywords or (attributes and keywords in attributes['qualifiedName']):
atlasEntity = self._atlasEntity_to_entity(entity)
atlasEntities.append(atlasEntity)
return atlasEntities

def get_project(self, id_or_name: Union[str, UUID]) -> EntitiesAndRelations:
project_id = self.get_entity_id(id_or_name)
if not project_id:
return None
lineage = self.purview_client.get_entity_lineage(project_id)
guidAtlasEntityMap = lineage['guidEntityMap']

guidEntityMap = {}
finalGuidEntityMap = {}
edges = []
Expand Down Expand Up @@ -249,7 +266,7 @@ def search_entity(self,
Search entities with specified type that also match the keyword in a project
"""
query_result = self.purview_client.search_entities(keyword)
result = []
result = []
for entity in query_result:
qualified_name = entity["qualifiedName"]
entity_id = entity['id']
Expand Down Expand Up @@ -592,4 +609,5 @@ def _get_id_by_qualfiedName(self, qualifiedName):
for entity in entities:
if entity.get('qualifiedName') == qualifiedName:
return entity.get('id')