Skip to content

Commit

Permalink
[daggy-u] [dbt] - Add Lesson 4 (DEV-58) (#19928)
Browse files Browse the repository at this point in the history
This PR adds Lesson 4 of the new dbt module to Dagster University.

TODOs:

- [x] Add screenshots
- [x] Verify code snippets match the final project

---------

Co-authored-by: Tim Castillo <[email protected]>
  • Loading branch information
2 people authored and alangenfeld committed Feb 28, 2024
1 parent 67b28a3 commit 929c35a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 5 additions & 0 deletions docs/dagster-university/pages/dagster-dbt.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ title: Dagster + dbt
- [Updating the Definitions object](/dagster-dbt/lesson-3/6-updating-the-definitions-object)
- [Viewing dbt models in the Dagster UI](/dagster-dbt/lesson-3/7-viewing-dbt-models-in-the-dagster-ui)
- [Knowledge check](/dagster-dbt/lesson-3/knowledge-check)
- Lesson 4: Improving development
- [Overview](/dagster-dbt/lesson-4/1-overview)
- [Speeding up the development cycle](/dagster-dbt/lesson-4/2-speeding-up-the-development-cycle)
- [Debugging failed runs](/dagster-dbt/lesson-4/3-debugging-failed-runs)
- [Customizing your execution](/dagster-dbt/lesson-4/4-customizing-your-execution)
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@ lesson: '4'

By now, you’ve had to run `dbt parse` and reload your code location quite frequently, which doesn’t feel like the cleanest developer experience.

Before we move on, we’ll reduce the number of steps in the feedback loop. We'll automate the `dbt parse` command by taking advantage of the `DbtCliResource` that we wrote earlier.
Before we move on, we’ll reduce the number of steps in the feedback loop by automating the `dbt parse` command. We’ll also take advantage of a few other aspects of the `DbtCliResource` that we wrote earlier.

---

## Automating running dbt parse in development

The first detail is that resources don’t need to be part of an asset to be executed. This means that once a `dbt_resource` is defined, you can use it to execute commands when your code location is being built. Rather than manually running `dbt parse`, let’s use the `dbt_resource` to run the command for us.
The first feature is that resources don’t need to be part of an asset to be executed. This means that once a `dbt_resource` is defined, you can use it to execute commands when your code location is being built. Rather than manually running `dbt parse`, let’s use the `dbt_resource` to run the command for us.

In `dbt.py`, import the `dbt_resource` with:

```python
from ..resources import dbt_resource
```

Afterward, above your `dbt_manifest_path` declaration, add this snippet to run `dbt parse`:
In `dbt.py`, above the `dbt_manifest_path` declaration, add this snippet to run `dbt parse`:

```python
dbt_resource.cli(["--quiet", "parse"]).wait()
Expand Down Expand Up @@ -74,5 +68,5 @@ This is great, however, it might feel a bit greedy and intensive to be constantl
.target_path.joinpath("manifest.json")
)
else:
dbt_manifest_path = os.path.join(DBT_DIRECTORY, "target", "manifest.json")
dbt_manifest_path = DBT_DIRECTORY.joinpath("target", "manifest.json")
```

0 comments on commit 929c35a

Please sign in to comment.