Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Somtom
Somtom / data_regression_example__snapshot_data_diff.sql
Last active January 29, 2022 09:39
Dbt macro which generates a query for data diffs of snapshots
/*
This macro is used to generate a query for data regression diffs. The query
compares new data (where dbt_valid_to is not null) to old data which is not valid
anymore.
*/
{% macro
snapshot_data_diff(
table,
unique_key,
exclude=[
{% snapshot snapshot__fct_web_sessions %}
{{
config(
target_schema=generate_schema_name('snapshots'),
unique_key='session_id',
strategy='check',
check_cols = 'all',
invalidate_hard_deletes=True
)
@Somtom
Somtom / dbt_is_null_test_example.sql
Created January 29, 2022 09:34
Example for a dbt custom test to test a is_null condition
/*
Based on https://github.com/dbt-labs/dbt-labs-experimental-features/blob/master/snapshot-testing/macros/test_is_null.sql
*/
{% macro test_is_null(model, column_name) %}
SELECT *
FROM {{ model }}
WHERE {{ column_name }} IS NOT NULL
{% endmacro %}
@Somtom
Somtom / data_regression_example__historic_fct_web_sessions.sql
Created January 29, 2022 09:32
Snippet which shows an example for a data regression snapshot in dbt. It creates a simple snapshot of summary statistics for a table to monitor.
{% snapshot historic_fct_web_sessions %}
{{
config(
target_schema=generate_schema_name('snapshots'),
unique_key='date',
strategy='check',
check_cols=[
'duration_in_s',
'page_views',