def update_parsed_node(self, parsed_node: IntermediateNode, config: ContextConfig) -> None: """Given the ContextConfig used for parsing and the parsed node, generate and set the true values to use, overriding the temporary parse values set in _build_intermediate_parsed_node. """ config_dict = config.build_config_dict() # Set tags on node provided in config blocks model_tags = config_dict.get('tags', []) parsed_node.tags.extend(model_tags) parsed_node.unrendered_config = config.build_config_dict( rendered=False) # do this once before we parse the node database/schema/alias, so # parsed_node.config is what it would be if they did nothing self.update_parsed_node_config(parsed_node, config_dict) self.update_parsed_node_name(parsed_node, config_dict) # at this point, we've collected our hooks. Use the node context to # render each hook and collect refs/sources hooks = list( itertools.chain(parsed_node.config.pre_hook, parsed_node.config.post_hook)) # skip context rebuilding if there aren't any hooks if not hooks: return # we could cache the original context from parsing this node. Is that # worth the cost in memory/complexity? context = self._context_for(parsed_node, config) for hook in hooks: get_rendered(hook.sql, context, parsed_node, capture_macros=True)
def config_dict( self, config: ContextConfig, ) -> Dict[str, Any]: config_dict = config.build_config_dict(base=True) self._mangle_hooks(config_dict) return config_dict
def initial_config(self, fqn: List[str]) -> ContextConfig: config_version = min( [self.project.config_version, self.root_project.config_version]) if config_version == 2: return ContextConfig( self.root_project, fqn, self.resource_type, self.project.project_name, ) else: raise InternalException( f'Got an unexpected project version={config_version}, ' f'expected 2')
def initial_config(self, fqn: List[str]) -> ContextConfigType: config_version = min( [self.project.config_version, self.root_project.config_version]) # grab a list of the existing project names. This is for var conversion all_projects = self.root_project.load_dependencies() if config_version == 1: return LegacyContextConfig( self.root_project.as_v1(all_projects), self.project.as_v1(all_projects), fqn, self.resource_type, ) elif config_version == 2: return ContextConfig( self.root_project, fqn, self.resource_type, self.project.project_name, ) else: raise InternalException( f'Got an unexpected project version={config_version}, ' f'expected 1 or 2')