Skip to content

Instantly share code, notes, and snippets.

@lbk-fishtown
lbk-fishtown / core.yml
Last active November 15, 2023 21:45
orders_summary.sql
- name: orders_summary
columns:
- name: customer_key
tests:
- not_null
@lbk-fishtown
lbk-fishtown / clone_prod_to_target.sql
Last active July 31, 2023 05:12
Clone & Reset Dev Environment Macros
{%- macro clone_prod_to_target(from_schema, from_database='analytics') -%}
{# The role that executes these statements will be the owner of the created schema and objects #}
{%- set sql -%}
create schema if not exists {{ target.database }}.{{ target.schema }} clone {{ from_database }}.{{ from_schema }} with managed access;
{%- endset -%}
{{ log("Cloning schema " ~ from_database ~ "." ~ from_schema ~ " into " ~ target.database | lower ~ "." ~ target.schema, info = true) }}
{%- do run_query(sql) -%}
@lbk-fishtown
lbk-fishtown / 01_stg_customers.sql
Last active February 13, 2023 00:24
Customers Table
with source as (
select * from {{ source('jaffle_shop', 'customers') }}
),
renamed as (
select
id as customer_id,
first_name,
last_name
from source
@lbk-fishtown
lbk-fishtown / store_test_failures.sql
Created June 16, 2022 23:43
dbt Store Test Failures Macro
/*
--add "{{ store_test_results(results) }}" to an on-run-end: block in dbt_project.yml
--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) -%}
{%- endfor -%}