update structure

This commit is contained in:
Deeman
2025-07-08 22:41:59 +02:00
parent 0ef57f3e06
commit c3c281fcd8
24 changed files with 869 additions and 682 deletions

View File

View File

View File

@@ -0,0 +1,9 @@
AUDIT (
name assert_positive_order_ids,
);
SELECT *
FROM @this_model
WHERE
item_id < 0

View File

@@ -0,0 +1,59 @@
# --- Gateway Connection ---
gateways:
duckdb:
connection:
# For more information on configuring the connection to your execution engine, visit:
# https://sqlmesh.readthedocs.io/en/stable/reference/configuration/#connection
# https://sqlmesh.readthedocs.io/en/stable/integrations/engines/duckdb/#connection-options
type: duckdb
database: db.db
# concurrent_tasks: 1
# register_comments: True
# pre_ping: False
# pretty_sql: False
# catalogs:
# extensions:
# connector_config:
# secrets:
# filesystems:
# token:
default_gateway: duckdb
# --- Model Defaults ---
# https://sqlmesh.readthedocs.io/en/stable/reference/model_configuration/#model-defaults
model_defaults:
dialect: duckdb
start: 2025-07-07 # Start date for backfill history
cron: '@daily' # Run models daily at 12am UTC (can override per model)
# --- Linting Rules ---
# Enforce standards for your team
# https://sqlmesh.readthedocs.io/en/stable/guides/linter/
linter:
enabled: true
rules:
- ambiguousorinvalidcolumn
- invalidselectstarexpansion
# FLOW: Minimal prompts, automatic changes, summary output
# https://sqlmesh.readthedocs.io/en/stable/reference/configuration/#plan
plan:
no_diff: true # Hide detailed text differences for changed models
no_prompts: true # No interactive prompts
auto_apply: true # Apply changes automatically
# --- Optional: Set a default target environment ---
# This is intended for local development to prevent users from accidentally applying plans to the prod environment.
# It is a development only config and should NOT be committed to your git repo.
# https://sqlmesh.readthedocs.io/en/stable/guides/configuration/#default-target-environment
# Uncomment the following line to use a default target environment derived from the logged in user's name.
# default_target_environment: dev_{{ user() }}
# Example usage:
# sqlmesh plan # Automatically resolves to: sqlmesh plan dev_yourname
# sqlmesh plan prod # Specify `prod` to apply changes to production

Binary file not shown.

View File

View File

View File

@@ -0,0 +1,15 @@
MODEL (
name sqlmesh_example.full_model,
kind FULL,
cron '@daily',
grain item_id,
audits (assert_positive_order_ids),
);
SELECT
item_id,
COUNT(DISTINCT id) AS num_orders,
FROM
sqlmesh_example.incremental_model
GROUP BY item_id

View File

@@ -0,0 +1,19 @@
MODEL (
name sqlmesh_example.incremental_model,
kind INCREMENTAL_BY_TIME_RANGE (
time_column event_date
),
start '2020-01-01',
cron '@daily',
grain (id, event_date)
);
SELECT
id,
item_id,
event_date,
FROM
sqlmesh_example.seed_model
WHERE
event_date BETWEEN @start_date AND @end_date

View File

@@ -0,0 +1,13 @@
MODEL (
name sqlmesh_example.seed_model,
kind SEED (
path '../seeds/seed_data.csv'
),
columns (
id INTEGER,
item_id INTEGER,
event_date DATE
),
grain (id, event_date)
);

View File

@@ -0,0 +1,16 @@
[project]
name = "sqlmesh-duckdb"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
authors = [
{ name = "Deeman", email = "hendriknote@gmail.com" }
]
requires-python = ">=3.13"
dependencies = [
"sqlmesh>=0.200.0",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

View File

View File

@@ -0,0 +1,8 @@
id,item_id,event_date
1,2,2020-01-01
2,1,2020-01-01
3,3,2020-01-03
4,1,2020-01-04
5,1,2020-01-05
6,1,2020-01-06
7,1,2020-01-07
1 id item_id event_date
2 1 2 2020-01-01
3 2 1 2020-01-01
4 3 3 2020-01-03
5 4 1 2020-01-04
6 5 1 2020-01-05
7 6 1 2020-01-06
8 7 1 2020-01-07

View File

View File

@@ -0,0 +1,19 @@
test_example_full_model:
model: sqlmesh_example.full_model
inputs:
sqlmesh_example.incremental_model:
rows:
- id: 1
item_id: 1
- id: 2
item_id: 1
- id: 3
item_id: 2
outputs:
query:
rows:
- item_id: 1
num_orders: 2
- item_id: 2
num_orders: 1