Skip to content

Commit

Permalink
dbt: Add example project using delete+insert materialization
Browse files Browse the repository at this point in the history
Ephemeral and incremental materialization using the `delete+insert`
strategy.
  • Loading branch information
amotl committed Dec 23, 2024
1 parent 90bb5b2 commit 35f9f39
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ updates:
schedule:
interval: "daily"

- directory: "/framework/dbt/materialize"
package-ecosystem: "pip"
schedule:
interval: "daily"

- directory: "/framework/gradio"
package-ecosystem: "pip"
schedule:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/framework-dbt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ jobs:
pip install -r requirements.txt
dbt run --debug
dbt test --debug
- name: Validate framework/dbt/materialize
run: |
cd framework/dbt/materialize
pip install -r requirements.txt
dbt deps
dbt run --debug
dbt test --debug
5 changes: 5 additions & 0 deletions framework/dbt/materialize/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.user.yml
target/
dbt_packages/
logs/
package-lock.yml
25 changes: 25 additions & 0 deletions framework/dbt/materialize/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# dbt CrateDB example about model materialization

## What's Inside
Ephemeral and incremental materialization using the `delete+insert`
strategy.

## Setup
```shell
uv pip install -r requirements.txt
```

## Usage

Try running the following commands:
- `dbt run`
- `dbt test`

Optionally, use `--debug` to display executed SQL statements.

## Resources
- Learn more about dbt [in the docs](https://docs.getdbt.com/docs/introduction)
- Check out [Discourse](https://discourse.getdbt.com/) for commonly asked questions and answers
- Join the [chat](https://community.getdbt.com/) on Slack for live discussions and support
- Find [dbt events](https://events.getdbt.com) near you
- Check out [the blog](https://blog.getdbt.com/) for the latest news on dbt's development and best practices
12 changes: 12 additions & 0 deletions framework/dbt/materialize/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Project name and metadata.
name: 'testdrive_materialized'
version: '1.0.0'
config-version: 2

# Configure connection profile dbt uses for this project.
profile: 'cratedb_localhost'

# Directories to be removed by `dbt clean`.
clean-targets:
- "target"
- "dbt_packages"
3 changes: 3 additions & 0 deletions framework/dbt/materialize/models/example/jobslog.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ config(materialized='ephemeral') }}

select * from sys.jobs_log
12 changes: 12 additions & 0 deletions framework/dbt/materialize/models/example/test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{ config(materialized='incremental',
unique_key='id',
incremental_strategy='delete+insert'
)
}}

select * from {{ ref('jobslog') }}
{% if is_incremental() %}

where started >= (select max(started) from {{ this }})

{% endif %}
3 changes: 3 additions & 0 deletions framework/dbt/materialize/packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
- package: dbt-labs/dbt_utils
version: 1.3.0
12 changes: 12 additions & 0 deletions framework/dbt/materialize/profiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cratedb_localhost:
outputs:
dev:
type: cratedb
host: localhost
user: crate
pass: crate
port: 5432
dbname: crate
schema: doc
catalog: crate
target: dev
1 change: 1 addition & 0 deletions framework/dbt/materialize/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dbt-cratedb2>=0.0.1
25 changes: 25 additions & 0 deletions framework/dbt/materialize/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
models:
- name: test
columns:
- name: id
data_tests:
- unique
- not_null
- name: started
data_tests:
- unique
- not_null
- name: classification['type']
data_tests:
- accepted_values:
values: ['SELECT', 'INSERT', 'DELETE', 'DDL', 'MANAGEMENT', 'UNDEFINED']
- name: started
data_tests:
- dbt_utils.accepted_range:
min_value: 1734815733815
max_value: "now()"

#- name: classification['labels']
# data_tests:
# - accepted_values:
# values: [[], ["Collect"], ["Collect", "Order"], ["Collect", "Union"], ["Collect", "GroupHashAggregate"], ["Collect", "GroupHashAggregate", "Order"], ["InsertFromValues"], ["TableFunction"]]

0 comments on commit 35f9f39

Please sign in to comment.