Skip to content

feat: opt-in -1 from RowsAffected when no count is reported - #591

Open
shiminlin-db wants to merge 4 commits into
mainfrom
fix/rows-affected-unknown-count
Open

shiminlin-db wants to merge 4 commits into
mainfrom
fix/rows-affected-unknown-count

Conversation

@shiminlin-db

Copy link
Copy Markdown
Collaborator

Fixes #588

Problem

Result.RowsAffected() returns 0 both when a statement modified no rows and when the server reported no modified-row count at all (DDL such as CREATE VIEW / DROP VIEW, or a SELECT run through ExecContext). Callers cannot tell the two apart.

  • Thrift backend: AffectedRows() returns the generated GetNumModifiedRows(), which yields 0 when TGetOperationStatusResp.numModifiedRows is unset (internal/backend/thrift/operation.go).
  • Kernel (SEA) backend: the C ABI returns -1 when the count is not applicable, and normalizeAffectedRows folds it to 0 for Thrift parity (internal/backend/kernel/affectedrows.go). The Statement Execution API has no modified-row field for non-DML statements, so every DDL / SELECT takes this path.

Change

Add WithReportUnknownRowsAffected(bool) and the DSN parameter reportUnknownRowsAffected=true, default off.

  • Off (default): unchanged, an unreported count is 0.
  • On: an unreported count is returned as -1 on both backends. A reported count, including 0, is returned unchanged.

Client-side only; nothing is sent to the server.

Compatibility

Returning -1 unconditionally would change what existing callers see for DDL via ExecContext (0 today), and some treat 0 as "nothing modified". The option keeps today's behavior by default; callers who want the distinction opt in.

Question for maintainers: the next release is the v2.0.0 prototype and already carries behavior changes. Do you want -1 to be the default (and drop the option), as was done for VARIANT type names in #576? The Python connector already reports cursor.rowcount = -1 for an unreported count. Happy to make that change if preferred.

Tests

  • internal/backend/thrift/operation_test.go: unset / nil status returns -1 under the option; explicit 0 and positive counts are unchanged; the default path still returns 0.
  • internal/backend/kernel/affectedrows_test.go: the sentinel is kept as -1 under the option; default folding is unchanged.
  • connection_test.go: ExecContext end to end through the Thrift backend for both settings.
  • connector_test.go, internal/config/config_test.go, kernel_config_test.go: option, DSN parsing (including a malformed value), DeepCopy, forwarding to the kernel config.
  • go test ./... and go vet ./... pass locally with CGO_ENABLED=0. The kernel-tagged call site in internal/backend/kernel/operation.go is covered by the Test (kernel backend) CI job; it was not run locally.

Not verified: whether the Thrift server leaves numModifiedRows unset (rather than 0) for DDL against a live warehouse. The Thrift half of the change acts only when the field is unset.

Docs

README, CONNECTION_PARAMETERS.md, doc.go, CHANGELOG (Unreleased).

This pull request and its description were written by Isaac.

Result.RowsAffected() returns 0 both when a statement modified no rows
and when the server reported no modified-row count (DDL such as
CREATE VIEW), so callers cannot tell the two apart.

Add WithReportUnknownRowsAffected / reportUnknownRowsAffected=true,
off by default. When enabled, an unreported count is returned as -1:

- Thrift: AffectedRows() returns -1 when NumModifiedRows is unset or
  there is no status response.
- Kernel: normalizeAffectedRows keeps the C ABI's unknown sentinel as
  -1 instead of folding it to 0, so both backends stay in parity.

A reported count, including 0, is unchanged. With the option off the
behavior is the same as before.

Refs #588

Signed-off-by: Shimin Lin <135086178+shiminlin-db@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Looks good, with 1 low concern. The option is wired through DSN parsing, DeepCopy, the Thrift backend and the kernel config, and each has unit tests. Whether the Thrift side works against a live server hasn't been checked yet. The question of making -1 the default is for the maintainers to decide.

Comment thread internal/backend/thrift/operation.go Resolved
Adds a credential-gated e2e test that runs CREATE/DROP TEMPORARY VIEW through ExecContext and checks RowsAffected is 0 by default and -1 with WithReportUnknownRowsAffected. The unit tests mock the status response, so this is what shows the server leaves NumModifiedRows unset for view DDL. Skips without warehouse credentials.

Signed-off-by: Shimin Lin <135086178+shiminlin-db@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Medium

Looks good, with 1 medium concern. The option is wired correctly through the DSN, DeepCopy, the Thrift AffectedRows and the kernel normalizeAffectedRows, and has solid unit coverage. Follow-up: the kernel path has no live E2E coverage for the new option.

Comment thread driver_e2e_test.go Resolved
The nightly Thrift job selects tests with a -run allowlist, so TestE2EReportUnknownRowsAffected never ran there. Add it so the live server's NumModifiedRows behavior for view DDL is checked.

Signed-off-by: Shimin Lin <135086178+shiminlin-db@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Nit

Looks good, with 1 low concern. The option is wired consistently through the DSN, DeepCopy, the Thrift AffectedRows and the kernel's normalizeAffectedRows, and the default behavior is unchanged. Only the kernel half lacks end-to-end coverage.

Other findings

  • ⚪ Nit — The new E2E test only exercises Thrift and the kernel-e2e nightly filter is unchanged, so no live test checks that the kernel really reports the -1 sentinel for view DDL. Unit tests do cover the config forwarding and normalizeAffectedRows, so this is a small coverage gap. Add a kernel-tagged variant and register it in the kernel-e2e -run filter. (Found by Claude Opus 5.5 · confirmed by the judge)

Moves the view DDL checks into a shared helper and adds TestKernelE2EReportUnknownRowsAffected, so a live test also confirms the kernel reports its unknown-count sentinel for view DDL. The kernel-e2e nightly filter selects the TestKernelE2E prefix, so it runs there without a workflow change.

Signed-off-by: Shimin Lin <135086178+shiminlin-db@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@shiminlin-db

Copy link
Copy Markdown
Collaborator Author

Reply to the review bot's "Other findings" on 4cd8b43:

  • Nit (no live kernel test for the -1 sentinel on view DDL): fixed in c9e3429. The view DDL checks now live in a shared helper, testViewDDLRowsAffected, and the new kernel-tagged TestKernelE2EReportUnknownRowsAffected in kernel_e2e_test.go calls it with WithUseKernel(true) and the option on and off. The kernel-e2e nightly job's -run 'TestKernelE2E' filter is a prefix match, so it already selects the new test and the workflow needs no change. The kernel-tagged code can't be built here, so the "Test (kernel backend)" CI job's compile-only vet is the check for it.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

This branch has not been deployed

No deployments
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.

ExecContext().RowsAffected() reports 0 for statements the server gives no row count for (DDL, views)

1 participant