Skip to content

feat(motherduck): connect through a separate DuckDB 1.5 process (install sqlload[motherduck]), as MotherDuck doesn't accept DuckDB 2.0 clients yet - #182

Merged
kvlonge merged 1 commit into
mainfrom
chi-1237-motherduck-bridge
Nov 12, 2026
Merged

kvlonge merged 1 commit into
mainfrom
chi-1237-motherduck-bridge

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

MotherDuck accepts DuckDB clients 1.4.1 to 1.5.6, and SQLLoad bundles DuckDB 2.0, so a motherduck target couldn't connect. It now runs its SQL on Python's duckdb package in a separate process; every other target stays on the bundled DuckDB 2.0, and the two versions never share a process.

How it works

  • crates/sqlload/src/adapters/motherduck_bridge/: a small Python program (bridge.py, run with python -c) and the Rust side that talks to it over newline-delimited JSON on stdin/stdout. One DuckDB cursor per table connection, run in order on its own thread. Batches go over as temporary Parquet files inserted with read_parquet(?) inside the batch's transaction.
  • The DuckDB adapter's connection is now DuckDbConnection::{Local, Bridge}; each entry in adapters/duckdb/main has a Bridge branch. Local DuckDB is unchanged.
  • The token goes over the pipe, never in the command line, and is redacted from errors and from the process's stderr.
  • sqlload[motherduck] adds duckdb>=1.4.1,<=1.5.6; the sqlload command runs the process on its own Python. SQLLOAD_MOTHERDUCK_PYTHON names another (needed with sqlload-cli).
  • Removal once MotherDuck accepts DuckDB 2.0 is listed step by step on the MotherDuck docs page.

Tests

  • Offline (packages/sqlload/tests/test_motherduck.py, in make test-python): a stand-in for MotherDuck keeps each md: database in a local file. Covers every write strategy and portable type compared with the same load into DuckDB, an incremental rerun with a new column, the process ending mid-load (nothing committed, the next load recovers, the token is redacted), a value MotherDuck rejects, and setup errors (no Python, no duckdb package, refused version, refused token).
  • Live (packages/sqlload/tests/test_motherduck_live.py, skipped unless SQLLOAD_TEST_MOTHERDUCK_TOKEN is set): run against a real MotherDuck account on duckdb 1.5.6. It creates a prefixed database, runs debug, loads all four strategies and every portable type, does an incremental load with a new column, reruns, and drops the database. Passed twice; the account is left with only its original databases.

…all sqlload[motherduck]), as MotherDuck doesn't accept DuckDB 2.0 clients yet

A motherduck target now runs its SQL on Python's duckdb package (1.4.1 to 1.5.6, which MotherDuck
accepts) in a process of its own, so the two DuckDB versions never share a process and every other
target stays on the bundled DuckDB 2.0. SQLLoad sends it newline-delimited JSON requests over a pipe,
one cursor per table connection, and hands it each batch as a temporary Parquet file it inserts with
read_parquet inside the batch's transaction. The token goes over the pipe, never in the command
line, and is redacted from everything the process prints.

The sqlload package gains a motherduck extra (duckdb>=1.4.1,<=1.5.6) and runs the process on its
own Python; sqlload-cli and other setups name one with SQLLOAD_MOTHERDUCK_PYTHON. Everything
specific to it sits behind the DuckDB adapter's Bridge connection and adapters/motherduck_bridge;
the MotherDuck page lists the steps to remove it once MotherDuck accepts DuckDB 2.0.

Tested offline through a stand-in for MotherDuck (every write strategy and portable type compared
with DuckDB, an incremental rerun, the process ending mid-load, a rejected value, setup errors) and
live against a MotherDuck account (test_motherduck_live.py, run with SQLLOAD_TEST_MOTHERDUCK_TOKEN).
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sqlload with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1fdbba0
Status: ✅  Deploy successful!
Preview URL: https://cb366125.sqlload.pages.dev
Branch Preview URL: https://chi-1237-motherduck-bridge.sqlload.pages.dev

View logs

@kvlonge
kvlonge merged commit 2a11162 into main Nov 12, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant