33import json
44from typing import Any , Iterable , Optional , Union
55
6- from pydantic import BaseModel , Field , field_validator
6+ from pydantic import BaseModel , Field
77
88from dve .core_engine .configuration .v1 import V1EngineConfig , _LinkageConfig
99from dve .core_engine .type_hints import EntityName , ErrorCode , ErrorMessage
@@ -16,18 +16,16 @@ class HierarchyNode(BaseModel):
1616 """Stores entity hierarchy information"""
1717
1818 entity_name : str
19- children : Optional [list ["HierarchyNode" ]] = Field (default_factory = list )
20- mandatory : Optional [bool ] = False
21- join_fields : Optional [dict [str , str ]] = Field (default_factory = dict )
22- no_valid_records_error_code : Optional [ErrorCode ] = "NoValidRecords"
23- no_valid_records_error_message : Optional [ErrorMessage ] = (
24- "parent record removed as no valid child records"
25- )
19+ children : list ["HierarchyNode" ] = Field (default_factory = list )
20+ mandatory : bool = False
21+ join_fields : dict [str , str ] = Field (default_factory = dict )
22+ no_valid_records_error_code : ErrorCode = "NoValidRecords"
23+ no_valid_records_error_message : ErrorMessage = "parent record removed as no valid child records"
2624 missing_parent_id_error_code : Optional [ErrorCode ] = "MissingParentRecord"
2725 missing_parent_id_error_message : Optional [ErrorMessage ] = (
2826 "Records removed due to no valid parent record"
2927 )
30-
28+
3129 def get_descendents (self ) -> list [str ]:
3230 """Recursively list all descendents of the node"""
3331 descendents = []
@@ -79,24 +77,34 @@ def determine_trees(
7977 all_datasets : Iterable [str ], entity_relationships : dict [str , _LinkageConfig ]
8078 ) -> dict [EntityName , HierarchyNode ]:
8179 """Determine the entity hierarchy trees and store as HierarchyNodes"""
82- root_entities : dict [str , _LinkageConfig ] = dict (filter (lambda x : x [1 ].is_root_entity ,
83- entity_relationships .items ()))
80+ root_entities : dict [str , _LinkageConfig ] = dict (
81+ filter (lambda x : x [1 ].is_root_entity , entity_relationships .items ())
82+ )
8483 top_level_parents : dict [EntityName , HierarchyNode ] = {
85- entity_name : HierarchyNode (entity_name = entity_name ,
86- ** config .model_dump (exclude = {"parent_entity" ,
87- "missing_parent_id_error_code" ,
88- "missing_parent_id_error_message" }),
89- missing_parent_id_error_code = None ,
90- missing_parent_id_error_message = None )
84+ entity_name : HierarchyNode (
85+ entity_name = entity_name ,
86+ ** config .model_dump (
87+ exclude = {
88+ "parent_entity" ,
89+ "missing_parent_id_error_code" ,
90+ "missing_parent_id_error_message" ,
91+ }
92+ ),
93+ missing_parent_id_error_code = None ,
94+ missing_parent_id_error_message = None ,
95+ )
9196 for entity_name , config in root_entities .items ()
9297 }
93-
94- if default_roots := [ entity_name for entity_name in all_datasets
95- if not entity_name in entity_relationships ]:
98+
99+ if default_roots := [
100+ entity_name for entity_name in all_datasets if not entity_name in entity_relationships
101+ ]:
96102 for entity_name in default_roots :
97- top_level_parents [entity_name ] = HierarchyNode (entity_name = entity_name ,
98- missing_parent_id_error_code = None ,
99- missing_parent_id_error_message = None )
103+ top_level_parents [entity_name ] = HierarchyNode (
104+ entity_name = entity_name ,
105+ missing_parent_id_error_code = None ,
106+ missing_parent_id_error_message = None ,
107+ )
100108
101109 for name , linkage_detail in entity_relationships .items ():
102110 for main_entity , parent_node in top_level_parents .items ():
0 commit comments