class_docstr: Engine spec for Cloudera's Impala
class_docstr_tok: ["Engine","spec","for","Cloudera","'s","Impala"]
docstr: Stop query and updates progress information
docstr_tok: ["Stop","query","and","updates","progress","information"]
code: def handle_cursor(cls, cursor: Any, query: Query) -> None:
      """Stop query and updates progress information"""
  
      query_id = query.id
      unfinished_states = (
          "INITIALIZED_STATE",
          "RUNNING_STATE",
      )
  
      try:
          status = cursor.status()
          while status in unfinished_states:
              db.session.refresh(query)
              query = (
                  db.session.query(Query).filter_by(id=query_id).one()
              )
              # if query cancelation was requested prior to the handle_cursor call, but
              # the query was still executed
              # modified in stop_query in views / core.py is reflected  here.
              # stop query
              if query.extra.get(QUERY_EARLY_CANCEL_KEY):
                  cursor.cancel_operation()
                  cursor.close_operation()
                  cursor.close()
                  break
  
              #  updates progress info by log
              try:
                  log = cursor.get_log() or ""
              except Exception:  # pylint: disable=broad-except
                  logger.warning("Call to GetLog() failed")
                  log = ""
  
              if log:
                  match = QUERY_PROGRESS_REGEX.match(log)
                  if match:
                      progress = int(
                          match.groupdict()["query_progress"]
                      )
                  logger.debug(
                      "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:
                      db.session.commit()
              sleep_interval = current_app.config[
                  "DB_POLL_INTERVAL_SECONDS"
              ].get(cls.engine, 5)
              time.sleep(sleep_interval)
              status = cursor.status()
      except Exception:  # pylint: disable=broad-except
          logger.debug("Call to status() failed ")
          return
  
file_path: superset/superset/db_engine_specs/impala.py
imports: import logging
  import re
  import time
  from datetime import datetime
  from typing import Any, Optional
  from flask import current_app
  from sqlalchemy import types
  from sqlalchemy.engine.reflection import Inspector
  from superset import db
  from superset.constants import QUERY_EARLY_CANCEL_KEY, TimeGrain
  from superset.db_engine_specs.base import BaseEngineSpec
  from superset.models.sql_lab import Query
label_desc: Use image node_id 6 for calling the ImpalaEngineSpec obj's underlying member method code with example usage: obj.handle_cursor(cls, cursor, query) without return types