Repository navigation
feat!: load through a connection the caller owns, and move the request-describing Python API into sqlload-api - #366
Merged
Merged
Conversation
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.
Deploying sqlload with
|
| Latest commit: |
3867507
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://49739cf1.sqlload.pages.dev |
| Branch Preview URL: | https://feat-session-destination.sqlload.pages.dev |
…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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A program embedding the
sqlloadcrate (SQLBuild is the first) needs two things from SQLLoad:sl.http,sl.json,sl.field,sl.checkpoint, ...), so its loaders can build HTTP jobs. Until now, importing any of it loadedsqlload._native, a second engine in that process, andsl.httpneeded a SQLLoad source.Changes: loading through a caller's connection
SessionConnectionby name throughparse_python_project. It's a warehouse dialect plus anArc<dyn CallerConnection>, and no project file can write one. Targets use it as any connection of that kind, andDestination::Sessiongets an arm in every dispatch function.read_parquet.PUTto@~/sqlload/<load>/<batch>/, thenCOPY INTO, thenREMOVE.COPY FROM STDIN.BEGIN,COMMITandROLLBACKitself, and rolls back after a failed statement, a failedCOMMITincluded. A Snowflake session with autocommit off is refused, and Snowflake sessions run in UTC, as SQLLoad's own do.Changes: the
sqlload-apipackagepackages/sqlload-api(importsqlload_api) is pure Python with no dependencies. It holds what a loader yields, moved withgit mvunchanged apart from the points below:sl.httpand its paginators and cell helpers,sl.json,sl.ndjson,sl.field,sl.parent,sl.key,sl.checkpoint,@sl.transformandliteral_paths.sqlloaddepends onsqlload-apiat exactly its own version and re-exports the same objects (sl.http is sqlload_api.http), soimport sqlload as slis unchanged.sl.source,sl.table,sl.rename, the runtime and the CLI stay insqlload.JsonDatawithout native code. It crosses through__sqlload_json__(), which returns its bytes and read spec as JSON, as jobs and checkpoints already cross. Thesqlloadcrate 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 pathsl.json(fields=...)can't use now fails when the item is yielded, with the same message, rather than at thesl.json(...)call.httpwithout a source.sqlload_api.http(connection="shop_api")builds the same job, byte for byte, assl.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, andcontext_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.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 realsl.source) and compare, and an engine test reads every committed item without a problem. Other tools can run the same cases against their ownctx.http.sqlload-apiis in Release Please'sextra-files, and the release-metadata check also matches its version andsqlload's pin.publish.ymlbuilds the pure wheel and sdist, checks that the wheel imports without the engine, and uploads them in thepypienvironment, where the pending publisher is set.published-smoke.ymlwaits forsqlload-apion PyPI.PUTpath as a SQL literal writes it on Windows (backslashes doubled).BREAKING CHANGE: for library callers only.
parse_python_projecttakes(python, sessions);ConnectionConfig,Destination,WriterandLoaderErrorgain variants. The TOML and CLI are unchanged. Thesqlload-apimove doesn't breaksl.*users: only private modules (sqlload._http,sqlload._data, ...) andsqlload._native.JsonDatamove or go.Verification
cargo fmt --check, the three clippy configurations, and fensu with 0 faults.sqlload-apitests pass: 40, including the import check with no engine loaded.sqlloadPython test files pass: 622 (crossing, everytest_http_*, transforms, rename, logged state, declare, Python sources, batched, and the newtest_api_wire).publish.ymlruns on this PR, aspyproject.tomlchanged).