From 0c51b6979772942307e660f040b717b8c7e85b29 Mon Sep 17 00:00:00 2001 From: Alex Noonan Date: Wed, 25 Sep 2024 13:09:04 -0400 Subject: [PATCH] minor code fixes for dagster uni dbt course --- .../lesson-4/3-debugging-failed-runs.md | 2 +- ...connecting-dbt-models-to-dagster-assets.md | 6 +- ...eating-assets-that-depend-on-dbt-models.md | 89 +++++++++---------- 3 files changed, 48 insertions(+), 49 deletions(-) diff --git a/docs/dagster-university/pages/dagster-dbt/lesson-4/3-debugging-failed-runs.md b/docs/dagster-university/pages/dagster-dbt/lesson-4/3-debugging-failed-runs.md index c0b06d52e354d..f4d5f9e477e63 100644 --- a/docs/dagster-university/pages/dagster-dbt/lesson-4/3-debugging-failed-runs.md +++ b/docs/dagster-university/pages/dagster-dbt/lesson-4/3-debugging-failed-runs.md @@ -18,7 +18,7 @@ To demonstrate, we’re going to intentionally make a bug in our dbt model code, from {{ source('raw_taxis', 'zones') }} ) select - {{ dbt_utils.generate_surrogate_key(['zone_id']) }} as zone_id, + zone_id, zone as zone_name, borough, zone_name like '%Airport' as is_airport, diff --git a/docs/dagster-university/pages/dagster-dbt/lesson-5/2-connecting-dbt-models-to-dagster-assets.md b/docs/dagster-university/pages/dagster-dbt/lesson-5/2-connecting-dbt-models-to-dagster-assets.md index 6f0851e9b674f..9f0cfb07b00cd 100644 --- a/docs/dagster-university/pages/dagster-dbt/lesson-5/2-connecting-dbt-models-to-dagster-assets.md +++ b/docs/dagster-university/pages/dagster-dbt/lesson-5/2-connecting-dbt-models-to-dagster-assets.md @@ -49,11 +49,11 @@ Open the `assets/dbt.py` file and do the following: 4. Now, let’s fill in the `get_asset_key` method with our own logic for defining asset keys. - 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`): + 1. There are two properties that we’ll want from `dbt_resource_props`: the `resource_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"] + resource_type = dbt_resource_props["resource_type"] name = dbt_resource_props["name"] ``` @@ -63,7 +63,7 @@ Open the `assets/dbt.py` file and do the following: ```python def get_asset_key(self, dbt_resource_props): - type = dbt_resource_props["resource_type"] + resource_type = dbt_resource_props["resource_type"] name = dbt_resource_props["name"] return AssetKey(f"taxi_{name}") diff --git a/docs/dagster-university/pages/dagster-dbt/lesson-5/3-creating-assets-that-depend-on-dbt-models.md b/docs/dagster-university/pages/dagster-dbt/lesson-5/3-creating-assets-that-depend-on-dbt-models.md index 185f3144a9233..10f750e8662cb 100644 --- a/docs/dagster-university/pages/dagster-dbt/lesson-5/3-creating-assets-that-depend-on-dbt-models.md +++ b/docs/dagster-university/pages/dagster-dbt/lesson-5/3-creating-assets-that-depend-on-dbt-models.md @@ -107,53 +107,52 @@ Now we’re ready to create the asset! At this point, the `airport_trips` asset should look like this: ```python - @asset( - deps=["location_metrics"], - ) - def airport_trips(database: DuckDBResource) -> MaterializeResult: - """ - A chart of where trips from the airport go - """ - - query = """ - select - zone, - destination_borough, - trips - from location_metrics - where from_airport - """ - - with database.get_connection() as conn: - airport_trips = conn.execute(query).fetch_df() - - fig = px.bar( - airport_trips, - x="zone", - y="trips", - color="destination_borough", - barmode="relative", - labels={ - "zone": "Zone", - "trips": "Number of Trips", - "destination_borough": "Destination Borough" - }, - ) - - pio.write_image(fig, constants.AIRPORT_TRIPS_FILE_PATH) - - with open(constants.AIRPORT_TRIPS_FILE_PATH, 'rb') as file: - image_data = file.read() + @asset( + deps=["location_metrics"], + ) + def airport_trips(database: DuckDBResource) -> MaterializeResult: + """ + A chart of where trips from the airport go + """ + + query = """ + select + zone, + destination_borough, + trips + from location_metrics + where from_airport + """ + with database.get_connection() as conn: + airport_trips = conn.execute(query).fetch_df() + + fig = px.bar( + airport_trips, + x="zone", + y="trips", + color="destination_borough", + barmode="relative", + labels={ + "zone": "Zone", + "trips": "Number of Trips", + "destination_borough": "Destination Borough" + }, + ) + + pio.write_image(fig, constants.AIRPORT_TRIPS_FILE_PATH) + + with open(constants.AIRPORT_TRIPS_FILE_PATH, 'rb') as file: + image_data = file.read() # Convert the image data to base64 - base64_data = base64.b64encode(image_data).decode('utf-8') - md_content = f"![Image](data:image/jpeg;base64,{base64_data})" - - return MaterializeResult( - metadata={ - "preview": MetadataValue.md(md_content) - } - ) + base64_data = base64.b64encode(image_data).decode('utf-8') + md_content = f"![Image](data:image/jpeg;base64,{base64_data})" + + return MaterializeResult( + metadata={ + "preview": MetadataValue.md(md_content) + } + ) ``` 5. Reload your code location to see the new `airport_trips` asset within the `metrics` group. Notice how the asset graph links the dependency between the `location_metrics` dbt asset and the new `airport_trips` chart asset: