You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ExecContext().RowsAffected() reports 0 for statements the server gives no row count for (DDL, views) #588
Result.RowsAffected() from ExecContext returns 0 both when a statement really modified no rows and when the server reported no count at all (DDL, CREATE VIEW, and other statements with no modified-row count). A caller cannot tell the two apart.
On the Thrift backend this comes from thriftOperation.AffectedRows(), which returns GetNumModifiedRows(). The generated getter returns 0 when TGetOperationStatusResp.NumModifiedRows is unset.
The kernel backend is affected too, in a different way. The C ABI already returns -1 from kernel_executed_statement_num_modified_rows for "not applicable / unknown", and normalizeAffectedRows (added in 21ad6fa) folds that -1 to 0 so the kernel backend matches Thrift. The information is available, and the Go layer discards it on both backends.
Why it matters
Tools that report how many rows a statement wrote need to tell "unknown" from "zero". For example, dbt v2 reads this value through the ADBC Databricks driver, which wraps this one, to show a per-node row count.
The ADBC spec defines the value as "the number of rows affected if known, else -1" (rows_affected in adbc.h, and the same wording on ExecuteUpdate in the Go API). Today every view or DDL statement is reported as having written 0 rows instead. The ADBC Databricks driver already returns -1 for "unknown" from its ExecuteQuery, but its ExecuteUpdate passes this driver's RowsAffected() through, so it returns 0 for the same kind of statement.
Proposal
Return -1 when the server reports no count, on both backends:
Thrift: AffectedRows() returns -1 when NumModifiedRows is unset or there is no status response. A server-reported 0 stays 0.
Kernel: normalizeAffectedRows keeps "no count" as -1 instead of folding it to 0, so both backends still report the same value (the parity goal of 21ad6fa).
Statements that report a count are unchanged.
Compatibility
This is a behavior change. Code that treated 0 as "nothing modified" will see -1 for statements with no count, such as DDL. It looks like a fit for the v2.0.0 prototype line, where the CHANGELOG already carries other behavior changes. I would add a **Behavior change:** entry there.
The change is small (about 15 lines of non-test code). I have a branch with tests and can open a PR as soon as you agree with the direction, or if you prefer a different convention for "no count", I can adapt it.
Not verified
I have not run the kernel-tagged (cgo) tests or anything against a live warehouse.
I have not confirmed what the server reports for CTAS.
Activity
feat: opt in to unknown affected-row errors