How to use build_node_ancestor_tree method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

osmosis.py

Source:osmosis.py Github

copy

Full Screen

...946 blueprint.keys(),947 )948 )949 )950 def build_node_ancestor_tree(951 self,952 node: ManifestNode,953 family_tree: Optional[Dict[str, List[str]]] = None,954 members_found: Optional[List[str]] = None,955 depth: int = 0,956 ) -> Dict[str, List[str]]:957 """Recursively build dictionary of parents in generational order"""958 if family_tree is None:959 family_tree = {}960 if members_found is None:961 members_found = []962 for parent in node.depends_on.nodes:963 member = self.dbt.nodes.get(parent, self.dbt.sources.get(parent))964 if member and parent not in members_found:965 family_tree.setdefault(f"generation_{depth}", []).append(parent)966 members_found.append(parent)967 # Recursion968 family_tree = self.build_node_ancestor_tree(969 member, family_tree, members_found, depth + 1970 )971 return family_tree972 def inherit_column_level_knowledge(973 self,974 family_tree: Dict[str, Any],975 ) -> Dict[str, Dict[str, Any]]:976 """Inherit knowledge from ancestors in reverse insertion order to ensure that the most recent ancestor is always the one to inherit from"""977 knowledge: Dict[str, Dict[str, Any]] = {}978 for generation in reversed(family_tree):979 for ancestor in family_tree[generation]:980 member: ManifestNode = self.dbt.nodes.get(ancestor, self.dbt.sources.get(ancestor))981 if not member:982 continue983 for name, info in member.columns.items():984 knowledge.setdefault(name, {"progenitor": ancestor})985 deserialized_info = info.to_dict()986 # Handle Info:987 # 1. tags are additive988 # 2. descriptions are overriden989 # 3. meta is merged990 # 4. tests are ignored until I am convinced those shouldn't be hand curated with love991 if deserialized_info["description"] in self.placeholders:992 deserialized_info.pop("description", None)993 deserialized_info["tags"] = list(994 set(deserialized_info.pop("tags", []) + knowledge[name].get("tags", []))995 )996 if not deserialized_info["tags"]:997 deserialized_info.pop("tags") # poppin' tags like Macklemore998 deserialized_info["meta"] = {999 **knowledge[name].get("meta", {}),1000 **deserialized_info["meta"],1001 }1002 if not deserialized_info["meta"]:1003 deserialized_info.pop("meta")1004 knowledge[name].update(deserialized_info)1005 return knowledge1006 def get_node_columns_with_inherited_knowledge(1007 self,1008 node: ManifestNode,1009 ) -> Dict[str, Dict[str, Any]]:1010 """Build a knowledgebase for the model based on iterating through ancestors"""1011 family_tree = self.build_node_ancestor_tree(node)1012 knowledge = self.inherit_column_level_knowledge(family_tree)1013 return knowledge1014 @staticmethod1015 def get_column_sets(1016 database_columns: Iterable[str],1017 yaml_columns: Iterable[str],1018 documented_columns: Iterable[str],1019 ) -> Tuple[List[str], List[str], List[str]]:1020 """Returns:1021 missing_columns: Columns in database not in dbt -- will be injected into schema file1022 undocumented_columns: Columns missing documentation -- descriptions will be inherited and injected into schema file where prior knowledge exists1023 extra_columns: Columns in schema file not in database -- will be removed from schema file1024 """1025 missing_columns = [...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run dbt-osmosis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful