Skip to content

feat(pyo3): metadata + ResultStream surface - #14

Merged
vikrantpuppala merged 1 commit into
feat/pyo3-scaffoldfrom
feat/pyo3-metadata
May 13, 2026
Merged

vikrantpuppala merged 1 commit into
feat/pyo3-scaffoldfrom
feat/pyo3-metadata

Conversation

@vikrantpuppala

Copy link
Copy Markdown
Collaborator

Stacks on #13 (PyO3 scaffold). Review/merge that first.

Summary

  • Phase 1 step 3 of the PySQL × kernel integration plan.
  • Wraps the kernel's Metadata API one-to-one and introduces a standalone ResultStream Python class for the bare streams metadata calls return (no statement_id / no cancel — that surface is reserved for ExecutedStatement).

Surface added

Python Returns
Session.metadata() Metadata
Metadata.list_catalogs() ResultStream
Metadata.list_schemas(*, catalog=None, schema_pattern=None) ResultStream
Metadata.list_tables(*, catalog=None, schema_pattern=None, table_pattern=None, table_types=None) ResultStream
Metadata.list_columns(*, catalog, schema_pattern=None, table_pattern=None, column_pattern=None) ResultStream
Metadata.primary_keys(*, catalog, schema, table) ResultStream
Metadata.foreign_keys(*, parent_*, foreign_catalog, foreign_schema, foreign_table) ResultStream
Metadata.functions / procedures(*, catalog=None, schema_pattern=None, name_pattern=None) ResultStream
Metadata.type_info() / table_types() ResultStream (static, no wire call)
ResultStream.arrow_schema / fetch_next_batch / fetch_all_arrow / close —

The Python surface collapses kernel Identifier / LikePattern back to Option[str]; the kernel still enforces empty / NUL / backtick / length-cap checks, surfacing bad input as KernelError(code='InvalidArgument', ...).

Implementation notes

  • New fetch.rs shared helpers (next_batch, drain, batches_to_pyarrow_table) so ExecutedStatement.fetch_* and ResultStream.fetch_* produce identical Python objects from the same code path.
  • ExecutedStatement::fetch_* refactored to call the helpers; no behavior change.
  • Metadata methods are inline block_ons — the for<'a> FnOnce(&'a Metadata) -> Fut HRTB trick can't express the bound the borrow checker needs, and the inline form is simpler anyway.

Test plan

  • cargo build --workspace
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo +stable fmt --all -- --check
  • cargo test --workspace — kernel suite unchanged
  • Live smoke test against dogfood: extended pyo3/smoke.py exercises every metadata method, the ResultStream surface (drain + close + use-after-close), and input validation. All 30+ checks pass. Notable live numbers: 74 catalogs visible, 142 schemas in main, 47 tables in system.information_schema, 24 type_info rows, 4 table_types. meta.list_schemas(catalog="") correctly raises KernelError(code='InvalidArgument', message='identifier must not be empty').

This pull request and its description were written by Isaac.

Phase 1 step 3 of the PySQL × kernel integration plan. Wraps the
kernel's `Metadata` API and adds a standalone `ResultStream` Python
class for the bare streams the metadata calls return.

New Python surface:

- `Session.metadata() -> Metadata`
- `Metadata.list_catalogs() -> ResultStream`
- `Metadata.list_schemas(*, catalog=None, schema_pattern=None) -> ResultStream`
- `Metadata.list_tables(*, catalog=None, schema_pattern=None,
  table_pattern=None, table_types=None) -> ResultStream`
- `Metadata.list_columns(*, catalog, schema_pattern=None,
  table_pattern=None, column_pattern=None) -> ResultStream`
- `Metadata.primary_keys(*, catalog, schema, table) -> ResultStream`
- `Metadata.foreign_keys(*, parent_catalog=None, parent_schema=None,
  parent_table=None, foreign_catalog, foreign_schema, foreign_table)
  -> ResultStream`
- `Metadata.functions / procedures(*, catalog=None, schema_pattern=None,
  name_pattern=None) -> ResultStream`
- `Metadata.type_info() / table_types() -> ResultStream` (static, no
  wire call)
- `ResultStream` — `arrow_schema()`, `fetch_next_batch()`,
  `fetch_all_arrow()`, `close()`.

The Python surface collapses kernel `Identifier` / `LikePattern` back
to `Option[str]`; the kernel still enforces empty / NUL / backtick /
length-cap checks, surfacing bad input as
`KernelError(code='InvalidArgument', ...)`.

Implementation notes:

- New `fetch.rs` shared helpers (`next_batch`, `drain`,
  `batches_to_pyarrow_table`) so `ExecutedStatement` and the new
  `ResultStream` produce identical Python objects from the same
  code path.
- `ExecutedStatement::fetch_*` refactored to call the helpers; no
  behavior change.
- `Metadata` methods are inline `block_on`s — the `for<'a> FnOnce(&'a
  Metadata) -> Fut` HRTB trick can't express the bound the borrow
  checker needs, and the inline form is simpler anyway.

Smoke test (`pyo3/smoke.py`) extended with the metadata surface and
validation checks; verified end-to-end against dogfood.

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
@vikrantpuppala
vikrantpuppala merged commit 6bc3ecd into feat/pyo3-scaffold May 13, 2026
gopalldb added a commit that referenced this pull request May 22, 2026
…ject comments (#41)

## Summary

Closes three audit findings related to CI and dependency hygiene.

| Audit | Commit | What |
|---|---|---|
| #9 | `2acc8e5` | `dco-check.yml` checkout was `@v6.0.2`; all other
workflows use `@v4`. Aligned to v4. Both SHA-pinned — no security delta.
|
| #10 | `820e69c` | No `.github/dependabot.yml`. Added one covering
`cargo` + `github-actions`. `pip` intentionally omitted per
`go/pinning-python-deps` (externally-published-library rule). |
| #16 (dependency-pinning audit row 3) | `732827b` |
`pyo3/pyproject.toml` comments claimed `uv sync --frozen` + committed
`uv.lock` with SHA256 hashes. Actual CI uses `uv sync --group dev` (no
`--frozen`, no committed lockfile) per the externally-published-library
policy. Rewrote both comment blocks to match reality. Documentation-only
fix. |

## #9 — Checkout pin alignment

`dco-check.yml:37` was the only workflow using
`actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2`.
All other 7 workflows use
`actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4`. Both
are SHA-pinned, so no actual security delta — purely version-drift
hygiene.

## #10 — Dependabot configuration

New `.github/dependabot.yml`:

- **`cargo`** ecosystem: tracks the Rust crate graph weekly, complements
the existing `cargo-deny` gate. Patch + minor grouped to reduce PR
churn; security advisories still surface as individual PRs. Limit: 10
open PRs.
- **`github-actions`** ecosystem: tracks SHA-pinned action versions
weekly. Patch + minor grouped. Limit: 5 open PRs.

**`pip` ecosystem intentionally NOT included.** The kernel is treated as
an externally-published library per
[go/pinning-python-deps](https://docs.google.com/document/d/1thJsoOBW3NzvRV6pWpujcD8mn4KOXgAW8t10iw6Z6LA/edit):

- Major-version upper bounds in `pyo3/pyproject.toml` (e.g.
`pyarrow>=14,<19`).
- `uv sync` re-resolves on each CI run within those bounds.
- No committed lockfile (would impede downstream `pip install`).

Letting Dependabot rewrite pinned pip versions would conflict with that
policy.

## #16 — pyproject.toml comment accuracy

The `[project].dependencies` block comment said:

> The CI environment is fully hash-locked via `uv.lock` (see below),
separately from this contract.

And the `[dependency-groups].dev` block said:

> `uv sync --frozen` installs from `uv.lock`, which carries SHA256
hashes for every artifact + transitive dep.

Neither was true. The repo has **no `uv.lock`** committed; the workflow
runs **`uv sync --group dev`** (no `--frozen`). The workflow's own
inline comment correctly describes the policy ("No `--frozen` and no
committed lockfile: per go/pinning-python-deps the
externally-published-library rule says *not* to pin transitive deps") —
only the pyproject comments were stale.

This documentation drift was actively misleading dependency-pinning
audits, contributing to false "unpinned pyarrow" findings. Both comment
blocks now match the actual in-repo policy.

No behavioural change.

## Audit items NOT addressed here

- **#11** (audit-log alerts on `.github/workflows/**` changes) —
org-level streaming, not a repo-admin action.
- **#12** (`id-token: write` in 3 workflows) — audit confirms current
scoping is correct.
- **#13** (`persist-credentials: false` in rust-e2e) — audit confirms
positive control, preserved.
- **#14** (`azure-prod.can_admins_bypass: true`) — handled via repo
settings PUT, already flipped to `false`.

## Test plan

- [ ] Reviewer checks GitHub recognises the dependabot config (Insights
→ Dependency graph → Dependabot tab shows cargo + github-actions
ecosystems active).
- [ ] DCO check on this PR runs successfully with the new v4 checkout
(the workflow runs on PR open, once Actions are enabled).
- [ ] Reviewer skims the pyproject comment changes to confirm they match
the workflow's actual behaviour (`uv sync --group dev`, no `--frozen`).

This pull request and its description were written by Isaac.

---------

Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
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