Skip to content

Instantly share code, notes, and snippets.

@adinsmoor
adinsmoor / dbt_workshop_solution_ex1.sql
Created March 25, 2024 23:12
dbt Cloud Workshop: Mesh Solution Code
with campaigns as (
select * from {{ ref('stg_campaigns') }}
),
campaign_sequence as (
select * from {{ ref('stg_campaign_sequence') }}
),
final as (
select
campaign_sequence.campaign_id,
@adinsmoor
adinsmoor / _loading_source.yml
Last active April 29, 2023 06:54
autogen macro example
version: 2
sources:
- name: csv_load
database: adinsmoor_sandbox_dev
schema: loading_layer
tables:
- name: sw_line_input
- name: recipe
@adinsmoor
adinsmoor / dbt_nz_lab_starter_code.sql
Last active December 14, 2022 00:01
Starter code for hands-on exercises
-- Exercise 1: Define a staging model (stg_player.sql)
with player as (
select * from {{ source('fifa', 'player') }}
)
select
id as player_id
, affiliation_id
, concat(player_first_name, ' ', player_last_name) as player_name
@adinsmoor
adinsmoor / dbt_nz_lab_solution_code.sql
Last active December 12, 2023 13:36
Solution code for hands-on exercises
-- Exercise 1: Define a staging model (stg_player.sql)
with player as (
select * from {{ source('fifa', 'player') }}
)
select
id as player_id
, affiliation_id
, concat(player_first_name, ' ', player_last_name) as player_name
-- 1A) dim_customers SQL
select
store_id || "-" || cast(id as string) as unique_id
, id
, store_id
, name
, email
from {{ source('apjuice', 'users') }}
@adinsmoor
adinsmoor / dbt_grow_exercises.sql
Last active December 7, 2022 02:11
Grow Bootcamp _ dbt Solution Key
-- 1A) dim_customers SQL
select
store_id || "-" || cast(id as string) as unique_id
, id
, store_id
, name
, email
from {{ source('apjuice', 'users') }}
@adinsmoor
adinsmoor / event_logging_with_row_count.sql
Created August 1, 2022 05:55
Logging package customization example: add row_count
-- add a dispatch command to your dbt_project.yml file (where my_project is your project name)
dispatch:
- macro_namespace: logging
search_order: ['my_project', ' logging']
-- modify the macro with desired customizations
@adinsmoor
adinsmoor / store_test_failures.sql
Created August 1, 2022 05:02
dbt Store Test Failures Macro (for BigQuery)
/*
--add "{{ store_test_results(results) }}" to an on-run-end: block in dbt_project.yml
--run with dbt build --store-failures. The next v.1.0.X release of dbt will include post run hooks for dbt test!
*/
{% macro store_test_results(results) %}
{%- set test_results = [] -%}
{%- for result in results if result.node.resource_type == 'test' -%}
{%- set test_results = test_results.append(result) -%}