Skip to content

Commit

Permalink
[daggy-u] fix indentation of indented code snippets (#22571)
Browse files Browse the repository at this point in the history
## Summary & Motivation

- Fixes indentation of code snippets for indented code blocks

## How I Tested These Changes

- Previewed rendered markdown

<img width="1106" alt="image"
src="https://github.com/dagster-io/dagster/assets/5807118/148b214a-318e-47f9-87e1-77ed302348aa">
  • Loading branch information
cmpadden committed Jun 24, 2024
1 parent 234b497 commit aa8ef88
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,35 @@ Open the `assets/dbt.py` file and do the following:
1. There are two properties that we’ll want from `dbt_resource_props`: the `type` (ex., model, source, seed, snapshot) and the `name`, such as `trips` or `stg_trips`. Access both of those properties from the `dbt_resource_props` argument and store them in their own respective variables (`type` and `name`):

```python
def get_asset_key(self, dbt_resource_props):
type = dbt_resource_props["resource_type"]
name = dbt_resource_props["name"]
def get_asset_key(self, dbt_resource_props):
type = dbt_resource_props["resource_type"]
name = dbt_resource_props["name"]
```

2. As mentioned above, the asset keys of our existing Dagster assets used by our dbt project are named `taxi_trips` and `taxi_zones`. If you were to print out the `name`, you’d see that the dbt sources are named `trips` and `zones`. Therefore, to match our asset keys up, we can prefix our keys with the string `taxi_` .

Copy and paste the following code to return an `AssetKey` of `AssetKey(f"taxi_{name}")`:

```python
def get_asset_key(self, dbt_resource_props):
type = dbt_resource_props["resource_type"]
name = dbt_resource_props["name"]
def get_asset_key(self, dbt_resource_props):
type = dbt_resource_props["resource_type"]
name = dbt_resource_props["name"]

return AssetKey(f"taxi_{name}")
return AssetKey(f"taxi_{name}")
```

3. You have full control over how each asset can be named, as you can define how asset keys are created. In our case we only want to rename the dbt sources, but we can keep the asset keys of the models the same.

The object-oriented pattern of the `DagsterDbtTranslator` means that we can leverage the existing implementations of the parent class by using the `super` method. We’ll use this pattern to customize how the sources are defined but default to the original logic for deciding the model asset keys. Copy and paste the code below to complete the `get_asset_key` function:

```python
def get_asset_key(self, dbt_resource_props):
resource_type = dbt_resource_props["resource_type"]
name = dbt_resource_props["name"]
if resource_type == "source":
return AssetKey(f"taxi_{name}")
else:
return super().get_asset_key(dbt_resource_props)
def get_asset_key(self, dbt_resource_props):
resource_type = dbt_resource_props["resource_type"]
name = dbt_resource_props["name"]
if resource_type == "source":
return AssetKey(f"taxi_{name}")
else:
return super().get_asset_key(dbt_resource_props)
```

You’ve successfully written your first translator!
Expand Down Expand Up @@ -140,4 +140,4 @@ else:
)
def dbt_analytics(context: AssetExecutionContext, dbt: DbtCliResource):
yield from dbt.cli(["build"], context=context).stream()
```
```

0 comments on commit aa8ef88

Please sign in to comment.