-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dbt project with an example of test with multiple parents
- Loading branch information
Showing
7 changed files
with
97 additions
and
0 deletions.
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,12 @@ | ||
name: 'my_dbt_project' | ||
version: '1.0.0' | ||
config-version: 2 | ||
|
||
profile: 'default' | ||
|
||
model-paths: ["models"] | ||
test-paths: ["tests"] | ||
|
||
models: | ||
my_dbt_project: | ||
materialized: view |
17 changes: 17 additions & 0 deletions
17
dev/dags/dbt/multiple_parents_test/macros/custom_test_combined_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,17 @@ | ||
{% test custom_test_combined_model(model) %} | ||
WITH source_data AS ( | ||
SELECT id FROM {{ ref('model_a') }} | ||
), | ||
combined_data AS ( | ||
SELECT id FROM {{ model }} | ||
) | ||
SELECT | ||
s.id | ||
FROM | ||
source_data s | ||
LEFT JOIN | ||
combined_data c | ||
ON s.id = c.id | ||
WHERE | ||
c.id IS NULL | ||
{% endtest %} |
16 changes: 16 additions & 0 deletions
16
dev/dags/dbt/multiple_parents_test/models/combined_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,16 @@ | ||
-- Combine data from model_a and model_b | ||
WITH model_a AS ( | ||
SELECT * FROM {{ ref('model_a') }} | ||
), | ||
model_b AS ( | ||
SELECT * FROM {{ ref('model_b') }} | ||
) | ||
SELECT | ||
a.id, | ||
a.name, | ||
b.created_at | ||
FROM | ||
model_a AS a | ||
JOIN | ||
model_b AS b | ||
ON a.id = b.id |
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,4 @@ | ||
-- Create a simple table | ||
SELECT 1 AS id, 'Alice' AS name | ||
UNION ALL | ||
SELECT 2 AS id, 'Bob' AS name |
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,4 @@ | ||
-- Create another simple table | ||
SELECT 1 AS id, '2024-12-25'::date AS created_at | ||
UNION ALL | ||
SELECT 2 AS id, '2024-12-26'::date AS created_at |
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,32 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: model_a | ||
description: "A simple model with user data" | ||
tests: | ||
- unique: | ||
column_name: id | ||
|
||
- name: model_b | ||
description: "A simple model with date data" | ||
tests: | ||
- unique: | ||
column_name: id | ||
|
||
- name: combined_model | ||
description: "Combines data from model_a and model_b" | ||
columns: | ||
- name: id | ||
tests: | ||
- not_null | ||
|
||
- name: name | ||
tests: | ||
- not_null | ||
|
||
- name: created_at | ||
tests: | ||
- not_null | ||
|
||
tests: | ||
- custom_test_combined_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,12 @@ | ||
default: | ||
target: dev | ||
outputs: | ||
dev: | ||
type: postgres | ||
host: "{{ env_var('POSTGRES_HOST') }}" | ||
user: "{{ env_var('POSTGRES_USER') }}" | ||
password: "{{ env_var('POSTGRES_PASSWORD') }}" | ||
port: "{{ env_var('POSTGRES_PORT') | int }}" | ||
dbname: "{{ env_var('POSTGRES_DB') }}" | ||
schema: "{{ env_var('POSTGRES_SCHEMA') }}" | ||
threads: 4 |