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

Stop button for queries doesn't work in SQL Lab when using SQL Lab with impala engine #20950

Closed
haimingOu opened this issue Aug 3, 2022 · 3 comments · Fixed by #22635
Closed
Labels
#bug Bug report

Comments

@haimingOu
Copy link

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

11

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.

@haimingOu haimingOu added the #bug Bug report label Aug 3, 2022
@msestak
Copy link

msestak commented Aug 3, 2022

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)

@wanghong1314
Copy link
Contributor

Same issue here

@wanghong1314
Copy link
Contributor

wanghong1314 commented Oct 28, 2022

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()

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#bug Bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants