def compile_models(self, linker, models): compiled_models = { model: self.compile_model(linker, model, models) for model in models } sorted_models = [ find_model_by_fqn(models, fqn) for fqn in linker.as_topological_ordering() ] written_models = [] for model in sorted_models: injected_stmt = self.add_cte_to_rendered_query( linker, model, compiled_models) context = self.get_context(linker, model, models) wrapped_stmt = model.compile(injected_stmt, self.project, self.create_template, context) serialized = model.serialize() linker.update_node_data(tuple(model.fqn), serialized) if model.is_ephemeral: continue self.__write(model.build_path(), wrapped_stmt) written_models.append(model) return compiled_models, written_models
def compile_models(self, linker, models): compiled_models = { model: self.compile_model(linker, model, models) for model in models } sorted_models = [ find_model_by_fqn(models, fqn) for fqn in linker.as_topological_ordering() ] written_models = [] for model in sorted_models: # in-model configs were just evaluated. Evict anything that is # newly-disabled if not model.is_enabled: self.remove_node_from_graph(linker, model, models) continue injected_stmt = self.add_cte_to_rendered_query( linker, model, compiled_models) context = self.get_context(linker, model, models) wrapped_stmt = model.compile(injected_stmt, self.project, self.create_template, context) serialized = model.serialize() linker.update_node_data(tuple(model.fqn), serialized) if model.is_ephemeral: continue self.__write(model.build_path(), wrapped_stmt) written_models.append(model) return compiled_models, written_models
def skip_dependent(model): dependent_nodes = linker.get_dependent_nodes(model.fqn) for node in dependent_nodes: if node in selected_nodes: try: model_to_skip = find_model_by_fqn(models, node) model_to_skip.do_skip() except RuntimeError as e: pass
def remove_node_from_graph(self, linker, model, models): # remove the node children = linker.remove_node(tuple(model.fqn)) # check if we bricked the graph. if so: throw compilation error for child in children: other_model = find_model_by_fqn(models, child) if other_model.is_enabled: this_fqn = ".".join(model.fqn) that_fqn = ".".join(other_model.fqn) compiler_error( model, "Model '{}' depends on model '{}' which is " "disabled".format(that_fqn, this_fqn))
def as_concurrent_dep_list(self, linker, models, existing, target, limit_to): model_dependency_list = [] dependency_list = linker.as_dependency_list(limit_to) for node_list in dependency_list: level = [] for fqn in node_list: try: model = find_model_by_fqn(models, fqn) except RuntimeError as e: continue if model.should_execute(self.args, existing): model.prepare(existing, target) level.append(model) model_dependency_list.append(level) return model_dependency_list
def skip_dependent(model): dependent_nodes = linker.get_dependent_nodes(model.fqn) for node in dependent_nodes: model_to_skip = find_model_by_fqn(models, node) model_to_skip.do_skip()