Skip to content

[DRAFT] feat: expose rows_affected in adapter_response - #1614

Closed
ericvinicius wants to merge 1 commit into
databricks:mainfrom
ericvinicius:feature/rows-affected-adapter-response
Closed

[DRAFT] feat: expose rows_affected in adapter_response#1614
ericvinicius wants to merge 1 commit into
databricks:mainfrom
ericvinicius:feature/rows-affected-adapter-response

Conversation

@ericvinicius

@ericvinicius ericvinicius commented Jul 27, 2026

Copy link
Copy Markdown

Description

Add rows_affected to DatabricksAdapterResponse so downstream consumers (monitoring, validation pipelines) can read the number of rows affected by DML operations (INSERT/UPDATE/DELETE/MERGE) directly from run_results.json.

Changes

  • Added rows_affected: Optional[int] field to DatabricksAdapterResponse dataclass
  • Read cursor.rowcount from the Databricks SQL connector, using getattr with defensive type checking
  • Added unit tests to verify the new field is populated correctly
  • Updated CHANGELOG.md with the new feature

Why cursor.rowcount?

The value is sourced from the public cursor.rowcount attribute, which the databricks-sql-connector populates after executing DML statements.

In databricks-sql-connector (client.py, around line 1384-1390), the connector surfaces the affected-row count from the backend:

# Surface the affected-row count for DML (INSERT/UPDATE/DELETE/MERGE) as
# cursor.rowcount instead of the hardcoded -1. num_modified_rows is None
# for SELECT (and statements the server does not report a count for) →
# leave rowcount at its -1 default.
num_modified_rows = getattr(self.active_result_set, "num_modified_rows", None)
if num_modified_rows is not None:
    self.rowcount = num_modified_rows

Implementation Details

  • Reads cursor.rowcount after execution (no additional query required)
  • Uses getattr with defensive type checking to handle edge cases (missing attribute, wrong types)
  • Returns None when rowcount is -1 (default for SELECT/DDL) or not available
  • Minimal and focused on the specific use case

Related Issues

Add 'rows_affected' field to AdapterResponse that reflects
cursor.rowcount reported by the databricks-sql-connector
after DML statements (INSERT/UPDATE/DELETE/MERGE).
For SELECT or queries where the backend does not report
a count, the field is None.

This makes affected-row counts available in
'run_results.json' → adapter_response, enabling
downstream monitoring and validation pipelines.

Resolves: databricks#1607
@ericvinicius ericvinicius changed the title feat: expose rows_affected in adapter_response [DRAFT] feat: expose rows_affected in adapter_response Jul 27, 2026
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