Skip to content

fix(python): correct cursor rowcount semantics - #792

Merged
youngsofun merged 1 commit into
databendlabs:fix/python-cursor-rowcount-790from
youngsofun:codex/fix-python-cursor-rowcount-semantics
Aug 6, 2026
Merged

fix(python): correct cursor rowcount semantics#792
youngsofun merged 1 commit into
databendlabs:fix/python-cursor-rowcount-790from
youngsofun:codex/fix-python-cursor-rowcount-semantics

Conversation

@youngsofun

@youngsofun youngsofun commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

  • keep rowcount at -1 for result-producing and unclassified statements
  • continue reporting write_rows for DML, including statements that affect zero rows
  • preserve zero-progress REST pages so successful empty writes still expose ServerStats
  • cache the parsed SQL AST in driver query builders and reuse it for DML classification, placeholder detection, and parameter replacement

Motivation

The target branch exposes write_rows as cursor.rowcount, but that makes a non-empty SELECT report 0. It also misses successful statements whose final response has no schema, rows, or non-zero progress, leaving zero-row DML with stats is None and rowcount == -1.

This follow-up keeps the write-statistics behavior for DML while making result-set row counts conform to PEP 249 and retaining zero-valued final statistics. SQL classification reuses the driver's existing parser result instead of parsing again in the Python binding.

Testing

  • cargo fmt --all -- --check
  • cargo test -p databend-client --lib
  • cargo test -p databend-driver --lib
  • cargo test -p databend-python --lib
  • cargo check -p databend-python
  • cargo clippy -p databend-client -p databend-driver -p databend-python --lib -- -D warnings
  • cd bindings/python && uv run ruff format --check package/databend_driver/__init__.pyi tests/cursor/steps/binding.py
  • make integration-bindings-python
  • cd bindings/python && QUERY_RESULT_FORMAT=arrow .venv/bin/python -m behave tests/cursor --name 'Insert and Select'
  • git diff --check

Compatibility

For a result-producing statement, cursor.rowcount remains -1. DML continues to report affected rows immediately from server statistics.

Follow-up to #791.

@youngsofun
youngsofun marked this pull request as draft August 6, 2026 07:57
@youngsofun
youngsofun force-pushed the codex/fix-python-cursor-rowcount-semantics branch from f9a0cbc to 30c1e87 Compare August 6, 2026 08:17
@youngsofun
youngsofun force-pushed the codex/fix-python-cursor-rowcount-semantics branch from 30c1e87 to 3257903 Compare August 6, 2026 08:33
@youngsofun
youngsofun marked this pull request as ready for review August 6, 2026 08:56
@youngsofun
youngsofun requested a review from sundy-li August 6, 2026 08:56
@youngsofun
youngsofun merged commit f1f968a into databendlabs:fix/python-cursor-rowcount-790 Aug 6, 2026
youngsofun added a commit that referenced this pull request Aug 6, 2026
* fix(python): expose cursor write statistics

* style(python): format README code examples

* fix(python): correct cursor rowcount semantics (#792)

* fix(core): move tests after implementations

---------

Co-authored-by: Yang Xiufeng <yangxiufeng.c@gmail.com>
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