Skip to content

fix(FIR-43199): add query cancel setting #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions src/firebolt/async_db/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ async def _handle_query_execution(
query_params: Dict[str, Any] = {"output_format": JSON_OUTPUT_FORMAT}
if async_execution:
query_params["async"] = True
# timeout cancels the query by aborting the connection
if timeout_controller.timeout is not None:
query_params["cancel_query_on_connection_drop"] = "all"
resp = await self._api_request(
query,
query_params,
Expand Down
3 changes: 3 additions & 0 deletions src/firebolt/db/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ def _handle_query_execution(
query_params: Dict[str, Any] = {"output_format": JSON_OUTPUT_FORMAT}
if async_execution:
query_params["async"] = True
# timeout cancels the query by aborting the connection
if timeout_controller.timeout is not None:
query_params["cancel_query_on_connection_drop"] = "all"
resp = self._api_request(
query,
query_params,
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/dbapi/async/V2/test_timeout.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from pytest import raises

from firebolt.async_db import Connection
Expand All @@ -8,6 +10,17 @@


async def test_query_timeout(connection: Connection):
timestamp = int(time.time())
label = f"test_query_async_timeout_cancel:{timestamp}"
with connection.cursor() as cursor:
with raises(QueryTimeoutError):
await cursor.execute(f"SET query_label='{label}'")
await cursor.execute(LONG_SELECT, timeout_seconds=1)
time.sleep(10) # it takes some time for query history to update
await cursor.execute("SET query_label=''")
await cursor.execute(
"SELECT status FROM information_schema.engine_query_history WHERE query_label = ? ORDER BY end_time DESC",
[label],
)
status = await cursor.fetchone()
assert status[0] == "CANCELED_EXECUTION"
13 changes: 13 additions & 0 deletions tests/integration/dbapi/sync/V2/test_timeout.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from pytest import raises

from firebolt.db import Connection
Expand All @@ -7,6 +9,17 @@


def test_query_timeout(connection: Connection):
timestamp = int(time.time())
label = f"test_query_async_timeout_cancel:{timestamp}"
with connection.cursor() as cursor:
with raises(QueryTimeoutError):
cursor.execute(f"SET query_label='{label}'")
cursor.execute(LONG_SELECT, timeout_seconds=1)
time.sleep(10) # it takes some time for query history to update
cursor.execute("SET query_label=''")
cursor.execute(
"SELECT status FROM information_schema.engine_query_history WHERE query_label = ? ORDER BY end_time DESC",
[label],
)
status = cursor.fetchone()
assert status[0] == "CANCELED_EXECUTION"