Repository navigation
feat!: publish the Python host as the sqlload-python-host crate - #368
Merged
Merged
Conversation
Another pyo3 extension can now run its Python tables on SQLLoad's engine without copying the crossing: - The crossing and the host move from the sqlload extension into sqlload-python-host. module_host(runtime) is the engine's PythonHost over a Python runtime module the host provides. table_stream, transform_stream, read_error and error_text are building blocks for a host that implements PythonHost itself. The crate re-exports pyo3 (0.29, abi3-py310) and fails the first read when the interpreter's sqlload-api is not its own version. - Context and Connection move to sqlload_api, with Context.from_read for a host (or a subclass with fields of its own). Transforms and the crossing's callbacks move to sqlload_api._host, so a process has one transform registry. sl.Context is the same object as before. - PythonSource takes an opaque host value that the engine copies unread into each of the source's TableReads. - Publish releases sqlload, then sqlload-python-host, with the same crates.io token, and the release-metadata check covers both exact workspace pins. - An unpublished example host (crates/sqlload-python-host-example, tests/external_host) loads into DuckDB through module_host from make test-python. BREAKING CHANGE: PythonSource, TableRead and ProjectConfig are #[non_exhaustive]; build PythonSource and TableRead with their new constructors.
Deploying sqlload with
|
| Latest commit: |
bdbbd9e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c789d187.sqlload.pages.dev |
| Branch Preview URL: | https://feat-python-host.sqlload.pages.dev |
…ave exited The last handle of a bridge closed its stdin and left the exit to a detached thread, so sqlload could return while the bridge still held the database it opened, and the next command (or a reader) hit DuckDB's file lock. Dropping the last handle now waits for the bridge to exit, ending it after 10 s. The memory watchdog's interrupt thread holds a weak handle, so that wait happens on the command's own path, not on that thread. make test-python roots pytest at the repository, so test IDs name their real paths instead of sqlload-api's folder.
The rules for how a table's options combine (merge needs a unique_key, replace takes no cursor, append takes no lookback, a setting for another strategy, and the rest the loader enforced from settings alone) ran only when a table was planned. A tool that validates a project offline, such as one calling parse_python_project, never saw them. They now live in one place, the table_options module. The loader's build_spec calls it as it plans a table, and parse_project and parse_python_project call it for every table entry, Python tables included, before anything connects. A source that lists no tables is checked with its own settings, which every table it finds takes. Parse reports each problem at the table's entry with plan's wording. Rules that need the discovered table (its columns, its primary key and its nullability, constants, a missing write_strategy) stay at plan. The integration test cases that expected plan to refuse settings-only combinations moved to a parse test covering every rule, for TOML and Python sources.
…se test These combinations are refused when the project is parsed, which stops the whole command, so the container tests that expected plan to refuse one table no longer reach plan. Each case is a parse test case now (a masked newest_by column, a cursor on a delete_insert by replace_key, null_cursor = "include" on append and delete_insert, and on_overlapping_files on a merge, an append and a delete_insert by cursor), with the full message the container tests checked. The postgres_cdc files case that checks a source which cannot list its tables is refused while another source loads no longer declares a postgres_cdc source merging into a files target, which the project parse refuses; the parse test covers that.
…smoke tests The wheel smoke tests installed the sqlload wheel with --find-links dist. Before Release Please bumps the version, the branch's sqlload-api has the version of the release already on PyPI, so pip took PyPI's copy, which lacks this branch's modules. Each install now names dist's sqlload_api wheel too: the smoke test on every OS, its Linux ODBC container, and the MySQL Connector/ODBC smoke script. The Makefile already installs the local package, and published-smoke.yml keeps installing from PyPI.
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.
What this changes
Another pyo3 extension can now run its Python tables on SQLLoad's engine without copying the crossing.
sqlload-python-hostholds the crossing and the host, moved out of thesqlloadextension.module_host(runtime)is the engine'sPythonHostover a Python runtime module the host provides. That module definesdiscover,start_table,current_state,table_state,renameandfinish_run.table_stream,transform_stream,read_erroranderror_textare building blocks for a host that implementsPythonHostitself.pyo3(0.29,abi3-py310). The first read fails when the interpreter'ssqlload-apiisn't the crate's version, and the error names the version to install.sqlload_api.ContextandConnectionmove fromsqlload, together withContext.from_read(read, **extras)for hosts and their subclasses. Transforms and the crossing's callbacks move tosqlload_api._host, so a process has one transform registry.sl.Contextis the same object as before.PythonSource.hostis an opaque value the engine copies unread into each of the source'sTableReads.PythonSource,TableReadandProjectConfigare#[non_exhaustive].PythonSource::newandTableRead::newbuild them.publish.ymlpublishessqlload, thensqlload-python-host, with the same OIDC token.verify.ymlpackages both crates withcargo package.sqlload-python-host0.0.0 is already on crates.io, reserving the name. Its trusted publisher (sqlstack-io/sqlload,publish.yml, environmentcrates) needs to be in place before the release runs.crates/sqlload-python-host-example, with its Python side intests/external_host) loads into DuckDB throughmodule_host, frommake test-python. It covers:ExampleContext(sqlload_api.Context)with a field read fromhost;sqlload_api.httpjob with a page transform;Checks run
cargo fmt --all --check, the threemake check-ciclippy runs andfensu check(0 faults), all on Rust 1.95.0.cargo package --no-verify --locked -p sqlload -p sqlload-python-host, andmaturin sdistforsqlload.sqlload-api(including the newtest_host.py);sqlloaddeclare, crossing, cursor, logged-state, Python-sources, transforms, rename, batched, API-wire and HTTP tests (642 passed).Also in this PR
sqlloadcould return while the bridge still held DuckDB's file lock. That race was already onmain, and it caused the flakytest_motherduck.pyfailure.make test-pythonpasses--rootdirto pytest, so test IDs show their real paths instead ofpackages/sqlload-api/….table_optionsmodule. The loader'sbuild_specandparse_project/parse_python_projectboth call it. So these mistakes are reported before anything connects, for TOML and Python tables, with plan's wording at the table's entry. Rules that need the discovered table stay at plan. A new parse test covers every rule. The integration cases that expected plan to refuse these combinations moved there.