def get_hook_sql(self, adapter, hook, idx, num_hooks, extra_context): compiled = compile_node(adapter, self.config, hook, self.manifest, extra_context) statement = compiled.injected_sql hook_index = hook.index or num_hooks hook_obj = get_hook(statement, index=hook_index) return hook_obj.sql or ''
def run_hooks(self, adapter, hook_type, extra_context): nodes = self.manifest.nodes.values() hooks = get_nodes_by_tags(nodes, {hook_type}, NodeType.Operation) ordered_hooks = sorted(hooks, key=lambda h: h.get('index', len(hooks))) for i, hook in enumerate(ordered_hooks): model_name = hook.get('name') # This will clear out an open transaction if there is one. # on-run-* hooks should run outside of a transaction. This happens # b/c psycopg2 automatically begins a transaction when a connection # is created. TODO : Move transaction logic out of here, and # implement a for-loop over these sql statements in jinja-land. # Also, consider configuring psycopg2 (and other adapters?) to # ensure that a transaction is only created if dbt initiates it. adapter.clear_transaction(model_name) compiled = compile_node(adapter, self.config, hook, self.manifest, extra_context) statement = compiled.wrapped_sql hook_index = hook.get('index', len(hooks)) hook_dict = get_hook_dict(statement, index=hook_index) if dbt.flags.STRICT_MODE: Hook(**hook_dict) sql = hook_dict.get('sql', '') if len(sql.strip()) > 0: adapter.execute(sql, model_name=model_name, auto_begin=False, fetch=False) adapter.release_connection(model_name)
def get_hook_sql(self, adapter, hook, idx, num_hooks, extra_context): compiled = compile_node(adapter, self.config, hook, self.manifest, extra_context) statement = compiled.wrapped_sql hook_index = hook.get('index', num_hooks) hook_dict = get_hook_dict(statement, index=hook_index) if dbt.flags.STRICT_MODE: Hook(**hook_dict) return hook_dict.get('sql', '')
def _compile_ancestors(self, unique_id: str): # this just gets a transitive closure of the nodes. We could build a # special GraphQueue around this, but we do them all in the main thread # so we only care about preserving dependency order anyway if self.linker is None or self.manifest is None: raise InternalException( 'linker and manifest not set in _compile_ancestors') sorted_ancestors = self.linker.sorted_ephemeral_ancestors( self.manifest, unique_id, ) # We're just compiling, so we don't need to use a graph queue adapter = get_adapter(self.config) # type: ignore for unique_id in sorted_ancestors: # for each node, compile it + overwrite it parsed = self.manifest.expect(unique_id) self.manifest.nodes[unique_id] = compile_node(adapter, self.config, parsed, self.manifest, {}, write=False)
def compile(self, manifest): return compile_node(self.adapter, self.config, self.node, manifest, {}, write=False)
def compile(self, manifest): return compile_node(self.adapter, self.config, self.node, manifest, {})