0% fanden dieses Dokument nützlich (0 Abstimmungen)
9 Ansichten5 Seiten

Quick Code References

Das Dokument enthält eine Sammlung von dbt-Befehlen, die für verschiedene Operationen wie das Ausführen von Modellen, das Generieren von Dokumentationen und das Testen von Daten verwendet werden. Es beschreibt auch Konfigurationen für Snapshots, Quellenfrische, Tests und inkrementelle Modelle sowie einige Docker-Befehle zur Interaktion mit Containern. Die Beispiele sind spezifisch für eine Snowflake-Umgebung und beinhalten sowohl allgemeine als auch spezifische Anwendungsfälle.

Hochgeladen von

Raja Thangarajan
Copyright
© All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als TXT, PDF, TXT herunterladen oder online auf Scribd lesen
0% fanden dieses Dokument nützlich (0 Abstimmungen)
9 Ansichten5 Seiten

Quick Code References

Das Dokument enthält eine Sammlung von dbt-Befehlen, die für verschiedene Operationen wie das Ausführen von Modellen, das Generieren von Dokumentationen und das Testen von Daten verwendet werden. Es beschreibt auch Konfigurationen für Snapshots, Quellenfrische, Tests und inkrementelle Modelle sowie einige Docker-Befehle zur Interaktion mit Containern. Die Beispiele sind spezifisch für eine Snowflake-Umgebung und beinhalten sowohl allgemeine als auch spezifische Anwendungsfälle.

Hochgeladen von

Raja Thangarajan
Copyright
© All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als TXT, PDF, TXT herunterladen oder online auf Scribd lesen

###################################################################################

##########################################
##################################################
##################################################
################################################## dbt Terminal Commands
##################################################
##################################################
##################################################
###################################################################################
##########################################

## Sample commands ( the --debug option will show the detailed logs in the terminal

dbt run --profiles-dir profiles/snowflake --target trial_acc --models


demo_snowflake_db.sample_select_demo_records --debug

dbt build --profiles-dir profiles/snowflake --target trial_acc --select


demo_snowflake_db.sample_select_demo_records --defer --state <Path to the
[Link] file from Production / other Envs >

## Generating the document for all the models


dbt docs generate --profiles-dir profiles/snowflake --target trial_acc --debug

## Generating the document for specific model


dbt docs generate --profiles-dir profiles/snowflake --target trial_acc --models
demo_snowflake_db.sample_select_demo_records

# Running the webserver for viewing the generated docs


dbt docs serve --port 8001

dbt docs serve --host ""

# Display the installed dbt version


dbt --version

## Trigerring a Macro

dbt run-operation --profiles-dir profiles/snowflake union_tables_by_prefix

## Trigerring a Macro which has parameters


dbt run-operation --profiles-dir profiles/snowflake union_tables_by_prefix --args
'{DATABASE: DBT_DATABASE_DEV ,SCHEMA: DBT_CLONED_SCHEMA,PREFIX: fct}'

###################################################################################
#################################
##################################################
##################################################
################################################## Misc
##################################################
##################################################
##################################################
###################################################################################
#################################

#################################### START Snapshot Configs


#####################################################

### Using Strategy = TIMESTAMP


{% snapshot snap_products %}

{{
config(
target_database='analytics',
target_schema='dbt_jcohen_snapshots',
unique_key='id',
strategy='timestamp',
updated_at='updated_at',
)
}}

select * from {{ source('jaffle_shop_ext','products') }}


{% endsnapshot %}

### Using Strategy = CHECK

{{
config(
target_schema='snapshots', -- The schema where the snapshot data is
stored
target_database='analytics', -- The database where the snapshot is stored
unique_key='customer_id', -- The unique identifier for the record
strategy='check', -- The method of comparison (e.g., check vs
timestamp)
check_cols=['name', 'email'] -- The columns to check for changes
)
}}

SELECT
id AS customer_id,
name,
email,
current_timestamp AS snapshot_time
FROM
{{ ref('customers') }} -- The source table
{% endsnapshot %}

#################################### END Snapshot Configs


#####################################################

#################################### START Source Freshness


#######################################################

version: 2

sources:
- name: jaffle_shop
database: raw
schema: jaffle_shop
tables:
- name: orders
loaded_at_field: _etl_loaded_at
freshness:
warn_after: {count: 12, period: hour}
error_after: {count: 24, period: hour}

# Validate the source freshnes using the below command

dbt source freshness

#################################### END Source Freshness


#######################################################

#################################### START Testing Options


#######################################################

version: 2

models:
- name: stg_jaffle_shop__customers
columns:
- name: customer_id
tests:
- unique
- not_null
- name: stg_jaffle_shop__orders
columns:
- name: order_id
tests:
- unique
- not_null
- name: status
tests:
- accepted_values:
values:
- completed
- shipped
- returned
- return_pending
- placed
- name: customer_id
tests:
- relationships:
to: ref('stg_jaffle_shop__customers')
field: customer_id

#################################### END Testing Options


#######################################################

#################################### START Incremental


#######################################################

{{config (alias='nation_incr_str_merge',
materialized = 'incremental') }}

with
final as ( select * from {{ source('test_incremental','nation') }})
select * from final

{% if is_incremental() %}

where REC_CREATE_TIME > (select coalesce(max(REC_CREATE_TIME),'1900-01-01') from {{


this }} )

{% endif %}

#################################### END Incremental


#######################################################

#################################### START Sample SOURCE content and SCHEMA


#######################################################

version: 2

sources:
- name: raw_jaffle_shop
description: A replica of the postgres database used to power the jaffle_shop
app.
tables:
- name: customers
columns:
- name: id
description: Primary key of the table
tests:
- unique
- not_null

- name: orders
columns:
- name: id
description: Primary key of the table
tests:
- unique
- not_null

- name: user_id
description: Foreign key to customers

- name: status
tests:
- accepted_values:
values: ['placed', 'shipped', 'completed', 'return_pending',
'returned']

models:
- name: stg_jaffle_shop__customers
config:
tags: ['pii']
columns:
- name: customer_id
tests:
- unique
- not_null

- name: stg_jaffle_shop__orders
config:
materialized: view
columns:
- name: order_id
tests:
- unique
- not_null
- name: status
tests:
- accepted_values:
values: ['placed', 'shipped', 'completed', 'return_pending',
'returned']
config:
severity: warn

#################################### END Sample SOURCE content and SCHEMA


#######################################################

###################################################################################
####################################
##################################################
##################################################
################################################## Docker Commands
##################################################
##################################################
##################################################
###################################################################################
####################################

docker exec -it 72068e312d5d bash

docker cp "G://My Drive//dbt_cert_pract//" ffb33b44cdfc:/opt/airflow/

export ENVIRONMENT='dev'

dbt clone --profiles-dir profiles

Das könnte Ihnen auch gefallen