Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyo3/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ changes go in the root `NEXT_CHANGELOG.md`.
`AuthConfig::OAuthM2MPrivateKey`.
- `Session(..., identity_federation_client_id=...)` selects SP-wide Workload
Identity Federation during mandatory token exchange.
- `Statement.set_row_limit(...)` sets the SEA server-side row cap; passing
`None` clears it.

### Updated

Expand Down
7 changes: 7 additions & 0 deletions pyo3/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ impl Statement {
Ok(())
}

/// Set the server-side row cap for this statement. ``None`` clears it.
fn set_row_limit(&mut self, row_limit: Option<i64>) -> PyResult<()> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — set_row_limit forwards any i64 through unchecked, including negative values (e.g. -1) and 0. Unlike bind_param, which deliberately rejects out-of-range ordinals client-side to surface a typed KernelError(InvalidArgument) rather than a wire-level rejection, both the kernel StatementSpec::row_limit and this binding accept negatives and defer to the SEA server. That's arguably consistent with the kernel's own (non-validating) contract, so this is not a correctness bug — but the live test only covers None, 1, 5, leaving the negative/0 boundary behavior unspecified and untested. Consider either documenting that out-of-range values are the server's responsibility, or asserting the boundary (e.g. that 0/negative raises) so the contract is pinned. Non-blocking.

let inner = alive_mut!(self, "Statement");
inner.stmt.spec().row_limit(row_limit);
Ok(())
}

/// Set per-statement query tags.
///
/// ``tags`` is a ``dict[str, str | None]`` — a ``None`` value emits
Expand Down
16 changes: 16 additions & 0 deletions pyo3/tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ def test_range_drains_to_pyarrow_table(session):
stmt.close()


@pytest.mark.parametrize("row_limit", [None, 1, 5])
@live
def test_row_limit(session, row_limit):
stmt = session.statement()
stmt.set_sql("SELECT id FROM range(10) ORDER BY id")
stmt.set_row_limit(row_limit)
exec_ = stmt.execute()
try:
table = exec_.fetch_all_arrow()
expected = list(range(10 if row_limit is None else row_limit))
Comment thread
vuanhphung marked this conversation as resolved.
Resolved
assert table.column(0).to_pylist() == expected
finally:
exec_.close()
stmt.close()


@live
def test_executed_statement_double_close_is_idempotent(session):
stmt = session.statement()
Expand Down
4 changes: 4 additions & 0 deletions pyo3/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ def test_exports_expected_classes():
}
actual = {n for n in dir(k) if not n.startswith("_")}
assert expected.issubset(actual), f"missing exports: {expected - actual}"


def test_statement_exposes_row_limit():
assert callable(k.Statement.set_row_limit)
Loading