superset
superset copied to clipboard
Stop button for queries doesn't work in SQL Lab when using SQL Lab with impala engine
A clear and concise description of what the bug is. I am currently having a problem: Stop button for queries doesn't work in SQL Lab when I use SQL Lab with impala engine.
How to reproduce the bug
1.Run any query in SQL Lab with impala-thriftserver as backend processing engine. 2.Press STOP button on the UI. 3.Check the query engine, the query will still be running. You will still get the results on front end when the query finishes.
Expected results
The query should be killed on the query processing engine.
Actual results
Query keeps running on the processing engine. You will still get the results on the front end when the query finishes.
Screenshots
Environment
browser type and version: Chrome/Firefox superset version: latest python version: 3.8
Checklist
Make sure to follow these steps before submitting your issue - thank you!
[√] I have checked the superset logs for python stacktraces and included it here as text if there are any. [√] I have reproduced the issue with at least the latest released version of superset. [√] I have checked the issue tracker for the same issue and I haven't found one similar.
Same issue here.
error log:
2022-08-03 15:15:05,486:INFO:backoff:Backing off stop_query(...) for 0.5s (superset.exceptions.SupersetCancelQueryException: Could not cancel query)
2022-08-03 15:15:06,052:INFO:backoff:Backing off stop_query(...) for 0.8s (superset.exceptions.SupersetCancelQueryException: Could not cancel query)
[2022-08-03 15:15:06 +0200] [2279240] [DEBUG] GET /superset/queries/1659532434199.468
2022-08-03 15:15:06,850:INFO:backoff:Backing off stop_query(...) for 0.6s (superset.exceptions.SupersetCancelQueryException: Could not cancel query)
2022-08-03 15:15:07,433:INFO:backoff:Backing off stop_query(...) for 0.1s (superset.exceptions.SupersetCancelQueryException: Could not cancel query)
2022-08-03 15:15:07,601:ERROR:backoff:Giving up stop_query(...) after 5 tries (superset.exceptions.SupersetCancelQueryException: Could not cancel query)
Same issue here
I already have a solution,The following code in superset/db_engine_specs/impala.py
@classmethod def has_implicit_cancel(cls) -> bool: """ Return True if the live cursor handles the implicit cancelation of the query, False otherise.
:return: Whether the live cursor implicitly cancels the query
:see: handle_cursor
"""
return True
@staticmethod def execute( # type: ignore cursor, query: str, async_: bool = False ): # pylint: disable=arguments-differ # kwargs = {"async": async_} cursor.execute_async(query)
@classmethod def handle_cursor(cls, cursor: Any, query: Query, session: Session) -> None: """Handle a live cursor between the execute and fetchall calls
The flow works without this method doing anything, but it allows
for handling the cursor and updating progress information in the
query object"""
# TODO: Fix circular import error caused by importing sql_lab.Query
query_id = query.id
session.refresh(query, ['status'])
query = session.query(type(query)).filter_by(id=query_id).one()
unfinished_states = (
'INITIALIZED_STATE',
'RUNNING_STATE',
)
polled = cursor.status()
query_id = query.id
if query.status == QueryStatus.STOPPED:
logger.info("query_id_cancel=" + str(query_id))
try:
cursor.cancel_operation()
cursor.close_operation()
cursor.close()
except Exception as ex:
print("The following exception occurs%s" % ex)
while polled in unfinished_states:
query = session.query(Query).filter_by(id=query_id).one()
session.refresh(query, ['status'])
is_stopped = query.extra.get('is_stopped')
if query.status == QueryStatus.STOPPED or is_stopped:
logger.info("while polled query_id_cancel=" + str(query_id))
try:
cursor.cancel_operation()
cursor.close_operation()
cursor.close()
except Exception as ex:
print("exception %s" % ex)
break
logs = cursor.get_log()
logger.info("logs=" + logs)
if logs:
progress = cls.progress(logs)
logger.info(
"Query %s: Progress total: %s", str(query_id), str(progress)
)
needs_commit = False
if progress > query.progress:
query.progress = progress
needs_commit = True
if needs_commit:
session.commit()
time.sleep(current_app.config["IMPALA_POLL_INTERVAL"])
polled = cursor.status()