Skip to main content

dbt adapter that runs DuckDB models on DuckHaven compute through the DuckHaven API

Project description

dbt-duckhaven

A dbt adapter that runs your DuckDB models on DuckHaven compute through the DuckHaven API. Instead of dbt opening its own in-process DuckDB, every statement is routed through the DuckHaven session API, which dispatches it to an agent. dbt authenticates as a DuckHaven service-account personal access token (PAT), and identifies itself to the server via the connector's User-Agent (dbt-duckhaven/<version>), so a dbt run is fully governed and attributable.

It reuses dbt-duckdb wholesale — the DuckDB dialect, the macros, and the Iceberg-aware materializations — and swaps only the connection layer for the duckhaven-sql-connector session client.

Install

pip install dbt-duckhaven

Configure (profiles.yml)

my_project:
  target: dev
  outputs:
    dev:
      type: duckhaven
      host: https://duckhaven.internal        # DuckHaven API base URL
      workspace: analytics                     # DuckHaven workspace slug
      token: "{{ env_var('DUCKHAVEN_PAT') }}"  # a DuckHaven PAT (dh_pat_…)
      agent: 00000000-0000-0000-0000-000000000000  # optional agent UUID; omit to auto-pick
      catalog: sales                           # required — dbt "database" → Polaris catalog
      schema: analytics                        # dbt "schema"   → Polaris namespace
      threads: 4

host, workspace, token, and catalog are required; agent is optional (omit to let the API pick a compatible connected agent). dbt init scaffolds these prompts for you.

What works

Materializations: table, seed, incremental, ephemeral, and snapshots (both the timestamp and check strategies). Generic and singular tests.

Incremental strategies

append, delete+insert, merge, and microbatch.

merge and microbatch require the agent's DuckDB to be 1.5.3 or newer — that is when duckdb-iceberg gained MERGE INTO for Iceberg tables. The adapter checks the agent's version and simply won't offer the strategies below that, so you get a clear dbt error instead of a mid-run failure.

merge emits the explicit MERGE INTO … WHEN MATCHED THEN UPDATE SET … WHEN NOT MATCHED THEN INSERT … form that duckdb-iceberg documents, rather than dbt-duckdb's DuckDB-native UPDATE BY NAME / INSERT BY NAME. merge_update_columns, merge_exclude_columns, and incremental_predicates work as usual. dbt-duckdb's DuckDB-only extras — merge_clauses, merge_returning_columns, merge_on_using_columns, merge_update_condition, merge_insert_condition, merge_update_set_expressionsraise a compile-time error rather than being silently ignored, because they depend on syntax Iceberg does not support.

Because Iceberg writes are merge-on-read, a merge target must leave write.update.mode / write.delete.mode at merge-on-read; DuckDB fails the statement otherwise.

Microbatch batches run serially, by design: concurrent batches would each take their own session (an agent admission slot) and race each other to commit to the same Iceberg table. Size batch_size so one batch finishes inside the server's 600s per-statement limit. Note that each batch leaves a session-local temp table behind for the life of the run (dbt-duckdb's incremental materialization only cleans those up on MotherDuck), and a session has a fixed 256 MiB budget — so very high batch counts in one run are untested.

Not supported (yet)

  • view materialization — DuckDB's Iceberg REST catalog does not implement CREATE VIEW, so view models fail. Use table instead.
  • Python models — DuckHaven agents execute SQL only; a Python model fails clearly.
  • Re-running dbt seed over an existing seed, on an older server — dbt's seed reset emits TRUNCATE TABLE. DuckHaven's statement policy admits it, but only since the release that added it; against a server predating that, the statement is rejected and you need dbt seed --full-refresh, which drops and recreates instead. The adapter does not detect which case you are in: the server's GET /api/version reports a build version and a coarse API-contract number, but TRUNCATE admission was an additive change that moves neither, and there is no feature registry to check — so the adapter cannot choose for you. Note that on Iceberg TRUNCATE is not the cheap metadata-only operation the name suggests — it writes positional delete files just as the equivalent DELETE would.
  • on-schema-change for incremental models — the ALTER-driven flow is untested here. (Snapshots do handle a new column: that path is covered.)
  • external materialization / dbt-duckdb source plugins — out of scope.

Model constraints

Polaris/Iceberg does not enforce relational constraints. In model contracts, not_null is enforced (rejected on write), while primary_key, foreign_key, and unique are documentation-only (not enforced), and check constraints are not supported. The adapter advertises this to dbt so contracts don't promise enforcement the backend can't provide.

Server requirement. The adapter needs a DuckHaven build whose SQL session/statement API is enabled and whose statement policy admits DESCRIBE (used for column metadata).

Concurrency

threads: N opens N DuckHaven sessions, each holding one agent admission slot for the duration of the run. There is no deadlock, but keep threads ≤ the agent's admission capacity to avoid queueing/starvation. threads: 2–4 is a good default.

Cancelling a run (Ctrl-C, or a failure with --fail-fast) cancels the in-flight statement on each session, so the agent's admission slots are freed promptly instead of running the abandoned queries to completion.

License

Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbt_duckhaven-0.2.0.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbt_duckhaven-0.2.0-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file dbt_duckhaven-0.2.0.tar.gz.

File metadata

  • Download URL: dbt_duckhaven-0.2.0.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for dbt_duckhaven-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3dc5ee6e7b1478267753c727ce55e6ed4552c605f962ff537e705c1569110b47
MD5 a66b50498ae6af94b921228779ac2ce9
BLAKE2b-256 39ffa924e91995efa60cd51e7c8acfb147ccf917bd78e89d0fc89ccf08a14479

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbt_duckhaven-0.2.0.tar.gz:

Publisher: release.yml on tamasmrtn/duckhaven-clients

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dbt_duckhaven-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dbt_duckhaven-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for dbt_duckhaven-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22f922b854d5d8347c97f19101ea5e7f7a2222644a2811699d0dc3d74f5ae875
MD5 6429477ee545500638d2964257145c59
BLAKE2b-256 7db5bcd1b23c7e2170d49718917b64d6f59bcf208c6f6d0659fb9562b5917a6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbt_duckhaven-0.2.0-py3-none-any.whl:

Publisher: release.yml on tamasmrtn/duckhaven-clients

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page