Snippets Collections
{% macro generate_schema_name(custom_name, node) -%}

	{%- set default_schema = target.schema -%}
    {%- if custom_name is none -%}
    	
    	{{ default_schema }}
     
    {%- else -%}
    	
    	{{ default_schema }}_{{ custom_schema_name | trim }}
     
    {%- endif -%}

{%- endmacro -%}
    	
models:
  advanced_testing:
    # checks for every model under models directory should have unique and not_null test
    +required_tests: {"unique.*|not_null": 2}
    # checks for 'exclude' directory models should have unique and not_null test
    exclude:
      +required_tests: {"unique.*|not_null": 2}
	# checks for 'marts' directory models should have relationship test
    marts:
      +required_tests: {'relationship.*': 1}
select
	<column>
from <table>
group by 1
having count(*) > 1
version: 2

sources:
  - name: jaffle_shop
    description: a clone of a Postgres application database
    database: raw
    tables:
      - name: customers
        description: the raw customer data
        columns: 
          - name: id
            description: primary key of raw customer data
            tests: 
              - unique
              - not_null
      - name: orders
        description: the raw orders data
        columns: 
          - name: id
            description: primary key of raw orders data
            tests: 
              - unique
              - not_null
  
{% snapshot mock_orders %}

{% set new_schema = target.schema + '_snapshot' %}

{{
    config(
        target_database='analytics',
        target_schema=new_schema,
        unique_key='order_id',

        strategy='timestamp',
        updated_at='updated_at'
    )
}}

select * from analytics.{{ target.schema }}.mock_orders

{% endsnapshot %}
dbt run		--Materialize models
dbt snapshot	--Run models in snapshot folder only
dbt deps	--Run and install dependencies
dbt run-operation required_tests	--Run tests defined in dbt_project.yml
{{ 
	config(
    	materialized="incremental",
    	unique_key="page_view_id" 			-- This line is the key to replace duplicates
    )
}}

with events as (
  
	select * from {{ source('schema', 'table') }}
	{% if is_incremental() %}
    	where collector_tstamp >= ( select dateadd('day', -3, max(max_collector_tstamp)) from {{ 		this }}
    {% endif %}
    
)
-- for table
{{
  config(
  	materialized="table" 
  )
}}

-- for view
{{
  config(
  	materialized="view" 
  )
}}

-- for ephemeral
{{
  config(
  	materialized="ephemeral"
  )
}}

-- for incremental
{{
  config(
  	materialized="incremental"
  )
}}
star

Tue May 09 2023 07:45:26 GMT+0000 (Coordinated Universal Time)

#macro #dbt
star

Mon May 08 2023 05:12:28 GMT+0000 (Coordinated Universal Time)

#dbt #test #global
star

Mon May 08 2023 01:32:29 GMT+0000 (Coordinated Universal Time)

#dbt #test #ad-hoc
star

Sun May 07 2023 06:09:59 GMT+0000 (Coordinated Universal Time) https://docs.getdbt.com/docs/build/sources#tag/Runs/operation/cancelRunById

#dbt #yml #mart #source
star

Sat May 06 2023 15:30:45 GMT+0000 (Coordinated Universal Time)

#dbt #materialize
star

Sat May 06 2023 14:54:55 GMT+0000 (Coordinated Universal Time)

#dbt #commandline
star

Sat May 06 2023 14:45:35 GMT+0000 (Coordinated Universal Time)

#dbt #incremental #materialize
star

Sat May 06 2023 07:13:28 GMT+0000 (Coordinated Universal Time) https://docs.getdbt.com/docs/build/materializations

#dbt #config #materialize

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension