Skip to content

Commit 7485d4e

Browse files
committed
working dbt test
1 parent 861b1e6 commit 7485d4e

File tree

9 files changed

+89
-2
lines changed

9 files changed

+89
-2
lines changed

stacks/airflow-trino-dbt/airflow.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ data:
111111
catchup=False
112112
) as dag:
113113
run_dbt = KubernetesPodOperator(
114-
image="oci.stackable.tech/sandbox/andrew/dbt-trino:0.0.1",
114+
image="oci.stackable.tech/sandbox/andrew/dbt-demo:0.0.1",
115115
image_pull_policy="IfNotPresent",
116116
cmds=["/bin/bash", "-x", "-euo", "pipefail", "-c"],
117-
arguments=["cd /dbt && export DBT_PROFILES_DIR=/dbt && dbt debug"],
117+
arguments=["cd /dbt/dbt_test && export DBT_PROFILES_DIR=/dbt/dbt_test && dbt debug && dbt run && dbt test"],
118118
name="run-dbt",
119119
task_id="dbt-test",
120120
get_logs=True,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM python:3.12-slim-bullseye AS builder
2+
3+
# Install build dependencies
4+
RUN apt-get update && apt-get install -y \
5+
git \
6+
gcc \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Create virtual environment
10+
RUN python -m venv /opt/venv
11+
ENV PATH="/opt/venv/bin:$PATH"
12+
13+
# Install Python packages
14+
COPY requirements.txt .
15+
RUN pip install --no-cache-dir --upgrade pip && \
16+
pip install --no-cache-dir -r requirements.txt
17+
18+
# Final stage
19+
FROM python:3.12-slim-bullseye
20+
21+
RUN apt-get update && apt-get install -y \
22+
git \
23+
curl \
24+
vim \
25+
&& rm -rf /var/lib/apt/lists/*
26+
27+
# Copy virtual environment from builder
28+
COPY --from=builder /opt/venv /opt/venv
29+
ENV PATH="/opt/venv/bin:$PATH"
30+
31+
WORKDIR /dbt
32+
33+
COPY dbt_test ./dbt_test
34+
35+
# Security: non-root user
36+
RUN useradd -m -u 1000 dbt && chown -R dbt:dbt /dbt
37+
USER dbt
38+
39+
ENV DBT_PROFILES_DIR=/dbt
40+
41+
CMD ["dbt", "run"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: 'dbt_demo'
2+
version: '1.0.0'
3+
config-version: 2
4+
profile: 'trino_demo'
5+
model-paths: ['models']
6+
macro-paths: ['macros']
7+
target-path: "target"
8+
clean-targets: ['target']
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% test id_in_range(model, column_name) %}
2+
select *
3+
from {{ model }}
4+
where {{ column_name }} < 1 or {{ column_name }} > 5
5+
{% endtest %}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{ config(materialized='table') }}
2+
select * from (values (1),(2),(3),(4),(5)) as t(id)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
3+
models:
4+
- name: my_table
5+
description: "A simple demo table with integer IDs"
6+
columns:
7+
- name: id
8+
description: "ID value"
9+
tests:
10+
- not_null # built-in dbt test
11+
- unique # optional: ensure no duplicates
12+
- id_in_range
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: []
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trino_demo:
2+
outputs:
3+
iceberg:
4+
type: trino
5+
method: ldap
6+
user: "{{ env_var('TRINO_USER') }}"
7+
password: "{{ env_var('TRINO_PASSWORD') }}"
8+
catalog: iceberg
9+
host: "{{ env_var('TRINO_HOST') }}"
10+
port: "{{ env_var('TRINO_PORT') | int }}"
11+
schema: dbt_schema3
12+
threads: 1
13+
cert: "{{ env_var('CERT_PATH') }}"
14+
verify: true
15+
16+
target: iceberg
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dbt-core==1.10.13
2+
dbt-trino==1.9.3

0 commit comments

Comments
 (0)