bito-code-review[bot] commented on code in PR #44604:
URL: https://github.com/apache/superset/pull/44604#discussion_r4110242836
##########
superset/sql/execution/executor.py:
##########
@@ -186,6 +186,60 @@ def build_statement_blocks(
return parsed_script, blocks
+class _LimitedCursor:
+ """Bound cumulative cursor reads without bypassing engine fetch
processing."""
+
+ def __init__(self, cursor: Any, limit: int) -> None:
+ """Wrap a cursor with a shared budget for all row-reading methods."""
+ self._cursor = cursor
+ self._remaining = limit
+
+ def __getattr__(self, name: str) -> Any:
+ """Delegate metadata and driver-specific methods to the real cursor."""
+ return getattr(self._cursor, name)
+
+ @property
+ def arraysize(self) -> int:
+ """Expose the driver's default fetch batch size."""
+ return self._cursor.arraysize
+
+ @arraysize.setter
+ def arraysize(self, value: int) -> None:
+ """Preserve engine-specific cursor batch-size configuration."""
+ self._cursor.arraysize = value
+
+ def fetchmany(self, size: int | None = None) -> list[Any]:
+ """Read no more than the remaining budget, including across batches."""
+ size = self.arraysize if size is None else size
+ size = max(0, min(size, self._remaining))
+ # Some drivers interpret zero as unbounded, so do not call them at all.
+ if not size:
+ return []
+ # Reserve before reading so an engine's error fallback cannot retry
+ # beyond the budget after a driver has partially consumed a batch.
+ self._remaining -= size
+ return self._cursor.fetchmany(size)
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Budget reserved before driver error</b></div>
<div id="fix">
`_LimitedCursor.fetchmany` decrements `_remaining` before the driver call,
so a mid-fetch driver error consumes budget for rows never returned. BigQuery's
`fetch_data` fallback (`bigquery.py:501`) then calls `fetchall()`, which reads
only post-consumption rows — silently dropping `first_batch` or returning `[]`.
Decrement by `len(rows)` after the driver returns; returned rows still never
exceed the limit.
</div>
</div>
<small><i>Code Review Run #d0eba2</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]