Esempio n. 1
0
    def from_dict(cls, d: Dict[str, Any]) -> "NodeResult":
        """Constructs an instance of :class:`NodeResult <dagster_dbt.NodeResult>` from a dictionary.

        Args:
            d (Dict[str, Any]): A dictionary with key-values to construct a :class:`NodeResult
                <dagster_dbt.NodeResult>`.

        Returns:
            NodeResult: An instance of :class:`NodeResult <dagster_dbt.NodeResult>`.
        """
        node = check.dict_elem(d, "node")
        error = check.opt_str_elem(d, "error")
        execution_time = check.float_elem(d, "execution_time")
        thread_id = check.opt_str_elem(d, "thread_id")
        check.list_elem(d, "timing")
        step_timings = [
            StepTiming(
                name=d["name"],
                started_at=parser.isoparse(d["started_at"]),
                completed_at=parser.isoparse(d["completed_at"]),
            )
            for d in check.is_list(d["timing"], of_type=Dict)
        ]
        table = check.opt_dict_elem(d, "table")

        return cls(
            step_timings=step_timings,
            node=node,
            error=error,
            execution_time=execution_time,
            thread_id=thread_id,
            table=table,
        )
Esempio n. 2
0
    def from_dict(cls, d: Dict[str, Any]) -> "DbtResult":
        """Constructs an instance of :class:`DbtResult <dagster_dbt.DbtResult>` from a dictionary.

        Args:
            d (Dict[str, Any]): A dictionary with key-values to construct a :class:`DbtResult
                <dagster_dbt.DbtResult>`.

        Returns:
            DbtResult: An instance of :class:`DbtResult <dagster_dbt.DbtResult>`.
        """
        check.list_elem(d, "logs")
        logs = check.is_list(d["logs"], of_type=Dict)
        check.list_elem(d, "results")
        results = [
            NodeResult.from_dict(d)
            for d in check.is_list(d["results"], of_type=Dict)
        ]
        generated_at = check.str_elem(d, "generated_at")
        elapsed_time = check.float_elem(d, "elapsed_time")

        return cls(
            logs=logs,
            results=results,
            generated_at=generated_at,
            elapsed_time=elapsed_time,
        )
Esempio n. 3
0
def test_list_elem():
    list_value = ["blah", "blahblah"]
    ddict = {"listkey": list_value, "stringkey": "A", "nonekey": None}

    assert check.list_elem(ddict, "listkey") == list_value

    with pytest.raises(CheckError):
        assert check.list_elem(ddict, "nonekey") == []

    with pytest.raises(CheckError):
        assert check.list_elem(ddict, "nonexistantkey") == []

    with pytest.raises(CheckError):
        check.list_elem(ddict, "stringkey")
Esempio n. 4
0
def test_list_elem():
    list_value = ['blah', 'blahblah']
    ddict = {'listkey': list_value, 'stringkey': 'A', 'nonekey': None}

    assert check.list_elem(ddict, 'listkey') == list_value

    with pytest.raises(CheckError):
        assert check.list_elem(ddict, 'nonekey') == []

    with pytest.raises(CheckError):
        assert check.list_elem(ddict, 'nonexistantkey') == []

    with pytest.raises(CheckError):
        check.list_elem(ddict, 'stringkey')
Esempio n. 5
0
    def from_dict(cls, d: Dict[str, Any]) -> "NodeResult":
        """Constructs an instance of :class:`NodeResult <dagster_dbt.NodeResult>` from a dictionary.

        Args:
            d (Dict[str, Any]): A dictionary with key-values to construct a :class:`NodeResult
                <dagster_dbt.NodeResult>`.

        Returns:
            NodeResult: An instance of :class:`NodeResult <dagster_dbt.NodeResult>`.
        """
        check.dict_elem(d, "node")
        check.opt_str_elem(d, "error")
        check.float_elem(d, "execution_time")
        check.opt_str_elem(d, "thread_id")
        check.list_elem(d, "timing")
        check.is_list(d["timing"], of_type=Dict)
        check.opt_dict_elem(d, "table")

        return cls(step_timings=d.get("timing"), **d)
Esempio n. 6
0
    def from_dict(cls, d: Dict[str, Any]) -> "NodeResult":
        """Constructs an instance of :class:`NodeResult <dagster_dbt.NodeResult>` from a dictionary.

        Args:
            d (Dict[str, Any]): A dictionary with key-values to construct a :class:`NodeResult
                <dagster_dbt.NodeResult>`.

        Returns:
            NodeResult: An instance of :class:`NodeResult <dagster_dbt.NodeResult>`.
        """
        # When executing from the CLI in 0.19.x, we get unique_id as a top level attribute
        if "unique_id" in d:
            unique_id = check.str_elem(d, "unique_id")
            node = None
        # When executing via RPC server or via CLI in 0.18.x or lower, we get unique id within
        # "node" schema
        else:
            node = check.dict_elem(d, "node")
            unique_id = check.str_elem(node, "unique_id")
        error = check.opt_str_elem(d, "error")
        execution_time = check.float_elem(d, "execution_time")
        thread_id = check.opt_str_elem(d, "thread_id")
        check.list_elem(d, "timing")
        step_timings = [
            StepTiming(
                name=d["name"],
                started_at=parser.isoparse(d["started_at"]),
                completed_at=parser.isoparse(d["completed_at"]),
            ) for d in check.is_list(d["timing"], of_type=Dict)
        ]
        table = check.opt_dict_elem(d, "table")

        return cls(
            node=node,
            unique_id=unique_id,
            step_timings=step_timings,
            error=error,
            execution_time=execution_time,
            thread_id=thread_id,
            table=table,
        )
Esempio n. 7
0
def location_origins_from_config(
        workspace_config: Dict[str, object],
        yaml_path: str) -> Dict[str, RepositoryLocationOrigin]:
    workspace_config = ensure_workspace_config(workspace_config, yaml_path)
    location_configs = check.list_elem(workspace_config,
                                       "load_from",
                                       of_type=dict)
    location_origins: Dict[str, RepositoryLocationOrigin] = OrderedDict()
    for location_config in location_configs:
        origin = _location_origin_from_location_config(location_config,
                                                       yaml_path)
        check.invariant(
            location_origins.get(origin.location_name) is None,
            'Cannot have multiple locations with the same name, got multiple "{name}"'
            .format(name=origin.location_name, ),
        )

        location_origins[origin.location_name] = origin

    return location_origins