Přeskočit na obsah
_CORE
AI & Agentic Systems Core Informační Systémy Cloud & Platform Engineering Data Platforma & Integrace Security & Compliance QA, Testing & Observability IoT, Automatizace & Robotika Mobile & Digital Banky & Finance Pojišťovnictví Veřejná správa Obrana & Bezpečnost Zdravotnictví Energetika & Utility Telco & Média Průmysl & Výroba Logistika & E-commerce Retail & Loyalty
Reference Technologie Blog Knowledge Base O nás Spolupráce Kariéra
Pojďme to probrat

dbt — transformace dat ve warehouse pomocí SQL

01. 01. 2024 1 min čtení intermediate

dbt revolucionizoval práci s daty. SQL modely, které dbt kompiluje a spouští — verzování, testování a dokumentace jako kód.

Co je dbt

dbt transformuje data ve warehouse pomocí SELECT statementů. Stará se o DDL, závislosti, testy a dokumentaci.

dbt modely

-- models/staging/stg_orders.sql
WITH source AS (
    SELECT * FROM {{ source('raw', 'orders') }}
)
SELECT
    id AS order_id,
    user_id AS customer_id,
    created_at AS order_date,
    amount_cents / 100.0 AS amount_eur,
    status
FROM source
WHERE status != 'test'

Testy

# schema.yml
version: 2
models:
  - name: stg_orders
    columns:
      - name: order_id
        tests: [unique, not_null]
      - name: amount_eur
        tests: [not_null]

Incremental modely

{{ config(materialized='incremental', unique_key='order_id') }}

SELECT * FROM {{ ref('stg_orders') }}
{% if is_incremental() %}
WHERE order_date > (SELECT MAX(order_date) FROM {{ this }})
{% endif %}

Shrnutí

dbt je standard pro transformace ve warehouse. SQL modely, testy a dokumentace jako kód.

dbtsqltransformaceanalytics engineering