Beispiel #1
0
    def test_single_key_value_definition(self):
        dct = get_selector_dict('''\
            selectors:
              - name: nightly_selector
                definition:
                  tag: nightly
            ''')

        sel_dict = SelectorDict.parse_from_selectors_list(dct['selectors'])
        assert (sel_dict)
        expected = {'method': 'tag', 'value': 'nightly'}
        definition = sel_dict['nightly_selector']['definition']
        self.assertEqual(expected, definition)
Beispiel #2
0
    def test_parent_definition(self):
        dct = get_selector_dict('''\
            selectors:
              - name: kpi_nightly_selector
                definition:
                  '+exposure:kpi_nightly'
            ''')

        sel_dict = SelectorDict.parse_from_selectors_list(dct['selectors'])
        assert (sel_dict)
        expected = {
            'method': 'exposure',
            'value': 'kpi_nightly',
            'parents': True
        }
        definition = sel_dict['kpi_nightly_selector']['definition']
        self.assertEqual(expected, definition)
Beispiel #3
0
    def test_plus_definition(self):
        dct = get_selector_dict('''\
            selectors:
              - name: my_model_children_selector
                definition:
                  'my_model+2'
            ''')

        sel_dict = SelectorDict.parse_from_selectors_list(dct['selectors'])
        assert (sel_dict)
        expected = {
            'method': 'fqn',
            'value': 'my_model',
            'children': True,
            'children_depth': '2'
        }
        definition = sel_dict['my_model_children_selector']['definition']
        self.assertEqual(expected, definition)
Beispiel #4
0
    def test_compare_cli_non_cli(self):
        dct = get_selector_dict('''\
            selectors:
              - name: nightly_diet_snowplow
                description: "This uses more CLI-style syntax"
                definition:
                  union:
                    - intersection:
                        - '@source:snowplow'
                        - 'tag:nightly'
                    - 'models/export'
                    - exclude:
                        - intersection:
                            - 'package:snowplow'
                            - 'config.materialized:incremental'
                        - export_performance_timing
              - name: nightly_diet_snowplow_full
                description: "This is a fuller YAML specification"
                definition:
                  union:
                    - intersection:
                        - method: source
                          value: snowplow
                          childrens_parents: true
                        - method: tag
                          value: nightly
                    - method: path
                      value: models/export
                    - exclude:
                        - intersection:
                            - method: package
                              value: snowplow
                            - method: config.materialized
                              value: incremental
                        - method: fqn
                          value: export_performance_timing
            ''')

        sel_dict = SelectorDict.parse_from_selectors_list(dct['selectors'])
        assert (sel_dict)
        with_strings = sel_dict['nightly_diet_snowplow']['definition']
        no_strings = sel_dict['nightly_diet_snowplow_full']['definition']
        self.assertEqual(with_strings, no_strings)
Beispiel #5
0
    def create_project(self, rendered: RenderComponents) -> 'Project':
        unrendered = RenderComponents(
            project_dict=self.project_dict,
            packages_dict=self.packages_dict,
            selectors_dict=self.selectors_dict,
        )
        dbt_version = _get_required_version(
            rendered.project_dict,
            verify_version=self.verify_version,
        )

        try:
            ProjectContract.validate(rendered.project_dict)
            cfg = ProjectContract.from_dict(rendered.project_dict)
        except ValidationError as e:
            raise DbtProjectError(validator_error_message(e)) from e
        # name/version are required in the Project definition, so we can assume
        # they are present
        name = cfg.name
        version = cfg.version
        # this is added at project_dict parse time and should always be here
        # once we see it.
        if cfg.project_root is None:
            raise DbtProjectError('cfg must have a project root!')
        else:
            project_root = cfg.project_root
        # this is only optional in the sense that if it's not present, it needs
        # to have been a cli argument.
        profile_name = cfg.profile
        # these are all the defaults
        source_paths: List[str] = value_or(cfg.source_paths, ['models'])
        macro_paths: List[str] = value_or(cfg.macro_paths, ['macros'])
        data_paths: List[str] = value_or(cfg.data_paths, ['data'])
        test_paths: List[str] = value_or(cfg.test_paths, ['test'])
        analysis_paths: List[str] = value_or(cfg.analysis_paths, [])
        snapshot_paths: List[str] = value_or(cfg.snapshot_paths, ['snapshots'])

        all_source_paths: List[str] = _all_source_paths(
            source_paths, data_paths, snapshot_paths, analysis_paths,
            macro_paths)

        docs_paths: List[str] = value_or(cfg.docs_paths, all_source_paths)
        asset_paths: List[str] = value_or(cfg.asset_paths, [])
        target_path: str = value_or(cfg.target_path, 'target')
        clean_targets: List[str] = value_or(cfg.clean_targets, [target_path])
        log_path: str = value_or(cfg.log_path, 'logs')
        modules_path: str = value_or(cfg.modules_path, 'dbt_modules')
        # in the default case we'll populate this once we know the adapter type
        # It would be nice to just pass along a Quoting here, but that would
        # break many things
        quoting: Dict[str, Any] = {}
        if cfg.quoting is not None:
            quoting = cfg.quoting.to_dict(omit_none=True)

        models: Dict[str, Any]
        seeds: Dict[str, Any]
        snapshots: Dict[str, Any]
        sources: Dict[str, Any]
        vars_value: VarProvider

        models = cfg.models
        seeds = cfg.seeds
        snapshots = cfg.snapshots
        sources = cfg.sources
        if cfg.vars is None:
            vars_dict: Dict[str, Any] = {}
        else:
            vars_dict = cfg.vars

        vars_value = VarProvider(vars_dict)
        on_run_start: List[str] = value_or(cfg.on_run_start, [])
        on_run_end: List[str] = value_or(cfg.on_run_end, [])

        query_comment = _query_comment_from_cfg(cfg.query_comment)

        packages = package_config_from_data(rendered.packages_dict)
        selectors = selector_config_from_data(rendered.selectors_dict)
        manifest_selectors: Dict[str, Any] = {}
        if rendered.selectors_dict and rendered.selectors_dict['selectors']:
            # this is a dict with a single key 'selectors' pointing to a list
            # of dicts.
            manifest_selectors = SelectorDict.parse_from_selectors_list(
                rendered.selectors_dict['selectors'])

        project = Project(
            project_name=name,
            version=version,
            project_root=project_root,
            profile_name=profile_name,
            source_paths=source_paths,
            macro_paths=macro_paths,
            data_paths=data_paths,
            test_paths=test_paths,
            analysis_paths=analysis_paths,
            docs_paths=docs_paths,
            asset_paths=asset_paths,
            target_path=target_path,
            snapshot_paths=snapshot_paths,
            clean_targets=clean_targets,
            log_path=log_path,
            modules_path=modules_path,
            quoting=quoting,
            models=models,
            on_run_start=on_run_start,
            on_run_end=on_run_end,
            seeds=seeds,
            snapshots=snapshots,
            dbt_version=dbt_version,
            packages=packages,
            manifest_selectors=manifest_selectors,
            selectors=selectors,
            query_comment=query_comment,
            sources=sources,
            vars=vars_value,
            config_version=cfg.config_version,
            unrendered=unrendered,
        )
        # sanity check - this means an internal issue
        project.validate()
        return project