-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Week 4 Challenge
- Loading branch information
Showing
10 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DBT_PROJECT_PATH = "/opt/dagster/dagster_home/project/dbt_test_project" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: 'test_dbt' | ||
version: '1.0.0' | ||
config-version: 2 | ||
|
||
profile: 'test_dbt' | ||
|
||
source-paths: ["models"] | ||
analysis-paths: ["analysis"] | ||
test-paths: ["tests"] | ||
data-paths: ["data"] | ||
macro-paths: ["macros"] | ||
snapshot-paths: ["snapshots"] | ||
|
||
target-path: "target" | ||
clean-targets: | ||
- "target" | ||
- "dbt_modules" | ||
|
||
models: | ||
test_dbt: | ||
example: | ||
+materialized: view |
5 changes: 5 additions & 0 deletions
5
week_4/project/dbt_test_project/models/my_first_dbt_model.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{ config(materialized='table') }} | ||
|
||
|
||
SELECT * | ||
FROM {{ source('postgresql', 'dbt_table') }} |
5 changes: 5 additions & 0 deletions
5
week_4/project/dbt_test_project/models/my_second_dbt_model.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{ config(materialized='table') }} | ||
|
||
|
||
SELECT column_2 AS my_column | ||
FROM {{ ref('my_first_dbt_model') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: my_first_dbt_model | ||
description: "A starter dbt model" | ||
columns: | ||
- name: column_1 | ||
tests: | ||
- not_null | ||
- name: column_2 | ||
tests: | ||
- not_null | ||
- name: column_3 | ||
tests: | ||
- not_null | ||
|
||
- name: my_second_dbt_model | ||
description: "A starter dbt model" | ||
columns: | ||
- name: my_column | ||
tests: | ||
- not_null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: postgresql | ||
schema: analytics | ||
tables: | ||
- name: dbt_table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
test_dbt: | ||
target: test | ||
outputs: | ||
test: | ||
type: postgres | ||
host: postgresql | ||
user: postgres_user | ||
password: postgres_password | ||
port: 5432 | ||
dbname: postgres_db | ||
schema: analytics | ||
threads: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
from dagster import repository | ||
from dagster import repository, with_resources | ||
from dagster_dbt import dbt_cli_resource | ||
from project.dbt_config import DBT_PROJECT_PATH | ||
from project.resources import postgres_resource | ||
from project.week_4 import ( | ||
get_s3_data_docker, | ||
process_data_docker, | ||
put_redis_data_docker, | ||
) | ||
from project.week_4_challenge import create_dbt_table, insert_dbt_data | ||
|
||
|
||
@repository | ||
def repo(): | ||
return [get_s3_data_docker, process_data_docker, put_redis_data_docker] | ||
|
||
|
||
@repository | ||
def assets_dbt(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from random import randint | ||
|
||
from dagster import AssetIn, asset | ||
from dagster_dbt import load_assets_from_dbt_project | ||
from project.dbt_config import DBT_PROJECT_PATH | ||
|
||
|
||
@asset( | ||
required_resource_keys={"database"}, | ||
op_tags={"kind": "postgres"}, | ||
) | ||
def create_dbt_table(context): | ||
sql = "CREATE SCHEMA IF NOT EXISTS analytics;" | ||
context.resources.database.execute_query(sql) | ||
sql = "CREATE TABLE IF NOT EXISTS analytics.dbt_table (column_1 VARCHAR(100), column_2 VARCHAR(100), column_3 VARCHAR(100));" | ||
context.resources.database.execute_query(sql) | ||
|
||
|
||
@asset( | ||
required_resource_keys={"database"}, | ||
op_tags={"kind": "postgres"}, | ||
) | ||
def insert_dbt_data(context, create_dbt_table): | ||
sql = "INSERT INTO analytics.dbt_table (column_1, column_2, column_3) VALUES ('A', 'B', 'C');" | ||
|
||
number_of_rows = randint(1, 10) | ||
for _ in range(number_of_rows): | ||
context.resources.database.execute_query(sql) | ||
context.log.info("Inserted a row") | ||
|
||
context.log.info("Batch inserted") | ||
|
||
|
||
@asset | ||
def final(context): | ||
context.log.info("Week 4 Challenge completed") |