Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- **Behavior change:** Closed Thrift Arrow row scanners return an explicit error without logging an ERROR instead of stale values; a destination whose column count differs from the Arrow holders now errors instead of filling leading columns or NULL-padding missing columns. Column-value setup failures now stop scanning and are retained for subsequent scans instead of only being logged and ignored (databricks/databricks-sql-go#602).
- Support SOCKS proxies on the kernel backend; see [Proxy](CONNECTION_PARAMETERS.md#proxy).
- **Behavior change:** On the kernel backend, `NO_PROXY` now also applies to CloudFetch storage and OAuth hosts, with the differences from the Thrift path listed in [Proxy](CONNECTION_PARAMETERS.md#proxy).
- Support Volume PUT, GET and REMOVE on the kernel backend: with the staging context, the kernel transfers the file during execution. Local paths, with symlinks resolved, must be within the staging roots (databricks/databricks-sql-go#560).

## v2.0.0 (2026-11-23)

Expand Down
2 changes: 1 addition & 1 deletion KERNEL_REV
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a29235cbea9532efa5572ebff010045583a19cbe
d18b044bdd8d6a3ef7c7dd763a5f38c1532a213f
13 changes: 10 additions & 3 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@ RetryWaitMin / RetryWaitMax / RetryMax, including the disable form, forwarded to
kernel's HTTP retry config); and the TLS, proxy, and session-conf (query tags,
statement timeout, time zone) options. Federated token providers use one token snapshot
during setup. Nothing is silently ignored: WithTimeout and token-provider / external /
static authenticators are rejected at connect; staging (PUT/GET/REMOVE on a
Unity Catalog volume) is rejected at execute. WithMaxRows is accepted but inert (the
static authenticators are rejected at connect. WithMaxRows is accepted but inert (the
kernel manages fetching below the C ABI).

Kernel HTTP requests inherit the driver's ClientTimeout (900s by default). If
that value is zero, the kernel uses its own 120s default; zero is neither
unlimited nor an immediate timeout.
unlimited nor an immediate timeout. For a Volume file transfer it is an idle limit
rather than a total deadline; use a context deadline to bound the whole transfer.

OAuth U2M is interactive: on a cache miss, connecting launches the system browser and
blocks until login completes or the kernel's ~120s callback timeout expires. Because
Expand Down Expand Up @@ -381,6 +381,13 @@ After doing so, you can execute staging operations using this context using the

_, err1 := db.ExecContext(ctx, `PUT 'staging/file.csv' INTO '/Volumes/main/staging_test/e2etests/file.csv' OVERWRITE`)

With the kernel backend, a statement run with the staging context transfers its
file during ExecContext or QueryContext, and ExecContext reports zero rows
affected. Local paths, with symlinks resolved, must be within the staging roots.
Without the staging context, ExecContext fails a PUT, GET or REMOVE and
QueryContext returns its instruction row, as on Thrift. New GET files are created
with mode 0666 before the umask; the Thrift backend uses 0644.

# Errors

There are three error types exposed via dbsql/errors
Expand Down
10 changes: 0 additions & 10 deletions examples/kernel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,4 @@ func main() {
log.Fatalf("query: %v", err)
}
fmt.Printf("server version: %s\n", version)

// Options the kernel can't honor are rejected with an error wrapping
// ErrNotSupportedByKernel, never silently ignored. Staging (PUT/GET/REMOVE on a
// Unity Catalog volume) is one such feature, rejected at execute.
_, err = db.ExecContext(ctx, "PUT '/tmp/local.csv' INTO '/Volumes/main/default/vol/f.csv' OVERWRITE")
if errors.Is(err, dbsqlerr.ErrNotSupportedByKernel) {
fmt.Println("staging is not supported on the kernel backend (use Thrift for staging)")
} else if err != nil {
fmt.Printf("staging: %v\n", err)
}
}
11 changes: 0 additions & 11 deletions internal/backend/kernel/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import (
"sync/atomic"
"time"

dbsqlerr "github.com/databricks/databricks-sql-go/v2/errors"
"github.com/databricks/databricks-sql-go/v2/internal/backend"
dbsqlerrint "github.com/databricks/databricks-sql-go/v2/internal/errors"
)
Expand Down Expand Up @@ -925,15 +924,5 @@ func (k *KernelBackend) Execute(ctx context.Context, req backend.ExecRequest) (b
// so ErrBadConn can safely retire the connection before this request.
return &kernelOp{}, dbsqlerrint.NewBadConnectionError(errors.New("kernel: session is no longer valid"))
}
// Staging (Unity Catalog volume PUT/GET/REMOVE) needs a local file transfer the
// kernel path can't perform, and the kernel C ABI surfaces no IsStagingOperation
// signal to drive conn.execStagingOperation. Reject it here rather than let
// IsStaging return false and report success with no file moved (silent data loss).
// (Bound parameters, by contrast, ARE now supported — bound in execute via the
// kernel's raw-param C ABI.)
if isStagingStatement(req.Query) {
return &kernelOp{}, fmt.Errorf("databricks: staging operations (PUT/GET/REMOVE on a volume) are %w; "+
"use the default (Thrift) backend", dbsqlerr.ErrNotSupportedByKernel)
}
return k.execute(ctx, req)
}
9 changes: 8 additions & 1 deletion internal/backend/kernel/cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ import "C"
import (
"context"
"fmt"
"os"
"runtime"
"syscall"
"unsafe"

"github.com/databricks/databricks-sql-go/v2/driverctx"
Expand Down Expand Up @@ -178,6 +180,11 @@ func lastError(code C.KernelStatusCode) *KernelError {
if e.query_id != nil {
ke.QueryID = C.GoString(e.query_id)
}
ke.ErrorCode = C.GoString(C.kernel_get_last_error_code())
Comment thread
aakash-saravanan-db marked this conversation as resolved.
Resolved
Comment thread
aakash-saravanan-db marked this conversation as resolved.
Resolved
Comment thread
aakash-saravanan-db marked this conversation as resolved.
Resolved
Comment thread
aakash-saravanan-db marked this conversation as resolved.
Resolved
Comment thread
aakash-saravanan-db marked this conversation as resolved.
Resolved
Comment thread
aakash-saravanan-db marked this conversation as resolved.
Resolved

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The cgo shim now calls new kernel ABI symbols (kernel_get_last_error_code, kernel_result_stream_complete_volume_operation), but go.mod still pins the published bindings at v1.5.0. Only the source-built KERNEL_REV changes, so consumers using the default prebuilt archives may fail to link. Bump all platform bindings pins and go.sum to a release that exports these symbols.

🔀 Found by GPT-6.1 Sol · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of the release gate in #560 (comment). The v1.5.0 bindings archives lack these symbols, so the seven bindings modules in go.mod and go.sum move to the first kernel release that includes databricks-sql-kernel#512 and databricks-sql-kernel#513 before merge, as the Kernel version section of the description states.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at 16adbcd: go.mod:63-69 pins all seven bindings at v1.5.0, which lacks these symbols; this stays a merge blocker.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocked on the kernel release, so I'm leaving this open: the cgo calls need databricks/databricks-sql-kernel#520 and #521 merged and a bindings release that includes them, and the go.mod bindings pins move to that release before this merges. KERNEL_REV already pins the #521 head for source builds.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at b884e82: go.mod:63-69 still pins all seven bindings at v1.5.0; this blocks merge until the kernel release lands and the pins move to it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The PR calls new kernel C ABI symbols (kernel_result_stream_complete_volume_operation, kernel_get_last_error_code and others) and bumps KERNEL_REV. go.mod and go.sum still pin the published v1.5.0 bindings, so installed-driver builds may fail to link. Bump all platform bindings pins to a release that exports these symbols, or split the change.

🔀 Found by GPT-6.1 Sol · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of the release gate in #560 (comment). The v1.5.0 bindings archives lack these symbols, so the seven bindings modules in go.mod and go.sum move to the first kernel release that includes databricks-sql-kernel#512 and databricks-sql-kernel#513 before merge, as the Kernel version section of the description states.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at 16adbcd: all seven bindings modules are still pinned to v1.5.0 (go.mod:63-69), and that release lacks these symbols.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocked on the kernel release, so I'm leaving this open: the cgo calls need databricks/databricks-sql-kernel#520 and #521 merged and a bindings release that includes them, and the go.mod bindings pins move to that release before this merges. KERNEL_REV already pins the #521 head for source builds.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at b884e82: go.mod:63-69 still pins all seven bindings modules to v1.5.0, which lacks the new symbols; merge blocker.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The PR calls new kernel ABI symbols (kernel_get_last_error_code, kernel_result_stream_complete_volume_operation) unconditionally, but go.mod still pins every platform bindings module at v1.5.0. The repo's own lessons (L-0030) say a KERNEL_REV bump alone isn't enough. Bump the go.mod/go.sum pins to a bindings release that exports these symbols, or gate the change on that release.

🔀 Found by GPT-6.1 Sol · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocked on the kernel release, so I'm leaving this open: the cgo calls need databricks/databricks-sql-kernel#520 and #521 merged and a bindings release that includes them, and the go.mod bindings pins move to that release before this merges. KERNEL_REV already pins the #521 head for source builds.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at b884e82: cgo.go:183 calls new symbols, but the go.mod bindings pins are still v1.5.0. Waiting on the kernel release.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The change calls new C symbols such as kernel_get_last_error_code and kernel_result_stream_complete_volume_operation, and it bumps KERNEL_REV. go.mod still pins every kernel-bindings platform module at v1.5.0, which predates these symbols. Tagged builds that link the published modules (not make kernel-lib) will probably fail to link or fail at runtime. Bump the per-platform module versions and go.sum to the matching bindings release, then check a tagged build against the installed modules.

🔀 Found by GPT-6.1 Sol · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocked on the kernel release, so I'm leaving this open: the cgo calls need databricks/databricks-sql-kernel#520 and #521 merged and a bindings release that includes them, and the go.mod bindings pins move to that release before this merges. KERNEL_REV already pins the #521 head for source builds.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at b884e82: go.mod still pins kernel-bindings v1.5.0, which lacks kernel_get_last_error_code (cgo.go:183). Bump the pins once the bindings release ships.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The shim now calls new ABI symbols (kernel_get_last_error_code, kernel_result_stream_complete_volume_operation, etc.), but go.mod still pins every bindings module at v1.5.0. KERNEL_REV only affects source-built archives, so installed-driver kernel builds may not link. Bump the platform bindings pins and go.sum to a release that exports these symbols, or gate the merge on that release.

🔀 Found by GPT-6.1 Sol · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocked on the kernel release, so I'm leaving this open: the cgo calls need databricks/databricks-sql-kernel#520 and #521 merged and a bindings release that includes them, and the go.mod bindings pins move to that release before this merges. KERNEL_REV already pins the #521 head for source builds.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at b884e82: go.mod:63-69 still pin all bindings at v1.5.0; waiting on the kernel #520/#521 release.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — cgo.go now calls kernel_get_last_error_code and the Volume completion symbols. go.mod still pins the published bindings modules at v1.5.0, and the diff only bumps KERNEL_REV. Default (non-source-built) kernel builds may fail to link. Bump every platform module and go.sum to a bindings release that exports these symbols, then check a clean consumer build.

🔀 Found by GPT-6.1 Sol · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same release gate as #560 (comment). databricks/databricks-sql-kernel#520 and #521 are merged (KERNEL_REV now pins d18b044b), but the bindings modules and sums in go.mod and go.sum can only move once a bindings release ships, so this stays open until then.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at 4d71e38: go.mod:63-69 pins all bindings modules at v1.5.0; bump them and go.sum once the bindings release ships.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The code now calls new kernel C ABI symbols (kernel_result_stream_complete_volume_operation, kernel_get_last_error_code and others), but go.mod and go.sum still pin the published bindings at v1.5.0, which lack them. Tagged builds from installed consumers will therefore fail to link. Publish the matching bindings release, bump all platform pins and sums, and verify a clean build.

🔀 Found by GPT-6.1 Sol · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same release gate as #560 (comment). databricks/databricks-sql-kernel#520 and #521 are merged (KERNEL_REV now pins d18b044b), but the bindings modules and sums in go.mod and go.sum can only move once a bindings release ships, so this stays open until then.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at 4d71e38: go.mod/go.sum still pin bindings v1.5.0, which lack the new ABI symbols; this is blocked until a bindings release ships.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The new C symbols (kernel_get_last_error_code, kernel_statement_set_volume_options) are only in the newer kernel, but go.mod still pins the bindings at v1.5.0, so a databricks_kernel build that uses the published archives can't link. Bump the bindings modules and go.sum to a release that has these APIs before releasing. Source builds through KERNEL_REV and the Makefile are unaffected.

🔀 Found by both reviewers · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same release gate as #560 (comment). databricks/databricks-sql-kernel#520 and #521 are merged (KERNEL_REV now pins d18b044b), but the bindings modules and sums in go.mod and go.sum can only move once a bindings release ships, so this stays open until then.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at 4d71e38: go.mod:63-69 still pin the bindings at v1.5.0, so this release gate remains outstanding.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The shim now calls new kernel symbols (kernel_get_last_error_code, kernel_statement_set_volume_options, kernel_executed_statement_is_volume_operation), but go.mod and go.sum still pin bindings v1.5.0. Only KERNEL_REV changed, so default tagged builds will likely fail to link. Publish the matching bindings release and bump every platform module in go.mod and go.sum.

🔀 Found by both reviewers · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same release gate as #560 (comment). databricks/databricks-sql-kernel#520 and #521 are merged (KERNEL_REV now pins d18b044b), but the bindings modules and sums in go.mod and go.sum can only move once a bindings release ships, so this stays open until then.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at 4d71e38: go.mod:63-69 pins all bindings at v1.5.0; bump them and go.sum after the bindings release.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The shim calls new C symbols (kernel_get_last_error_code, kernel_statement_set_volume_options, kernel_executed_statement_is_volume_operation), but go.mod/go.sum still pin bindings v1.5.0 on every platform, so a tagged build may fail to link. Bump all platform bindings pins and sums to a release exporting these symbols, as the repo's own learning log requires.

🔀 Found by both reviewers · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same release gate as #560 (comment). databricks/databricks-sql-kernel#520 and #521 are merged (KERNEL_REV now pins d18b044b), but the bindings modules and sums in go.mod and go.sum can only move once a bindings release ships, so this stays open until then.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at efc80cd: go.mod and go.sum still pin bindings v1.5.0. They need to move to the bindings release that exports these symbols.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The new C calls (kernel_get_last_error_code, kernel_statement_set_volume_options, and the is_volume_operation functions) need a newer kernel. go.mod still pins every bindings archive to v1.5.0, so consumer builds with databricks_kernel can fail to link. Bump the go.mod and go.sum pins to a release with the new ABI before releasing. The Makefile's KERNEL_REV source build avoids this only for development.

🔀 Found by both reviewers · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same release gate as #560 (comment). databricks/databricks-sql-kernel#520 and #521 are merged (KERNEL_REV now pins d18b044b), but the bindings modules and sums in go.mod and go.sum can only move once a bindings release ships, so this stays open until then.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at efc80cd: go.mod/go.sum still pin bindings v1.5.0, so this blocks release until the new bindings ship.

if code := C.kernel_get_last_error_local_os_error(); code != 0 {
// The C ABI reports a path and errno without a syscall name.
ke.cause = &os.PathError{Op: "file", Path: C.GoString(C.kernel_get_last_error_local_path()), Err: syscall.Errno(code)}
}
klog("kernel error: code=%d sqlstate=%q vendor=%d http=%d retryable=%v msg=%q",
ke.Code, ke.SQLState, ke.VendorCode, ke.HTTPStatus, ke.Retryable, ke.Message)
// Also emit through the driver's logger — no SQL text or PII, just the
Expand All @@ -188,7 +195,7 @@ func lastError(code C.KernelStatusCode) *KernelError {
// User/query faults (bad SQL, bad argument) are routine and log at Debug so they
// don't inflate the WARN rate on-call alerts key on; infra codes stay at Warn.
msg := "databricks: kernel call failed: code=%d sqlstate=%q vendor=%d http=%d retryable=%v queryId=%q"
if isUserFault(ke.Code) {
if isUserFault(ke.Code, ke.ErrorCode) {
logger.Logger.Debug().Msgf(msg, ke.Code, ke.SQLState, ke.VendorCode, ke.HTTPStatus, ke.Retryable, ke.QueryID)
} else {
logger.Logger.Warn().Msgf(msg, ke.Code, ke.SQLState, ke.VendorCode, ke.HTTPStatus, ke.Retryable, ke.QueryID)
Expand Down
16 changes: 11 additions & 5 deletions internal/backend/kernel/errors_classify.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ type KernelError struct {
HTTPStatus uint16
Retryable bool
QueryID string
ErrorCode string
cause error
}

func (e *KernelError) Unwrap() error { return e.cause }

func (e *KernelError) Error() string {
// Append the server query id when present — it is the one correlation handle
// to server-side query history, and on the execute-error path (no exec handle)
Expand Down Expand Up @@ -135,6 +139,9 @@ func isBadConnection(code int) bool {
// invalid session handles are fatal; other missing resources or invalid
// arguments leave the session usable.
func isSessionFatal(ke *KernelError) bool {
if ke.ErrorCode == "VOLUME_STORAGE_HTTP_ERROR" || ke.ErrorCode == "VOLUME_STORAGE_NETWORK_ERROR" {
return false
}
switch ke.Code {
case statusUnauthenticated, statusUnavailable, statusNetworkError:
return true
Expand All @@ -147,20 +154,19 @@ func isSessionFatal(ke *KernelError) bool {
}
}

// isUserFault reports whether a status code is a user/query fault (a bad SQL
// statement or a bad argument) rather than an infrastructure problem. Used to
// isUserFault reports whether a kernel error is a user fault (bad SQL, a bad
// argument or a local file error) rather than an infrastructure problem. Used to
// pick the log level for a kernel-call failure: user faults are routine — a
// fat-fingered query should not raise the driver's WARN rate and page on-call —
// so they log at Debug, while infra codes (Unavailable / NetworkError / Timeout /
// Unauthenticated) stay at Warn. Mirrors the Thrift path, which keeps user SQL
// errors out of operational-noise logging.
func isUserFault(code int) bool {
func isUserFault(code int, errorCode string) bool {
switch code {
case statusSqlError, statusInvalidArgument:
return true
default:
return false
}
return errorCode == "VOLUME_LOCAL_FILE_ERROR"
}

// toConnError classifies a kernel error on a SESSION-lifecycle path (open/close/
Expand Down
18 changes: 16 additions & 2 deletions internal/backend/kernel/errors_classify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ func TestIsSessionFatal(t *testing.T) {
t.Errorf("code %d should not be session-fatal", code)
}
}
for _, err := range []*KernelError{
{Code: statusUnauthenticated, ErrorCode: "VOLUME_STORAGE_HTTP_ERROR"},
{Code: statusNetworkError, ErrorCode: "VOLUME_STORAGE_NETWORK_ERROR"},
} {
if isSessionFatal(err) {
t.Errorf("storage error %s should not be session-fatal", err.ErrorCode)
}
}
}

func expiredSessionError() *KernelError {
Expand Down Expand Up @@ -138,16 +146,22 @@ func TestExpiredSessionDoesNotTriggerReplay(t *testing.T) {
func TestIsUserFault(t *testing.T) {
faults := []int{statusSqlError, statusInvalidArgument}
for _, code := range faults {
if !isUserFault(code) {
if !isUserFault(code, "") {
t.Errorf("code %d should be a user fault (log at Debug)", code)
}
}
infra := []int{statusUnavailable, statusNetworkError, statusTimeout, statusUnauthenticated}
for _, code := range infra {
if isUserFault(code) {
if isUserFault(code, "") {
t.Errorf("code %d is infra-side and should NOT be a user fault (stays Warn)", code)
}
}
if !isUserFault(statusNotFound, "VOLUME_LOCAL_FILE_ERROR") {
t.Error("a local file error should be a user fault (log at Debug)")
}
if isUserFault(statusNotFound, "VOLUME_STORAGE_HTTP_ERROR") {
t.Error("a storage HTTP error should not be a user fault (stays Warn)")
}
}

// toConnError (session-lifecycle path) wraps a session-unusable KernelError as
Expand Down
58 changes: 52 additions & 6 deletions internal/backend/kernel/include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ typedef struct KernelError {
*/
bool kernel_get_last_error(KernelError* out);

/*
* Details of the last error recorded on the calling thread. Strings are NULL
* when absent and valid until the next kernel call on that thread.
* - `_code`: string code such as `VOLUME_PATH_NOT_ALLOWED`.
* - `_local_os_error`: OS error number behind a local file error (errno, or
* a Windows error code on Windows), or 0.
* - `_local_path`: local path of a local file error.
*/
const char* kernel_get_last_error_code(void);
int32_t kernel_get_last_error_local_os_error(void);
const char* kernel_get_last_error_local_path(void);

/* ─── Opaque handles ──────────────────────────────────────────────────
*
* All handles are owned heap allocations on the Rust side; the C side
Expand Down Expand Up @@ -387,7 +399,9 @@ KernelStatusCode kernel_session_config_set_sea_response_compression_enabled(
/* Configure the total timeout for one HTTP request, from connection start
* through response-body completion. A separate 30s connection timeout also
* applies, so connection establishment is bounded by the shorter limit.
* `request_timeout_ms == 0` keeps the kernel default (120s). */
* `request_timeout_ms == 0` keeps the kernel default (120s). For Volume file
* transfers it is an idle limit: a transfer fails after this long without
* progress. */
KernelStatusCode kernel_session_config_set_request_timeout(KernelSessionConfig* config,
uint64_t request_timeout_ms);

Expand Down Expand Up @@ -628,10 +642,8 @@ KernelStatusCode kernel_session_config_set_u2m_token_cache_config(KernelSessionC
*
* Counterpart to kernel_session_config_set_session_conf: that one carries
* SERVER session confs (ANSI_MODE, TIMEZONE, ...) to the SEA wire; this one
* sets CLIENT-SIDE knobs that tune how the kernel fetches, buffers, and
* post-processes results and are NEVER sent to the server. The two channels
* are deliberately separate (conflating them is what made a client flag
* masquerade as a rejected server conf).
* configures how the kernel requests, fetches, buffers, and post-processes
* results. These keys are kept out of the server session configuration.
*
* Key/value (rather than one typed setter per knob) so the signature never
* changes as new result knobs are added, and so a host that already has DSN
Expand All @@ -642,6 +654,9 @@ KernelStatusCode kernel_session_config_set_u2m_token_cache_config(KernelSessionC
* Recognised keys (case-insensitive):
* - "cloudfetch_enabled" = "true"|"false" — false serves every result
* through paged inline delivery without cloud-storage downloads.
* - "lz4_compression_enabled" = "true"|"false", for LZ4 compression
* for Arrow results. Sets the session default; defaults to "true".
* The C ABI has no per-statement compression setter.
* - "cloudfetch_link_prefetch_window" = positive integer.
* - "cloudfetch_max_chunks_in_memory" = positive integer (bounds peak RSS;
* values above the kernel ceiling of 256 are clamped with a warning).
Expand Down Expand Up @@ -802,6 +817,21 @@ KernelStatusCode kernel_statement_bind_parameter(kernel_statement_t* stmt,
KernelStatusCode kernel_statement_set_query_tags(kernel_statement_t* stmt,
const char* query_tags);

/*
* Set the Volume transfer options for later executions of `stmt`. With them,
* executing a Volume PUT, GET or REMOVE also runs its file transfer, and the
* execution fails if the transfer does. `allowed_paths_json`: JSON array of
* local directories a transfer may use; the local path, with symlinks
* resolved, must be inside one of them. NULL clears the options, so a Volume
* statement returns its instruction row without transferring.
* `remove_not_found_is_success`: report success when REMOVE targets a missing
* object. The options survive kernel_statement_set_sql. This API takes no upload
* bytes, so `PUT '__input_stream__'` fails.
*/
KernelStatusCode kernel_statement_set_volume_options(kernel_statement_t* stmt,
const char* allowed_paths_json,
bool remove_not_found_is_success);

/*
* Wait-for-result execution without an overall client polling deadline.
* On success, release `*out` with
Expand Down Expand Up @@ -959,6 +989,10 @@ KernelStatusCode kernel_executed_statement_get_result_stream(kernel_executed_sta
*/
int64_t kernel_executed_statement_num_modified_rows(const kernel_executed_statement_t* exec);

/* Whether the server marked the statement as a Volume PUT, GET or REMOVE. */
KernelStatusCode kernel_executed_statement_is_volume_operation(
const kernel_executed_statement_t* exec, bool* out);

/*
* Server statement (query) id of a successfully executed statement, as a
* NUL-terminated C string — the success-path counterpart to the query id on
Expand Down Expand Up @@ -988,10 +1022,18 @@ KernelStatusCode kernel_executed_async_statement_status(
* state returns KernelStatusCode_InvalidArgument rather than blocking (v0
* collapses invalid-state into that code). This is single-consumption:
* a second successful take is rejected. Close the stream with
* kernel_result_stream_close. */
* kernel_result_stream_close. For a statement the server marks as a Volume
* PUT, GET or REMOVE, it runs the file transfer before returning. */
KernelStatusCode kernel_executed_async_statement_get_result_stream(
kernel_executed_async_statement_t* exec, kernel_result_stream_t** out);

/* Whether the last status poll reported success for a statement the server
* marks as a Volume PUT, GET or REMOVE. False before that poll and once the
* result stream is taken. Returns KernelStatusCode_InvalidStatementHandle
* after the parent statement is re-executed or closed. */
KernelStatusCode kernel_executed_async_statement_is_volume_operation(
const kernel_executed_async_statement_t* exec, bool* out);

/* Most recently observed DML count, or -1 when unavailable. */
int64_t kernel_executed_async_statement_num_modified_rows(
const kernel_executed_async_statement_t* exec);
Expand Down Expand Up @@ -1068,6 +1110,10 @@ KernelStatusCode kernel_result_stream_canceller_cancel(
KernelStatusCode kernel_result_stream_canceller_free(
kernel_result_stream_canceller_t* canceller);

/* Whether the server marked this result as a Volume PUT, GET or REMOVE. */
KernelStatusCode kernel_result_stream_is_volume_operation(const kernel_result_stream_t* stream,
bool* out);

/* ─── Metadata ────────────────────────────────────────────────────────
*
* Each returns a self-contained result stream (released via
Expand Down
35 changes: 7 additions & 28 deletions internal/backend/kernel/kernel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"encoding/json"
"errors"
"fmt"
"io/fs"
"os"
"strings"
"sync"
"syscall"
"testing"
"time"

Expand Down Expand Up @@ -573,33 +575,6 @@ func TestExecuteHandleLessOpContract(t *testing.T) {
}
}

// TestExecuteRejectsStaging drives Execute with a staging statement (not just the
// isStagingStatement detector in isolation) to pin the detector→Execute wiring: a
// refactor that dropped or reordered the check would silently reopen the
// silent-no-op data-loss path. Mirrors TestExecuteRejectsParams.
func TestExecuteRejectsStaging(t *testing.T) {
k := &KernelBackend{valid: true}
op, err := k.Execute(context.Background(), backend.ExecRequest{
Query: "PUT '/tmp/f' INTO '/Volumes/main/s/e/f.csv'",
})
if err == nil {
t.Fatal("expected an error for a staging statement, got nil")
}
if !errors.Is(err, dbsqlerr.ErrNotSupportedByKernel) {
t.Errorf("staging rejection should wrap ErrNotSupportedByKernel, got %v", err)
}
if op == nil {
t.Fatal("Execute must return a non-nil Operation per the Backend contract")
}
closed, closeErr := op.Close(context.Background())
if closeErr != nil {
t.Errorf("Close error = %v, want nil", closeErr)
}
if closed {
t.Error("Close on a handle-less op must report closed=false (no CLOSE_STATEMENT)")
}
}

// ExecutionError must satisfy the same public contract as the Thrift path so the
// errors.Is → errors.As → SqlState()/QueryId() recipe documented in doc.go works
// on the kernel backend too (it previously returned a bare *KernelError that
Expand All @@ -611,7 +586,8 @@ func TestExecutionErrorContract(t *testing.T) {
t.Errorf("ExecutionError(nil) = %v, want nil", got)
}

cause := &KernelError{Code: statusSqlError, Message: "boom", SQLState: "42000", QueryID: "q-123"}
cause := &KernelError{Code: statusSqlError, Message: "boom", SQLState: "42000", QueryID: "q-123",
cause: &os.PathError{Op: "file", Path: "missing.bin", Err: syscall.ENOENT}}
err := o.ExecutionError(context.Background(), cause)
if err == nil {
t.Fatal("ExecutionError(cause) should not be nil")
Expand All @@ -637,6 +613,9 @@ func TestExecutionErrorContract(t *testing.T) {
if !errors.As(err, &ke) {
t.Error("the *KernelError cause should remain reachable via errors.As")
}
if !errors.Is(err, fs.ErrNotExist) {
t.Errorf("local file error should match fs.ErrNotExist; got %v", err)
}
}

// The execute error path must NEVER report retryable, even when the kernel marks
Expand Down
Loading
Loading