Best Python code snippet using dbt-osmosis_python
osmosis.py
Source:osmosis.py
...454 return self.adapter.get_relation(database, schema, name)455 def create_relation(self, database: str, schema: str, name: str) -> BaseRelation:456 """Wrapper for `adapter.Relation.create`"""457 return self.adapter.Relation.create(database, schema, name)458 def create_relation_from_node(self, node: ManifestNode) -> BaseRelation:459 """Wrapper for `adapter.Relation.create_from`"""460 return self.adapter.Relation.create_from(self.config, node)461 def get_columns_in_relation(self, node: ManifestNode) -> List[str]:462 """Wrapper for `adapter.get_columns_in_relation`"""463 return self.adapter.get_columns_in_relation(self.create_relation_from_node(node))464 @lru_cache(maxsize=5)465 def get_columns(self, node: ManifestNode) -> List[ColumnInfo]:466 """Get a list of columns from a compiled node"""467 columns = []468 try:469 columns.extend(470 [c.name for c in self.get_columns_in_relation(self.create_relation_from_node(node))]471 )472 except CompilationException:473 original_sql = str(getattr(node, RAW_CODE))474 # TODO: account for `TOP` syntax475 setattr(node, RAW_CODE, f"select * from ({original_sql}) limit 0")476 result = self.execute_node(node)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 = True496 ) -> Tuple[AdapterResponse, None]:497 """Materialize a table in the database"""498 return self.adapter_execute(499 # Returns CTAS string so send to adapter.execute500 self.execute_macro(501 "create_table_as",502 kwargs={503 "sql": getattr(node, COMPILED_CODE),504 "relation": self.create_relation_from_node(node),505 "temporary": temporary,506 },507 ),508 auto_begin=True,509 )510class DbtProjectContainer:511 """This class manages multiple DbtProjects which each correspond512 to a single dbt project on disk. This is mostly for osmosis server use"""513 def __init__(self):514 self._projects: Dict[str, DbtProject] = OrderedDict()515 self._default_project: Optional[str] = None516 def get_project(self, project_name: str) -> Optional[DbtProject]:517 """Primary interface to get a project and execute code"""518 return self._projects.get(project_name)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!