def parse(self, parser): node = jinja2.nodes.Macro(lineno=next(parser.stream).lineno) materialization_name = \ parser.parse_assign_target(name_only=True).name adapter_name = 'default' node.args = [] node.defaults = [] while parser.stream.skip_if('comma'): target = parser.parse_assign_target(name_only=True) if target.name == 'default': pass elif target.name == 'adapter': parser.stream.expect('assign') value = parser.parse_expression() adapter_name = value.value else: dbt.exceptions.invalid_materialization_argument( materialization_name, target.name) node.name = dbt.utils.get_materialization_macro_name( materialization_name, adapter_name) node.body = parser.parse_statements(('name:endmaterialization',), drop_needle=True) return node
def parse(self, parser): node = jinja2.nodes.Macro(lineno=next(parser.stream).lineno) materialization_name = \ parser.parse_assign_target(name_only=True).name adapter_name = 'default' node.args = [] node.defaults = [] while parser.stream.skip_if('comma'): target = parser.parse_assign_target(name_only=True) if target.name == 'default': pass elif target.name == 'adapter': parser.stream.expect('assign') value = parser.parse_expression() adapter_name = value.value else: dbt.exceptions.invalid_materialization_argument( materialization_name, target.name) node.name = dbt.utils.get_materialization_macro_name( materialization_name, adapter_name) node.body = parser.parse_statements(('name:endmaterialization', ), drop_needle=True) return node
def _parse_import(self, parser, type): # We do not use parser.parse_import here because it is not clear whether # that function is part of the stable API (the documentation does not # mention that method). lineno = next(parser.stream).lineno import_node = jinja2.nodes.Import(lineno=lineno) import_node.template = parser.parse_expression() parser.stream.expect('name:as') import_node.target = parser.parse_assign_target(name_only=True).name if (parser.stream.current.test_any('name:with', 'name:without') and parser.stream.look().test('name:context')): import_node.with_context = next(parser.stream).value == 'with' parser.stream.skip() else: import_node.with_context = False # The import node will take care of loading the referenced template and # making its contents available under the specified variable name. We # still have to transform the variable by deserializing the JSON or YAML # string. We do this by applying the appropriate filter on the variable # and assigning the result back to the variable. filter_name = 'load_' + type filter_node = jinja2.nodes.Filter(jinja2.nodes.Name(import_node.target, 'load', lineno=lineno), filter_name, [], [], None, None, lineno=lineno) assign_node = jinja2.nodes.Assign(jinja2.nodes.Name(import_node.target, 'store', lineno=lineno), filter_node, lineno=lineno) return [import_node, assign_node]