Skip to content

feat(napi): expose metadata methods on Connection - #97

Closed
msrathore-db wants to merge 6 commits into
mainfrom
msrathore/krn-napi-metadata-exposure
Closed

msrathore-db wants to merge 6 commits into
mainfrom
msrathore/krn-napi-metadata-exposure

Conversation

@msrathore-db

@msrathore-db msrathore-db commented May 31, 2026 •

Copy link
Copy Markdown
Collaborator

What

Exposes the JDBC DatabaseMetaData-style metadata methods on the napi Connection, backed by the kernel's flat Metadata API — listCatalogs, listSchemas, listTables, listColumns, listFunctions, listTableTypes, listTypeInfo, plus getPrimaryKeys / getCrossReference (with whitespace-only identifier rejection and tableTypes advisory-filter docs). Each returns a Statement handle that streams JDBC-shaped Arrow batches, so JS consumes metadata results through the same surface as executeStatement.

Scope (rebased + slimmed onto main, 2026-06-01)

This branch was previously a broad bundle (metadata + status accessors + TLS config + pool default + the napi Connection/Statement surface) built ~16 commits behind main. Since then main merged the decomposed stack that already contains all of those:

So this PR was rebased --onto main to drop all the already-merged content. What's left is just the metadata exposure — 4 files: napi/src/metadata.rs (new), the metadata wiring + AnyInner enum in napi/src/statement.rs, src/metadata_v0.rs, and the mod metadata line.

Rebase adaptation

The metadata work wraps the Statement inner in an AnyInner::{Executed, Metadata} enum (the Metadata variant holds a bare ResultStream from Metadata::list_*). One commit adapts main's #23 status accessors (num_modified_rows / display_message / diagnostic_info / error_details_json) to match on that enum — the Executed variant delegates as before; the Metadata variant returns None (metadata streams have no operation-status fields).

Routing

Targets main as the next single-concern item in the kernel decomposed stack. Independent of the param (#84) / async / TLS-napi (#101) PRs.

Testing

Builds clean against main; 26 napi tests pass; clippy/fmt clean.

This pull request and its description were written by Isaac.

Adds Statement::from_result_stream (internal constructor wrapping a
bare ResultStream) and a new napi/src/metadata.rs that wires all 10
kernel Metadata methods onto the JS Connection class:

  listCatalogs, listSchemas, listTables, listColumns,
  listFunctions, listProcedures, listTableTypes, listTypeInfo,
  getPrimaryKeys, getCrossReference

Each returns the same Statement type as executeStatement so the JS
SeaOperationBackend wraps them uniformly. Cancel on metadata-derived
Statements is a no-op (no server-side cancellation surface today).

The kernel Metadata methods hold a tracing::EnteredSpan (!Send) across
their await points. The fix: acquire the session lock, clone the Send
Metadata handle, drop the lock, then run the !Send future inside
tokio::task::spawn_blocking via Handle::block_on — a standard
pattern for escaping the Send bound without LocalSet.

Also fixes:
- pre-existing unused StatementState import in src/client/transport.rs
- pre-existing dead_code lint on open_session + ConnectionOptions in
  napi/src/database.rs (exported via napi macro codegen, not called
  from Rust directly)
- AnyInner::Executed variant boxed to satisfy large_enum_variant lint

Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
…nly identifiers

H1: `run_on_blocking`'s closure type was `FnOnce(Handle) -> Fut`, giving callers
access to the runtime handle inside a `spawn_blocking` thread. Any future caller
using that handle to call `block_on_in_runtime` would trigger `block_in_place`
inside a blocking thread — the PECOBLR-2917 abort vector. Drop the parameter;
callers that needed it for `Handle::block_on` already have a captured `handle`.
All 10 call sites updated from `move |_h|` to `move ||`.

H2: `Identifier::new` and `LikePattern::new` accepted whitespace-only strings
(e.g., `"   "`) that would produce meaningless or empty tokens at the SQL layer.
Add `s.trim().is_empty()` guard after the `s.is_empty()` check in both. Two unit
tests added covering space, tab, newline, and mixed whitespace inputs.

Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
Databricks SHOW TABLES does not accept a table-type filter server-side;
the kernel applies it client-side after the result returns. Mirror the
language already present in src/metadata_v0.rs:310-313 so napi callers
are not misled into expecting server-side enforcement.

Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
… docblocks

The whitespace-only check was added in code but the /// Rejects: bullet
list in each constructor docblock didn't mention it. Add a bullet to both
Identifier::new and LikePattern::new explaining the rejection and the
reason (blank token / use None for "match all").

Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
Leftover from the H1 fixup that removed the `Handle` parameter from
`run_on_blocking`'s signature. With no callers of `Handle` as a type
remaining in metadata.rs, the import is dead and trips
`cargo clippy --all-targets -- -D warnings`.

Doc-comment references to `Handle::block_on` and `Handle::current()`
remain (they describe behavior, not Rust paths).

Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
Rebasing the metadata-methods work onto main surfaced a clean conflict:
main's status accessors (num_modified_rows / display_message /
diagnostic_info / error_details_json, merged via PR #23) read
`inner_state.executed` directly, but the metadata work wraps the
Statement inner in an `AnyInner::{Executed, Metadata}` enum (the
Metadata variant holds a bare ResultStream from `Metadata::list_*`).

Match on the enum: the Executed variant delegates to the executed
handle as before; the Metadata variant returns None — metadata result
streams carry no operation-status fields.

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
@msrathore-db
msrathore-db force-pushed the msrathore/krn-napi-metadata-exposure branch from 6cda5ec to 52b680f Compare June 1, 2026 00:55
@msrathore-db msrathore-db changed the title feat(napi): expose metadata methods on Connection (+ status accessors, TLS config, pool default) feat(napi): expose metadata methods on Connection Jun 1, 2026
@msrathore-db

Copy link
Copy Markdown
Collaborator Author

Closing as superseded by #101, which is now the main-based kernel SEA parity mega PR for agent review. The branch is preserved and this can be reopened if we decide to return to smaller stacked reviews.

This branch had an error being deployed

1 failed deployment
azure-prod — 52b680f8 Deployed Jun 1, 2026 by msrathore-db via v0 E2E surface #7
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