@@ -134,6 +134,19 @@ def get_url_for_impersonation(
134134 def get_allow_cost_estimate (cls , extra : dict [str , Any ]) -> bool :
135135 return True
136136
137+ @classmethod
138+ def execute (cls , cursor : Cursor , query : str , ** kwargs : Any ) -> None :
139+ opts = {}
140+ if "async_" in kwargs :
141+ opts ["deferred_fetch" ] = kwargs ["async_" ]
142+ if cls .arraysize :
143+ cursor .arraysize = cls .arraysize
144+
145+ try :
146+ cursor .execute (query , ** opts )
147+ except Exception as ex :
148+ raise cls .get_dbapi_mapped_exception (ex )
149+
137150 @classmethod
138151 def get_tracking_url (cls , cursor : Cursor ) -> str | None :
139152 try :
@@ -160,8 +173,8 @@ def handle_cursor(cls, cursor: Cursor, query: Query, session: Session) -> None:
160173
161174 session .commit ()
162175
163- # if query cancelation was requested prior to the handle_cursor call, but
164- # the query was still executed, trigger the actual query cancelation now
176+ # if query cancellation was requested prior to the handle_cursor call, but
177+ # the query was still executed, trigger the actual query cancellation now
165178 if query .extra .get (QUERY_EARLY_CANCEL_KEY ):
166179 cls .cancel_query (
167180 cursor = cursor ,
@@ -178,7 +191,7 @@ def prepare_cancel_query(cls, query: Query, session: Session) -> None:
178191 session .commit ()
179192
180193 @classmethod
181- def cancel_query (cls , cursor : Any , query : Query , cancel_query_id : str ) -> bool :
194+ def cancel_query (cls , cursor : Cursor , query : Query , cancel_query_id : str ) -> bool :
182195 """
183196 Cancel query in the underlying database.
184197
@@ -188,11 +201,12 @@ def cancel_query(cls, cursor: Any, query: Query, cancel_query_id: str) -> bool:
188201 :return: True if query cancelled successfully, False otherwise
189202 """
190203 try :
204+ # Can't use cursor.cancel() because
205+ # cursor is new object created in sql_lab.cancel_query
191206 cursor .execute (
192207 f"CALL system.runtime.kill_query(query_id => '{ cancel_query_id } ',"
193208 "message => 'Query cancelled by Superset')"
194209 )
195- cursor .fetchall () # needed to trigger the call
196210 except Exception : # pylint: disable=broad-except
197211 return False
198212
0 commit comments