Repository navigation
fix(statement): distinguish SELECT aliases from DML row counts - #433
aakash-saravanan-db wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
Verdict: 2 Low
Looks good: requiring DML SQL before exposing row counts fixes the SELECT-alias misreport, and every path is covered (sync execute, execute-direct, submit, attached/reader() handles), with wiremock and C ABI tests. Two low-severity edge cases where the new keyword scanner misclassifies real DML.
ebd4f26 to
f62ad30
Compare
There was a problem hiding this comment.
Verdict: 1 Medium · 1 Low
The fix is sound: SQL-gated inference closes the alias false-positive across sync, async and C ABI, and it has good test coverage. Two concerns: attached handles (used by the Python bindings) lose DML counts, and FROM-first multi-insert DML is no longer counted.
f62ad30 to
77288a1
Compare
There was a problem hiding this comment.
Verdict: 1 Low
Looks good overall, with one low-severity note: the new SQL check stops CTAS/RTAS and EXECUTE IMMEDIATE DML from reporting affected-row counts. The infer_num_modified_rows setting is passed through the sync, async, execute_direct and attach paths correctly, and the new FetchResultOutcome caches the terminal status on every error path. The new wiremock tests cover all of this well.
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
There was a problem hiding this comment.
Verdict: 1 Medium
Overall the change looks good, with one medium gap: the new SQL classifier doesn't recognize CTAS/RTAS when the query after AS is in parentheses, so those statements stop reporting row counts. Also worth noting: ID-only attach_async_statement handles (which the PyO3 bindings expose) deliberately no longer infer DML counts from result columns. Python callers who re-attach to DML by ID will now get rowcount=-1 unless the server sends the count in status metadata.
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
There was a problem hiding this comment.
Verdict: 1 Low
Looks good overall, with one low concern. Gating column-name count inference on the submitted SQL is the right fix, and the classifier is careful about comments, quoting and CTEs. The classifier claims to handle COPY INTO, but the strict all-counter-columns check may still reject COPY INTO's real result, so it may never get a count. Nit: the get_statement_status doc comment in src/client/sea.rs now ends with a stray empty /// line where the removed sentence used to be.
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
There was a problem hiding this comment.
Verdict: 1 Medium
Looks good overall. One medium concern: handles reattached by statement ID no longer report modified-row counts for DML, and the wrappers can observe that. The SQL classifier, the async terminal-status caching and the new regression tests look correct; I traced the comment, quote, CTE and multi-insert paths and found no incorrect results.
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
There was a problem hiding this comment.
Verdict: 1 Low
Looks good overall. One low-severity note: attached handles no longer infer DML counts, which is intentional and documented but visible to users. The SQL classifier and the handling of the terminal status in async fetch both look correct, with good test coverage at the unit, wiremock and C ABI levels.
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
There was a problem hiding this comment.
Verdict: 1 Low
The fix looks sound, with one low-severity concern. The SQL classifier handles comments, quoted text, CTEs, multi-insert, COPY INTO, CTAS/RTAS and EXECUTE IMMEDIATE, and has thorough unit tests. The async terminal-status caching paths have tests that would fail without the change. The concern is that execute_direct's Completed path still never infers DML counts, unlike the other entry points.
There was a problem hiding this comment.
Verdict: 2 Low
Looks good, with two low-severity notes. Row-count inference now requires the submitted SQL to be a modifying statement, so a SELECT using counter names like num_affected_rows no longer reports modified rows; the async path now records the terminal status on every fetch outcome, and the tests cover these paths. The notes are a CTAS classifier gap (it stops at the first AS, so forms like STORED AS PARQUET AS SELECT are missed) and a missing changelog entry for the main fix.
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
There was a problem hiding this comment.
Verdict: 1 Low
Looks good overall, with one low-severity gap: the SQL classifier and the plumbing that passes the inference flag look sound. I checked UTF-8 slicing, nested comments, CTE forms and raw strings, and both terminal-error paths now record the status. The one gap is an existing inconsistency in the execute_direct Completed arm that this PR could close cheaply.
There was a problem hiding this comment.
Verdict: 1 Low
Looks good overall. The SQL-gated DML-count inference and the new FetchResultOutcome status retention are sound and have tests at the unit and wiremock levels. One low finding: the allow-list classifier now drops counts for statements it doesn't recognize, such as SQL scripting blocks, and the changelog doesn't mention that.
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
|
Will all of this complexity go away if we modify SEA API to expose numModifiedRows in the result manifest? I slightly prefer that tbh to simplify client side |
Summary
SEA returns affected-row counts as result columns such as
num_affected_rows. The kernel previously identified these results fromtheir column names alone, so an ordinary query such as:
was incorrectly exposed as having modified seven rows.
This change also checks the submitted SQL statement before inferring
modified-row metadata. The shared classifier recognizes direct, CTE-prefixed,
and
FROM ... INSERTmulti-insert DML, as well as COPY INTO, CTAS/RTAS, andliteral EXECUTE IMMEDIATE write statements. It ignores keywords inside
comments, quoted values, identifiers, and nested expressions. Dynamic
EXECUTE IMMEDIATE statements whose SQL is unavailable remain unknown.
ID-only attached statements do not have their submitted SQL, so they do not
infer counts from result-column names. Any count supplied directly in status
metadata remains available. Async result fetches retain the terminal wire
status across successful, failed, and reader-error paths before returning a
result or mapped error.
Validation
multi-insert, COPY INTO, CTAS/RTAS, literal EXECUTE IMMEDIATE, dynamic SQL,
and SELECT controls.
reader-error terminal paths.
SELECT 7 AS num_affected_rowsreturns row
7withrowcount=-1.2,1, and0.[2, 2, 0]; the rebuilt Python kernel reportsrowcount=2before and after fetching it.