Skip to content

feat!: load through a connection the caller owns, and move the request-describing Python API into sqlload-api - #366

Merged
kvlonge merged 7 commits into
mainfrom
feat/session-destination
Nov 26, 2026
Merged

kvlonge merged 7 commits into
mainfrom
feat/session-destination

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Why

A program embedding the sqlload crate (SQLBuild is the first) needs two things from SQLLoad:

  • Its own warehouse connection. It already holds an authenticated connection to the warehouse it builds into, and should load through that: same credentials and auth methods, and no second set of warehouse keys. SQLLoad still plans every load and renders every statement.
  • The Python that describes requests and data (sl.http, sl.json, sl.field, sl.checkpoint, ...), so its loaders can build HTTP jobs. Until now, importing any of it loaded sqlload._native, a second engine in that process, and sl.http needed a SQLLoad source.

Changes: loading through a caller's connection

  • Caller sessions. A library caller attaches a SessionConnection by name through parse_python_project. It's a warehouse dialect plus an Arc<dyn CallerConnection>, and no project file can write one. Targets use it as any connection of that kind, and Destination::Session gets an arm in every dispatch function.
  • Rows into staging, by warehouse:
    • DuckDB and MotherDuck: local Parquet read with read_parquet.
    • Snowflake: PUT to @~/sqlload/<load>/<batch>/, then COPY INTO, then REMOVE.
    • Postgres: binary COPY FROM STDIN.
    • BigQuery, ClickHouse and Databricks: a Parquet file the session loads itself.
  • Transactions. Sessions run in autocommit. SQLLoad sends BEGIN, COMMIT and ROLLBACK itself, and rolls back after a failed statement, a failed COMMIT included. A Snowflake session with autocommit off is refused, and Snowflake sessions run in UTC, as SQLLoad's own do.
  • Shared queries. Describe queries move into each dialect, so native and session destinations read live columns with the same SQL. Postgres write checks (merge key index, cascading foreign keys) run on sessions too, sharing their logic.
  • Not covered: warehouse-side file reads, Snowpipe Streaming and DuckDB memory budgets.
  • Docs: a guide, "Loading through your own connection".

Changes: the sqlload-api package

  • New package. packages/sqlload-api (import sqlload_api) is pure Python with no dependencies. It holds what a loader yields, moved with git mv unchanged apart from the points below: sl.http and its paginators and cell helpers, sl.json, sl.ndjson, sl.field, sl.parent, sl.key, sl.checkpoint, @sl.transform and literal_paths. sqlload depends on sqlload-api at exactly its own version and re-exports the same objects (sl.http is sqlload_api.http), so import sqlload as sl is unchanged. sl.source, sl.table, sl.rename, the runtime and the CLI stay in sqlload.
  • JsonData without native code. It crosses through __sqlload_json__(), which returns its bytes and read spec as JSON, as jobs and checkpoints already cross. The sqlload crate reads the spec (row_batches::main::json_read_spec), with the validation the removed pyo3 class did, and names the three crossing methods (python_sources::constants), so any engine shares one parser. A path sl.json(fields=...) can't use now fails when the item is yielded, with the same message, rather than at the sl.json(...) call.
  • http without a source. sqlload_api.http(connection="shop_api") builds the same job, byte for byte, as sl.http(source) does from a source with that connection. sl.http(source) and its errors are unchanged.
  • literal_paths. It accepts names from either package, and context_clients={"http"} reads jobs built on a context's client (ctx.http()). That is off by default, so SQLLoad's plan-time checks are unchanged.
  • Pinned wire. sqlload_api._wire (shipped in the wheel) commits one item of each kind and what it crosses as. Each package's tests build every item (by connection name, from a source-like object, and from a real sl.source) and compare, and an engine test reads every committed item without a problem. Other tools can run the same cases against their own ctx.http.
  • Packaging.
    • Released in lockstep: sqlload-api is in Release Please's extra-files, and the release-metadata check also matches its version and sqlload's pin.
    • publish.yml builds the pure wheel and sdist, checks that the wheel imports without the engine, and uploads them in the pypi environment, where the pending publisher is set.
    • The wheel smoke tests install the pin from the build, the unixODBC asserts skip the pure package, and published-smoke.yml waits for sqlload-api on PyPI.
  • Also: the session-route test now matches Snowflake's PUT path as a SQL literal writes it on Windows (backslashes doubled).

BREAKING CHANGE: for library callers only. parse_python_project takes (python, sessions); ConnectionConfig, Destination, Writer and LoaderError gain variants. The TOML and CLI are unchanged. The sqlload-api move doesn't break sl.* users: only private modules (sqlload._http, sqlload._data, ...) and sqlload._native.JsonData move or go.

Verification

  • The gate passes on Rust 1.95.0: cargo fmt --check, the three clippy configurations, and fensu with 0 faults.
  • The session unit tests and the new engine wire test pass.
  • The sqlload-api tests pass: 40, including the import check with no engine loaded.
  • The touched sqlload Python test files pass: 622 (crossing, every test_http_*, transforms, rename, logged state, declare, Python sources, batched, and the new test_api_wire).
  • CI covers the full suites, the container tests, Windows, and the wheel builds and smoke tests (publish.yml runs on this PR, as pyproject.toml changed).

A library caller can attach its own warehouse connection to a project
(ConnectionConfig::Session, which no project file can write) and targets
load into it as into any connection of its kind. SQLLoad still plans the
load and renders every statement in the warehouse's dialect; the caller
runs them and takes rows as Parquet files (DuckDB, MotherDuck), files PUT
on the user stage (Snowflake), binary COPY data (Postgres) or Parquet
files it loads itself (BigQuery, ClickHouse, Databricks).

Describe queries move into each dialect, so a warehouse's own destination
and a caller's session read live columns with the same SQL.

parse_python_project takes the caller's connections beside the Python
sources.
…nd Postgres checks writes through them

A Snowflake session runs in UTC as SQLLoad's own do, and one with
autocommit off is refused when it opens. A failed COMMIT is rolled back.
The checks before a Postgres write (a merge's unique index, foreign keys a
replace or delete_insert would cascade into) run on a caller's session too,
sharing their logic with SQLLoad's own Postgres session.
…er; Postgres write checks share their queries' text forms
… on Windows

The session-route test replaced the writer's folder with <folder> in each
call, but Snowflake's PUT literal doubles a Windows path's backslashes, so
on Windows the folder and the separator before the file name went
unreplaced. The test now matches the escaped folder too.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Deploying sqlload with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3867507
Status: ✅  Deploy successful!
Preview URL: https://49739cf1.sqlload.pages.dev
Branch Preview URL: https://feat-session-destination.sqlload.pages.dev

View logs

…lload-api package

sl.http and its paginators and cell helpers, sl.json, sl.ndjson, sl.field,
sl.parent, sl.key, sl.checkpoint and @sl.transform now live in
sqlload-api (import sqlload_api), a new pure-Python package with no
compiled code. sqlload depends on it at exactly its own version and
re-exports the same objects, so `import sqlload as sl; sl.http` is
unchanged. Another tool running the engine in its own process can build
the same items without loading a second engine.

- JsonData is pure Python and crosses through __sqlload_json__(), its
  bytes and read spec as JSON, as jobs and checkpoints already cross. The
  sqlload crate reads the spec (row_batches::main::json_read_spec), with
  the validation the removed pyo3 class did, and names the three crossing
  methods (python_sources::constants), so every engine shares one parser.
  A field path sl.json's fields= can't use now fails when the item is
  yielded, with the same message, rather than at the sl.json call.
- sl.http takes any source with a name and settings, or just
  connection=: sqlload_api.http(connection="shop_api") builds the same
  job, byte for byte, as sl.http(source) does from a source with that
  connection. sl.http(source) and its errors are unchanged.
- literal_paths moves intact, accepts names from either package, and
  takes context_clients={"http"} to read jobs built on a context's client
  (ctx.http()); off by default.
- sqlload_api._wire commits one item of each kind and what it crosses as.
  Both packages' tests build each item and compare, and an engine test
  reads every one, so the wire is pinned on both sides.
- Packaging: released in lockstep (release-please extra-files); publish
  builds the pure wheel and sdist, the wheel smoke tests install the pin
  from the build, and published-smoke waits for sqlload-api on PyPI.
@kvlonge kvlonge changed the title feat(adapters)!: load through a warehouse connection the caller owns feat!: load through a connection the caller owns, and move the request-describing Python API into sqlload-api Nov 26, 2026
load prints each table's line as the table finishes, so tables loading at
once print in completion order: the quickstart's Postgres section showed
raw.app__customers before raw.app__orders and failed when a run finished
them the other way round. Page tests now compare each run of adjacent
loaded, failed and skipped lines as a set of lines; which tables, and what
each line says, still have to match, and every other line keeps its
place.
… publish it first

make bench-wheel installed the sqlload wheel it built with --no-deps, so
the benchmark environment lacked the sqlload-api it pins (it reaches PyPI
only with the release); it now installs packages/sqlload-api from this
tree too. The release uploads sqlload-api in a step of its own before
sqlload, so pip install sqlload==<version> resolves as soon as sqlload is
listed.
@kvlonge
kvlonge merged commit 1ccba3e into main Nov 26, 2026
32 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