How to use get_or_create_relation method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

osmosis.py

Source:osmosis.py Github

copy

Full Screen

...477 setattr(node, RAW_CODE, original_sql)478 delattr(node, COMPILED_CODE)479 columns.extend(result.table.column_names)480 return columns481 def get_or_create_relation(482 self, database: str, schema: str, name: str483 ) -> Tuple[BaseRelation, bool]:484 """Get relation or create if not exists. Returns tuple of relation and485 boolean result of whether it existed ie: (relation, did_exist)"""486 ref = self.get_relation(database, schema, name)487 return (ref, True) if ref else (self.create_relation(database, schema, name), False)488 def create_schema(self, node: ManifestNode):489 """Create a schema in the database"""490 return self.execute_macro(491 "create_schema",492 kwargs={"relation": self.create_relation_from_node(node)},493 )494 def materialize(495 self, node: ManifestNode, temporary: bool = True...

Full Screen

Full Screen

diff.py

Source:diff.py Github

copy

Full Screen

...42 original_node = runner.compile_node(original_node).node43 changed_node = runner.compile_node(changed_node).node44 # Lookup and resolve original ref based on git sha45 git_node_parts = original_node.database, "dbt_diff", git_node_name46 ref_A, did_exist = runner.get_or_create_relation(*git_node_parts)47 if not did_exist:48 logger().info("Creating new relation for %s", ref_A)49 with runner.adapter.connection_named("dbt-osmosis"):50 runner.execute_macro(51 "create_schema",52 kwargs={"relation": ref_A},53 )54 runner.execute_macro(55 "create_table_as",56 kwargs={57 "sql": original_node.compiled_sql,58 "relation": ref_A,59 "temporary": True,60 },61 run_compiled_sql=True,62 )63 # Resolve modified fake ref based on hash of it compiled SQL64 temp_node_name = "z_" + hashlib.md5(changed_node.compiled_sql.encode("utf-8")).hexdigest()[-7:]65 git_node_parts = original_node.database, "dbt_diff", temp_node_name66 ref_B, did_exist = runner.get_or_create_relation(*git_node_parts)67 if not did_exist:68 ref_B = runner.adapter.Relation.create(*git_node_parts)69 logger().info("Creating new relation for %s", ref_B)70 with runner.adapter.connection_named("dbt-osmosis"):71 runner.execute_macro(72 "create_schema",73 kwargs={"relation": ref_B},74 )75 runner.execute_macro(76 "create_table_as",77 kwargs={78 "sql": original_node.compiled_sql,79 "relation": ref_B,80 "temporary": True,...

Full Screen

Full Screen

results_to_neo4j.py

Source:results_to_neo4j.py Github

copy

Full Screen

...42 node = py2neo.Node(*labels, **properties)43 self.tx.create(node)44 self.nodes.append(node)45 return node46 def get_or_create_relation(self, relation: py2neo.Relationship):47 for rel in self.relations:48 if rel == relation:49 return rel50 self.tx.merge(relation)51 self.relations.append(relation)52 return relation53 def create_node(self, *labels, **properties):54 node = py2neo.Node(*labels, **properties)55 self.tx.create(node)56 self.nodes.append(node)57 return node58 def get_node_by_property(self, *properties_values):59 for node in self.nodes:60 if set(properties_values).issubset(set(dict(node).values())):61 return node62 return None63 def add_relation(self, prop_a, prop_b, rel_type: str):64 node_a = self.get_node_by_property(prop_a)65 if node_a:66 node_b = self.get_node_by_property(prop_b)67 if node_b:68 self.tx.merge(py2neo.Relationship(node_a, rel_type, node_b))69 def __rec_browse_dir(self, path: Path, previous_node):70 labels, name, rel_type = extract_node(path.stem)71 current_node = self.get_or_create_node(*labels, name=name)72 if previous_node:73 self.get_or_create_relation(py2neo.Relationship(previous_node, rel_type, current_node))74 if path.is_dir():75 for elt in path.iterdir():76 self.__rec_browse_dir(elt, current_node)77 if path.is_file():78 if path.suffix == ".csv":79 with path.open() as file:80 sample = file.read(1024)81 dialect = csv.Sniffer().sniff(sample)82 file.seek(0)83 reader = csv.reader(file, dialect)84 header = next(reader, None)85 col_to_node = {}86 for col in range(len(header)):87 sub_labels, sub_name, sub_rel = extract_node(header[col])88 sub_node = self.create_node(*sub_labels, name=sub_name)89 self.get_or_create_relation(py2neo.Relationship(current_node, sub_rel, sub_node))90 col_to_node[col] = sub_node91 for row in reader:92 for col in range(len(row)):93 if row[col] != "":94 sub_sub_labels, sub_sub_name, sub_sub_rel = extract_node(row[col])95 sub_sub_node = self.get_or_create_node(*sub_sub_labels, name=sub_sub_name)96 self.get_or_create_relation(97 py2neo.Relationship(col_to_node[col], sub_sub_rel, sub_sub_node))98 elif path.suffix == ".lab":99 label = path.stem100 with path.open() as file:101 for name in file:102 node = self.get_node_by_property(name) # TODO Find a way to generalize GOI labels and TF labels103 if node is not None:104 node.update_labels(node.labels + [label])105 self.tx.push(node)106 elif path.suffix == ".rel":107 sep = re.compile('[\t|,; ]')108 with path.open() as file:109 for line in file:110 line.strip()...

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