Beispiel #1
0
    def load_and_parse(cls, root_project, all_projects, macros=None):
        """Load and parse archives in a list of projects. Returns a dict
           that maps unique ids onto ParsedNodes"""

        archives = []
        to_return = {}

        for name, project in all_projects.items():
            archives = archives + cls.parse_archives_from_project(project)

        # We're going to have a similar issue with parsed nodes, if we want to
        # make parse_node return those.
        for a in archives:
            # archives have a config, but that would make for an invalid
            # UnparsedNode, so remove it and pass it along to parse_node as an
            # argument.
            archive_config = a.pop('config')
            archive = UnparsedNode(**a)
            node_path = cls.get_path(archive.get('resource_type'),
                                     archive.get('package_name'),
                                     archive.get('name'))

            to_return[node_path] = cls.parse_node(
                archive,
                node_path,
                root_project,
                all_projects.get(archive.get('package_name')),
                all_projects,
                macros=macros,
                archive_config=archive_config)

        return to_return
Beispiel #2
0
    def parse_sql_nodes(cls, nodes, root_project, projects,
                        tags=None, macros=None):

        if tags is None:
            tags = []

        if macros is None:
            macros = {}

        to_return = {}
        disabled = []

        for n in nodes:
            node = UnparsedNode(**n)
            package_name = node.get('package_name')

            node_path = cls.get_path(node.get('resource_type'),
                                     package_name,
                                     node.get('name'))

            node_parsed = cls.parse_node(node,
                                         node_path,
                                         root_project,
                                         projects.get(package_name),
                                         projects,
                                         tags=tags,
                                         macros=macros)

            # Ignore disabled nodes
            if not node_parsed['config']['enabled']:
                disabled.append(node_parsed['fqn'])
                continue

            # Check for duplicate model names
            existing_node = to_return.get(node_path)
            if existing_node is not None:
                dbt.exceptions.raise_duplicate_resource_name(
                        existing_node, node_parsed)

            to_return[node_path] = node_parsed

        return to_return, disabled