john-bodley commented on a change in pull request #15403:
URL: https://github.com/apache/superset/pull/15403#discussion_r673636730
##########
File path: superset/db_engine_specs/base.py
##########
@@ -1303,6 +1303,28 @@ def get_column_spec(
)
return None
+ @classmethod
+ def get_cancel_query_payload(cls, cursor: Any, query: Query) -> Any:
+ """
+ Returns None if query can not be cancelled.
+ :param cursor: Cursor instance in which the query will be executed
+ :param query: Query instance
+ :return: Type of the payload can vary depends on databases
+ but must be jsonable. None if query can't be cancelled.
+ """
+ return None
+
+ @classmethod
+ def cancel_query(cls, cursor: Any, query: Query, payload: Any) -> None:
+ """
+ Cancels query in the underlying database.
+ The method is called only when payload is not None.
+ :param cursor: New cursor instance to the db of the query
+ :param query: Query instance
+ :param payload: Value returned by get_cancel_query_payload or set in
+ other life-cycle methods of the query
+ """
Review comment:
@koszti shouldn't the base method return `False`?
##########
File path: superset/db_engine_specs/mysql.py
##########
@@ -220,3 +221,34 @@ def get_column_spec( # type: ignore
return super().get_column_spec(
native_type, column_type_mappings=column_type_mappings
)
+
+ @classmethod
+ def get_cancel_query_id(cls, cursor: Any, query: Query) -> Optional[str]:
+ """
+ Get MySQL connection ID that will be used to cancel all other running
+ queries in the same connection.
+
+ :param cursor: Cursor instance in which the query will be executed
+ :param query: Query instance
+ :return: MySQL Connection ID
+ """
+ cursor.execute("SELECT CONNECTION_ID()")
+ row = cursor.fetchone()
+ return row[0]
+
+ @classmethod
+ def cancel_query(cls, cursor: Any, query: Query, cancel_query_id: str) ->
bool:
+ """
+ Cancel query in the underlying database.
+
+ :param cursor: New cursor instance to the db of the query
+ :param query: Query instance
+ :param cancel_query_id: MySQL Connection ID
+ :return: True if query cancelled successfully, False otherwise
+ """
+ try:
+ cursor.execute(f"KILL CONNECTION {cancel_query_id}")
+ except Exception: # pylint: disable=broad-except
Review comment:
Catching broad exceptions (per the Pylint message) is undesirable. This
should most likely be
[sqlalchemy.exc.DBAPIError](https://docs.sqlalchemy.org/en/14/core/exceptions.html#sqlalchemy.exc.DBAPIError).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]