Skip to content

Commit

Permalink
Add dbt project with an example of test with multiple parents
Browse files Browse the repository at this point in the history
  • Loading branch information
tatiana committed Dec 27, 2024
1 parent 344913f commit 4fbe0ed
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dev/dags/dbt/multiple_parents_test/dbt_project.yml
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
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 dev/dags/dbt/multiple_parents_test/models/combined_model.sql
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
4 changes: 4 additions & 0 deletions dev/dags/dbt/multiple_parents_test/models/model_a.sql
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
4 changes: 4 additions & 0 deletions dev/dags/dbt/multiple_parents_test/models/model_b.sql
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
32 changes: 32 additions & 0 deletions dev/dags/dbt/multiple_parents_test/models/schema.yml
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: {}
12 changes: 12 additions & 0 deletions dev/dags/dbt/multiple_parents_test/profiles.yml
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

0 comments on commit 4fbe0ed

Please sign in to comment.