Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7d120d0
feat(metadata): add pollable catalog operations to the C ABI
aakash-saravanan-db Nov 30, 2026
f1471f0
feat(metadata): expose pollable current catalog lookup
aakash-saravanan-db Nov 30, 2026
1759791
fix(metadata): clean up known statements when operations are dropped
aakash-saravanan-db Nov 30, 2026
45505fe
test(metadata): isolate foreign-key mock cleanup
aakash-saravanan-db Nov 30, 2026
1c90a64
fix(metadata): preserve foreground statement close on errors
aakash-saravanan-db Nov 30, 2026
95708c3
fix(metadata): close abandoned namespace lookup statements
aakash-saravanan-db Dec 1, 2026
beb85e2
docs(metadata): clarify in-flight statement ID ownership
aakash-saravanan-db Dec 1, 2026
bab5e90
fix(metadata): preserve terminal errors in the C ABI stream getter
aakash-saravanan-db Dec 1, 2026
ecd1809
test(c-abi): verify metadata submit exports clear their output
aakash-saravanan-db Dec 1, 2026
0ce08d4
docs(c-abi): clarify metadata handle teardown before session close
aakash-saravanan-db Dec 1, 2026
56cfaf5
test(c-abi): verify foreign key submit argument routing
aakash-saravanan-db Dec 1, 2026
8119723
test(sea): keep bounded poll fixtures valid on status reads
aakash-saravanan-db Dec 1, 2026
313709d
docs(metadata): clarify deferred operation cleanup
aakash-saravanan-db Dec 1, 2026
b0ea0a0
test(metadata): consolidate operation lifecycle coverage
aakash-saravanan-db Dec 2, 2026
8e7e356
test(metadata): reuse schema operation server fixture
aakash-saravanan-db Dec 2, 2026
c3d6f8b
feat(c-api): add owned asynchronous session operations
aakash-saravanan-db Dec 3, 2026
c548858
test(c-api): use the terminal status SQLSTATE field
aakash-saravanan-db Dec 3, 2026
e81a46c
refactor(c-api): keep session operation state compact
aakash-saravanan-db Dec 3, 2026
af066b6
fix(c-api): preserve setup error precedence and strengthen operation …
aakash-saravanan-db Dec 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ cadences and may not move in lockstep with the crate.
## [Unreleased]

### Added
- Pollable C ABI session open, close, transaction and catalog operations own
their inputs and run on the existing runtime.
- Native parameter-set snapshots on `StatementSpec` and the C ABI submit an
atomic batch and report aggregate affected-row counts.

Expand Down
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ changes go in their respective binding's NEXT_CHANGELOG.
`kernel_session_config_set_port` connect to `host:port`, so bindings no longer
build it into the host. A non-default port is rejected with `InvalidArgument`
if the host has credentials, a path, query or fragment.
- The C ABI exposes pollable catalog metadata operations with cancellation and owned result streams.

### Changed

Expand Down
150 changes: 136 additions & 14 deletions include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@
* If close fails, the kernel still schedules best-effort cleanup when the
* consumed session handle is dropped, but the status code reports the
* awaited close failure to the caller.
* - **Close the session LAST.** Because close initiates the server-side
* delete, any handle still open against that session — a statement /
* executed handle, or a metadata result stream (which holds its own
* session reference and remains drivable) — must be drained and closed
* BEFORE `kernel_session_close`. Driving such a handle afterwards issues
* RPCs against a session whose delete has already been initiated and
* will surface server errors. Order teardown: result streams → executed
* handles → statements → session. (Statement cancellers are not in this
* chain — freeing one drives no RPC; see the next bullet.)
* - **Close the session LAST.** `kernel_session_close` initiates server-side
* deletion even if handles retain client-side session state. For statements,
* drain and close result streams, then close executed handles, then
* statements. Close metadata operations and metadata result streams,
* whether returned directly or transferred from an operation, before
* closing the session. RPCs issued after session close will surface
* server errors. (Freeing a statement canceller drives no RPC. See the
* next bullet.)
* - **Free statement cancellers too.** A `kernel_statement_canceller_t`
* holds its own session reference, so a leaked canceller pins the
* client-side session (and its connection pool) past
Expand Down Expand Up @@ -207,6 +206,7 @@ typedef struct kernel_executed_async_statement_t kernel_executed_async_statement
typedef struct kernel_executed_async_statement_canceller_t
kernel_executed_async_statement_canceller_t;
typedef struct kernel_result_stream_t kernel_result_stream_t;
typedef struct kernel_metadata_operation_t kernel_metadata_operation_t;
/* Detached canceller for a sync-executing statement, returned by
* kernel_statement_canceller_new. The returned handle is safe to use from
* another thread concurrently with the blocking kernel_statement_execute on the
Expand Down Expand Up @@ -667,6 +667,66 @@ KernelStatusCode kernel_session_config_set_client_conf(KernelSessionConfig* conf
KernelStatusCode kernel_session_open(KernelSessionConfig* config, kernel_session_t** out);
KernelStatusCode kernel_session_close(kernel_session_t* session);

/* An operation owns its task inputs. Submit and poll never wait for network
* completion. Keep one operation per session at a time and do not run other
* work against that session until the operation has completed. */
typedef struct kernel_session_operation_t kernel_session_operation_t;

typedef enum {
KernelSessionControl_Commit = 0,
KernelSessionControl_Rollback = 1,
KernelSessionControl_AutocommitOn = 2,
KernelSessionControl_AutocommitOff = 3,
KernelSessionControl_UseCatalog = 4
} KernelSessionControlAction;

typedef struct {
const char* catalog; /* nullable, UTF-8 */
const char* schema; /* nullable, UTF-8 */
bool apply_autocommit;
bool autocommit;
} KernelSessionOpenSetup;

/* Consumes config on ALL paths, including invalid setup/out. Copies setup and
* its strings before returning. Runs open, optional quoted USE CATALOG,
* USE SCHEMA, and autocommit in that order. Object-not-found during USE is
* best effort; other setup errors close the session best effort and preserve
* the original error. A successful open is retrieved with take_session. */
KernelStatusCode kernel_session_open_submit(KernelSessionConfig* config,
const KernelSessionOpenSetup* setup,
kernel_session_operation_t** out);

/* Consumes session on ALL paths. Close child handles first, as for synchronous
* close. Successful close suppresses drop cleanup; failure retains the existing
* best-effort fallback and may initiate another delete. */
KernelStatusCode kernel_session_close_submit(kernel_session_t* session,
kernel_session_operation_t** out);

/* Does not consume session. Holds an owned reference for the task. UseCatalog
* requires a non-null UTF-8 catalog_value and backtick-quotes it as one
* identifier. All other actions require NULL. Invalid actions are rejected.
* Transaction controls preserve IgnoreTransactions no-op behavior. */
KernelStatusCode kernel_session_control_submit(kernel_session_t* session,
KernelSessionControlAction action,
const char* catalog_value,
kernel_session_operation_t** out);

/* Local check only. Writes false while pending, true on either terminal
* outcome. Terminal status repeats, including after take_session. Each failure
* copies the original error to the polling thread's last-error buffer. */
KernelStatusCode kernel_session_operation_poll(kernel_session_operation_t* op, bool* done);

/* Successful open only; transfers the session once. Other operations, pending
* opens and repeated takes fail. The session outlives operation_close. */
KernelStatusCode kernel_session_operation_take_session(kernel_session_operation_t* op,
kernel_session_t** out);

/* Exclusive local drop. Never waits for network completion or aborts work.
* A detached task continues. An untaken opened session uses existing
* best-effort cleanup. There is no cancellation or rollback guarantee.
* Poll may be concurrent with poll; take/close require exclusive access. */
KernelStatusCode kernel_session_operation_close(kernel_session_operation_t* op);

/* Report whether a session is still OPEN (its delete has not been
* initiated). Writes true/false to `*out`. LOCAL check only — no server
* round-trip, so it does NOT detect a server idle-timeout or dropped
Expand Down Expand Up @@ -1076,8 +1136,8 @@ KernelStatusCode kernel_result_stream_canceller_free(
*
* NULL string args mean "unfiltered" for the list_* calls (catalogs /
* schemas / tables / columns). The key/constraint calls differ:
* `kernel_metadata_primary_keys` requires a non-NULL catalog, schema, AND
* table (Databricks SHOW KEYS must target a fully-qualified table), while
* `kernel_metadata_primary_keys` requires a non-NULL table and resolves
* missing catalog or schema from the session, while
* `kernel_metadata_foreign_keys` keys off the foreign (referencing) table
* — a NULL foreign_table returns an empty result (0 rows, no wire call),
* not an error. Passing NULL for a required identifier returns
Expand All @@ -1097,9 +1157,8 @@ KernelStatusCode kernel_metadata_list_columns(kernel_session_t* session, const c
const char* schema_pattern, const char* table_pattern,
const char* column_pattern,
kernel_result_stream_t** out);
/* `catalog`, `schema`, and `table` are all REQUIRED (non-NULL): the
* underlying SHOW KEYS targets a fully-qualified table. NULL for any of
* them returns `KernelStatusCode_InvalidArgument`. */
/* `table` is required. A NULL `catalog` or `schema` uses the corresponding
* current session value. */
KernelStatusCode kernel_metadata_primary_keys(kernel_session_t* session, const char* catalog,
const char* schema, const char* table,
kernel_result_stream_t** out);
Expand Down Expand Up @@ -1149,6 +1208,69 @@ KernelStatusCode kernel_metadata_procedure_columns(kernel_session_t* session, co
const char* column_pattern,
kernel_result_stream_t** out);

/* Submit pollable versions of the metadata calls above. Inputs are copied
* during submit, and the operation owns the client-side session state it needs.
* The session handle must be valid throughout submit. Before
* `kernel_session_close`, close every successfully submitted operation
* (including after failure or cancellation) and any transferred stream.
* Cancel and close do not wait for the task to stop or for background statement
* cleanup. Cleanup is best effort and may race a subsequent session close.
* Argument validation failures may be reported through the operation's status. */
/* Succeeded means the current catalog value has been read and the lookup
* statement's close attempt has finished. The result is an in-memory single
* TABLE_CAT row using the catalog-list schema. An empty string is valid.
* Missing, NULL, or non-string values report DataLoss. Taking or reading the
* result issues no network requests. The usual operation lifecycle applies. */
KernelStatusCode kernel_metadata_submit_current_catalog(kernel_session_t* session,
kernel_metadata_operation_t** out);
KernelStatusCode kernel_metadata_submit_list_catalogs(kernel_session_t* session,
kernel_metadata_operation_t** out);
KernelStatusCode kernel_metadata_submit_list_schemas(kernel_session_t* session, const char* catalog,
const char* schema_pattern,
kernel_metadata_operation_t** out);
KernelStatusCode kernel_metadata_submit_list_tables(kernel_session_t* session, const char* catalog,
const char* schema_pattern, const char* table_pattern,
const char* table_types_csv,
kernel_metadata_operation_t** out);
KernelStatusCode kernel_metadata_submit_list_columns(kernel_session_t* session, const char* catalog,
const char* schema_pattern, const char* table_pattern,
const char* column_pattern,
kernel_metadata_operation_t** out);
KernelStatusCode kernel_metadata_submit_primary_keys(kernel_session_t* session, const char* catalog,
const char* schema, const char* table,
kernel_metadata_operation_t** out);
KernelStatusCode kernel_metadata_submit_foreign_keys(kernel_session_t* session, const char* parent_catalog,
const char* parent_schema, const char* parent_table,
const char* foreign_catalog, const char* foreign_schema,
const char* foreign_table,
kernel_metadata_operation_t** out);
KernelStatusCode kernel_metadata_submit_procedures(kernel_session_t* session, const char* catalog,
const char* schema_pattern, const char* procedure_pattern,
kernel_metadata_operation_t** out);
KernelStatusCode kernel_metadata_submit_procedure_columns(kernel_session_t* session, const char* catalog,
const char* schema_pattern, const char* procedure_pattern,
const char* column_pattern,
kernel_metadata_operation_t** out);

/* Poll without waiting. Pending and Succeeded return Success. Failed and
* Cancelled return the corresponding error code and set the caller's last
* error. Cancelled uses SQLSTATE HY008. */
KernelStatusCode kernel_metadata_operation_status(kernel_metadata_operation_t* op,
KernelStatementStatusKind* out);
/* Poll status for readiness. Succeeded transfers the lazy result stream once;
* the caller owns it and may use it after closing the operation. Pending or an
* already-taken stream returns InvalidArgument. Failed and Cancelled return
* the same code and last error as status (HY008 for Cancelled). A writable
* out is set to NULL before checking the operation and stays NULL on error. */
KernelStatusCode kernel_metadata_operation_get_result_stream(kernel_metadata_operation_t* op,
kernel_result_stream_t** out);
/* Cancel a pending operation. Safe to call concurrently with status polling.
* Repeated calls or calls after completion have no effect. */
KernelStatusCode kernel_metadata_operation_cancel(kernel_metadata_operation_t* op);
/* Consume the handle and abort any pending task. The caller must ensure no
* other thread is using the operation during close. */
KernelStatusCode kernel_metadata_operation_close(kernel_metadata_operation_t* op);

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
Loading