Skip to content
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

fix(trino): cancel_query doesn't abort query execution in Trino server #24913

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 18 additions & 4 deletions superset/db_engine_specs/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ def get_url_for_impersonation(
def get_allow_cost_estimate(cls, extra: dict[str, Any]) -> bool:
return True

@classmethod
def execute(cls, cursor: Cursor, query: str, **kwargs: Any) -> None:
opts = {}
if "async_" in kwargs:
opts["deferred_fetch"] = kwargs["async_"]
if cls.arraysize:
cursor.arraysize = cls.arraysize

try:
cursor.execute(query, **opts)
except Exception as ex:
raise cls.get_dbapi_mapped_exception(ex)

@classmethod
def get_tracking_url(cls, cursor: Cursor) -> str | None:
try:
Expand All @@ -160,8 +173,8 @@ def handle_cursor(cls, cursor: Cursor, query: Query, session: Session) -> None:

session.commit()

# if query cancelation was requested prior to the handle_cursor call, but
# the query was still executed, trigger the actual query cancelation now
# if query cancellation was requested prior to the handle_cursor call, but
# the query was still executed, trigger the actual query cancellation now
if query.extra.get(QUERY_EARLY_CANCEL_KEY):
cls.cancel_query(
cursor=cursor,
Expand All @@ -178,7 +191,7 @@ def prepare_cancel_query(cls, query: Query, session: Session) -> None:
session.commit()

@classmethod
def cancel_query(cls, cursor: Any, query: Query, cancel_query_id: str) -> bool:
def cancel_query(cls, cursor: Cursor, query: Query, cancel_query_id: str) -> bool:
giftig marked this conversation as resolved.
Show resolved Hide resolved
"""
Cancel query in the underlying database.

Expand All @@ -188,11 +201,12 @@ def cancel_query(cls, cursor: Any, query: Query, cancel_query_id: str) -> bool:
:return: True if query cancelled successfully, False otherwise
"""
try:
# Can't use cursor.cancel() because
# cursor is new object created in sql_lab.cancel_query
dungdm93 marked this conversation as resolved.
Show resolved Hide resolved
cursor.execute(
f"CALL system.runtime.kill_query(query_id => '{cancel_query_id}',"
"message => 'Query cancelled by Superset')"
)
cursor.fetchall() # needed to trigger the call
except Exception: # pylint: disable=broad-except
return False

Expand Down
Loading