Skip to content

Commit

Permalink
Update code snippets post-review
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed May 14, 2024
1 parent 9879642 commit d86c381
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 82 deletions.
60 changes: 30 additions & 30 deletions docs/content/integrations/dbt/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,52 +91,52 @@ my_dagster_project
```python file=/integrations/dbt/quickstart.py startafter=start_dbt_project_example endbefore=end_dbt_project_example
from pathlib import Path

from dagster_dbt import DbtProject
from dagster_dbt import DbtProject

RELATIVE_PATH_TO_MY_DBT_PROJECT = "./my_dbt_project"
RELATIVE_PATH_TO_MY_DBT_PROJECT = "./my_dbt_project"

my_project = DbtProject(
project_dir=Path(__file__)
.joinpath("..", RELATIVE_PATH_TO_MY_DBT_PROJECT)
.resolve(),
)
my_project = DbtProject(
project_dir=Path(__file__)
.joinpath("..", RELATIVE_PATH_TO_MY_DBT_PROJECT)
.resolve(),
)
```

3. In your `assets.py` file, add the following code. Using the `dbt_assets` decorator allows Dagster to create a definition for how to compute a set of dbt resources, described by a `manifest.json`.

```python file=/integrations/dbt/quickstart.py startafter=start_dbt_assets_example endbefore=end_dbt_assets_example
from dagster import AssetExecutionContext
from dagster_dbt import DbtCliResource, dbt_assets
from dagster_dbt import DbtCliResource, dbt_assets

from .project import my_project
from .project import my_project

@dbt_assets(manifest=my_project.manifest_path)
def my_dbt_assets(context: AssetExecutionContext, dbt: DbtCliResource):
yield from dbt.cli(["build"], context=context).stream()
@dbt_assets(manifest=my_project.manifest_path)
def my_dbt_assets(context: AssetExecutionContext, dbt: DbtCliResource):
yield from dbt.cli(["build"], context=context).stream()
```

4. In your `definitions.py` file, update your Definitions object to include the newly created objects.

```python file=/integrations/dbt/quickstart.py startafter=start_dbt_definitions_example endbefore=end_dbt_definitions_example
from dagster import Definitions
from dagster_dbt import DbtCliResource

from .assets import my_dbt_assets
from .project import my_project

defs = Definitions(
assets=[
# your other assets here,
my_dbt_assets
],
jobs=[
# your jobs here
],
resources={
# your other resources here,
"dbt": DbtCliResource(project_dir=my_project),
},
)
from dagster_dbt import DbtCliResource

from .assets import my_dbt_assets
from .project import my_project

defs = Definitions(
...,
assets=[
...,
# Add the dbt assets alongside your other asset
my_dbt_assets
],
resources={
...,
# Add the dbt resource alongside your other resources
"dbt": DbtCliResource(project_dir=my_project),
},
)
```

With these changes, your existing Dagster project is ready to run your dbt project.
Expand Down
107 changes: 55 additions & 52 deletions examples/docs_snippets/docs_snippets/integrations/dbt/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,55 +43,58 @@ def my_dbt_assets(context: AssetExecutionContext, dbt: DbtCliResource):
# end_example


def dbt_project_example():
# start_dbt_project_example
from pathlib import Path

from dagster_dbt import DbtProject

RELATIVE_PATH_TO_MY_DBT_PROJECT = "./my_dbt_project"

my_project = DbtProject(
project_dir=Path(__file__)
.joinpath("..", RELATIVE_PATH_TO_MY_DBT_PROJECT)
.resolve(),
)
# end_dbt_project_example


def dbt_assets_example():
# start_dbt_assets_example
from dagster import AssetExecutionContext
from dagster_dbt import DbtCliResource, dbt_assets

from .project import my_project

@dbt_assets(manifest=my_project.manifest_path)
def my_dbt_assets(context: AssetExecutionContext, dbt: DbtCliResource):
yield from dbt.cli(["build"], context=context).stream()

# end_dbt_assets_example


def dbt_definitions_example():
# start_dbt_definitions_example
from dagster import Definitions
from dagster_dbt import DbtCliResource

from .assets import my_dbt_assets
from .project import my_project

defs = Definitions(
assets=[
# your other assets here,
my_dbt_assets
],
jobs=[
# your jobs here
],
resources={
# your other resources here,
"dbt": DbtCliResource(project_dir=my_project),
},
)
# end_dbt_definitions_example
# start_dbt_project_example
from pathlib import Path

from dagster_dbt import DbtProject

RELATIVE_PATH_TO_MY_DBT_PROJECT = "./my_dbt_project"

my_project = DbtProject(
project_dir=Path(__file__)
.joinpath("..", RELATIVE_PATH_TO_MY_DBT_PROJECT)
.resolve(),
)
# end_dbt_project_example


# Using a string to avoid ruff adding a second blank line before the dbt_assets.
"""
# start_dbt_assets_example
from dagster import AssetExecutionContext
from dagster_dbt import DbtCliResource, dbt_assets
from .project import my_project
@dbt_assets(manifest=my_project.manifest_path)
def my_dbt_assets(context: AssetExecutionContext, dbt: DbtCliResource):
yield from dbt.cli(["build"], context=context).stream()
# end_dbt_assets_example
"""


# Using a string to avoid compilation error caused by the `...` placeholders
"""# start_dbt_definitions_example
from dagster import Definitions
from dagster_dbt import DbtCliResource
from .assets import my_dbt_assets
from .project import my_project
defs = Definitions(
...,
assets=[
...,
# Add the dbt assets alongside your other asset
my_dbt_assets
],
resources={
...,
# Add the dbt resource alongside your other resources
"dbt": DbtCliResource(project_dir=my_project),
},
)
# end_dbt_definitions_example
"""

0 comments on commit d86c381

Please sign in to comment.