in dataplex-quickstart-labs/00-resources/scripts/python/business-glossary-import/bg_import/business_glossary_export_v2.py [0:0]
def compute_ancestors(child_id: str,
parent_mapping: Dict[str, str],
map_entry_id_to_entry_type: Dict[str, str]) -> List[Dict[str, str]]:
"""
Build the ancestors array for an entry (using entry IDs).
For each ancestor in the chain, construct its export resource using get_export_resource_by_id.
If no belongs_to exists, assume the glossary is the only ancestor.
Args:
child_id (str): The entry id of the child.
parent_mapping (Dict[str, str]): The parent mapping.
map_entry_id_to_entry_type (Dict[str, str]): The mapping of entry id to entry type.
Returns: List[Dict[str, str]]: The ancestors array.
"""
ancestors = []
if child_id in parent_mapping:
current = parent_mapping[child_id]
while True:
current_type = map_entry_id_to_entry_type.get(current, "glossary")
resource = get_export_resource_by_id(current, current_type)
glossary_child_entry_name = f"{DATAPLEX_ENTRY_GROUP}/entries/{resource}"
ancestors.append({
"name": glossary_child_entry_name,
"type": get_entry_type_name(current_type)
})
if current not in parent_mapping:
break
current = parent_mapping[current]
glossary_entry_name = f"{DATAPLEX_ENTRY_GROUP}/entries/projects/{PROJECT}/locations/{LOCATION}/glossaries/{GLOSSARY}"
ancestors.append({
"name": glossary_entry_name,
"type": get_entry_type_name("glossary")
})
ancestors.reverse()
return ancestors