Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbt: Example project using delete+insert materialization #784

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 4 additions & 1 deletion framework/dbt/basic/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# dbt CrateDB Example
# dbt CrateDB basic example

## What's Inside
A basic model materialization using the `table` strategy.

## Setup
```shell
Expand Down
4 changes: 2 additions & 2 deletions framework/dbt/basic/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
name: 'dbt_cratedb_example'
name: 'testdrive_basic'
version: '1.0.0'
config-version: 2

Expand Down Expand Up @@ -31,7 +31,7 @@ clean-targets: # directories to be removed by `dbt clean`
# directory as views. These settings can be overridden in the individual model
# files using the `{{ config(...) }}` macro.
models:
dbt_cratedb_example:
testdrive_basic:
# Config indicated by + and applies to all files under models/example/
example:
+materialized: view
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"]]
Loading