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 src/flink_gateway/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ def _iter_rows(
continue

# Fetch next page.
if not token:
return
response = client.fetch_results(session, op_handle, token, "")
if response.result_type == ResultType.EOS:
return
Expand Down
31 changes: 31 additions & 0 deletions tests/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,37 @@ def test_pagination(self):
rows = cur.fetchall()
assert rows == [(1,), (2,), (3,), (4,)]

def test_single_page_eos_no_extra_fetch(self):
client = _mock_client()
cols = _columns(("id", "INTEGER", False))
client.execute_statement.return_value = "op-1"
client.fetch_results.side_effect = [
FetchResultsResponse(
result_type=ResultType.EOS,
result_kind=ResultKind.SUCCESS_WITH_CONTENT,
is_query_result=True,
next_result_uri="",
results=ResultSet(
columns=cols,
data=[
RowData(kind="INSERT", fields=[1]),
RowData(kind="INSERT", fields=[2]),
],
),
),
RuntimeError(
"fetch_results called with empty token — would be 404 on server"
),
]

conn = _make_connection(client)
cur = conn.cursor()
cur.execute("SELECT id FROM t")
rows = list(cur)

assert rows == [(1,), (2,)]
assert client.fetch_results.call_count == 1

def test_exec_non_query(self):
"""Non-query statements should not produce rows."""
client = _mock_client()
Expand Down
Loading