mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat(trino): support early cancellation of queries (#22498)
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# pylint: disable=too-many-lines
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
@@ -478,7 +481,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
@classmethod
|
||||
def get_engine(
|
||||
cls,
|
||||
database: "Database",
|
||||
database: Database,
|
||||
schema: Optional[str] = None,
|
||||
source: Optional[utils.QuerySource] = None,
|
||||
) -> ContextManager[Engine]:
|
||||
@@ -733,7 +736,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
@classmethod
|
||||
def extra_table_metadata( # pylint: disable=unused-argument
|
||||
cls,
|
||||
database: "Database",
|
||||
database: Database,
|
||||
table_name: str,
|
||||
schema_name: Optional[str],
|
||||
) -> Dict[str, Any]:
|
||||
@@ -750,7 +753,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
|
||||
@classmethod
|
||||
def apply_limit_to_sql(
|
||||
cls, sql: str, limit: int, database: "Database", force: bool = False
|
||||
cls, sql: str, limit: int, database: Database, force: bool = False
|
||||
) -> str:
|
||||
"""
|
||||
Alters the SQL statement to apply a LIMIT clause
|
||||
@@ -892,7 +895,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
@classmethod
|
||||
def df_to_sql(
|
||||
cls,
|
||||
database: "Database",
|
||||
database: Database,
|
||||
table: Table,
|
||||
df: pd.DataFrame,
|
||||
to_sql_kwargs: Dict[str, Any],
|
||||
@@ -939,7 +942,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def handle_cursor(cls, cursor: Any, query: "Query", session: Session) -> None:
|
||||
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
|
||||
@@ -1031,7 +1034,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
@classmethod
|
||||
def get_table_names( # pylint: disable=unused-argument
|
||||
cls,
|
||||
database: "Database",
|
||||
database: Database,
|
||||
inspector: Inspector,
|
||||
schema: Optional[str],
|
||||
) -> Set[str]:
|
||||
@@ -1059,7 +1062,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
@classmethod
|
||||
def get_view_names( # pylint: disable=unused-argument
|
||||
cls,
|
||||
database: "Database",
|
||||
database: Database,
|
||||
inspector: Inspector,
|
||||
schema: Optional[str],
|
||||
) -> Set[str]:
|
||||
@@ -1125,7 +1128,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
@classmethod
|
||||
def get_metrics( # pylint: disable=unused-argument
|
||||
cls,
|
||||
database: "Database",
|
||||
database: Database,
|
||||
inspector: Inspector,
|
||||
table_name: str,
|
||||
schema: Optional[str],
|
||||
@@ -1147,7 +1150,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
cls,
|
||||
table_name: str,
|
||||
schema: Optional[str],
|
||||
database: "Database",
|
||||
database: Database,
|
||||
query: Select,
|
||||
columns: Optional[List[Dict[str, str]]] = None,
|
||||
) -> Optional[Select]:
|
||||
@@ -1172,7 +1175,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
@classmethod
|
||||
def select_star( # pylint: disable=too-many-arguments,too-many-locals
|
||||
cls,
|
||||
database: "Database",
|
||||
database: Database,
|
||||
table_name: str,
|
||||
engine: Engine,
|
||||
schema: Optional[str] = None,
|
||||
@@ -1251,7 +1254,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
raise Exception("Database does not support cost estimation")
|
||||
|
||||
@classmethod
|
||||
def process_statement(cls, statement: str, database: "Database") -> str:
|
||||
def process_statement(cls, statement: str, database: Database) -> str:
|
||||
"""
|
||||
Process a SQL statement by stripping and mutating it.
|
||||
|
||||
@@ -1275,7 +1278,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
@classmethod
|
||||
def estimate_query_cost(
|
||||
cls,
|
||||
database: "Database",
|
||||
database: Database,
|
||||
schema: str,
|
||||
sql: str,
|
||||
source: Optional[utils.QuerySource] = None,
|
||||
@@ -1471,7 +1474,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
@classmethod
|
||||
def get_function_names( # pylint: disable=unused-argument
|
||||
cls,
|
||||
database: "Database",
|
||||
database: Database,
|
||||
) -> List[str]:
|
||||
"""
|
||||
Get a list of function names that are able to be called on the database.
|
||||
@@ -1496,7 +1499,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
|
||||
@staticmethod
|
||||
def mutate_db_for_connection_test( # pylint: disable=unused-argument
|
||||
database: "Database",
|
||||
database: Database,
|
||||
) -> None:
|
||||
"""
|
||||
Some databases require passing additional parameters for validating database
|
||||
@@ -1508,7 +1511,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_extra_params(database: "Database") -> Dict[str, Any]:
|
||||
def get_extra_params(database: Database) -> Dict[str, Any]:
|
||||
"""
|
||||
Some databases require adding elements to connection parameters,
|
||||
like passing certificates to `extra`. This can be done here.
|
||||
@@ -1527,7 +1530,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
|
||||
@staticmethod
|
||||
def update_params_from_encrypted_extra( # pylint: disable=invalid-name
|
||||
database: "Database", params: Dict[str, Any]
|
||||
database: Database, params: Dict[str, Any]
|
||||
) -> None:
|
||||
"""
|
||||
Some databases require some sensitive information which do not conform to
|
||||
@@ -1589,11 +1592,22 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
)
|
||||
return None
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
@classmethod
|
||||
def prepare_cancel_query(cls, query: Query, session: Session) -> None:
|
||||
"""
|
||||
Some databases may acquire the query cancelation id after the query
|
||||
cancelation request has been received. For those cases, the db engine spec
|
||||
can record the cancelation intent so that the query can either be stopped
|
||||
prior to execution, or canceled once the query id is acquired.
|
||||
"""
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def has_implicit_cancel(cls) -> bool:
|
||||
"""
|
||||
Return True if the live cursor handles the implicit cancelation of the query,
|
||||
False otherise.
|
||||
False otherwise.
|
||||
|
||||
:return: Whether the live cursor implicitly cancels the query
|
||||
:see: handle_cursor
|
||||
@@ -1605,7 +1619,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
def get_cancel_query_id( # pylint: disable=unused-argument
|
||||
cls,
|
||||
cursor: Any,
|
||||
query: "Query",
|
||||
query: Query,
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
Select identifiers from the database engine that uniquely identifies the
|
||||
@@ -1623,7 +1637,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
def cancel_query( # pylint: disable=unused-argument
|
||||
cls,
|
||||
cursor: Any,
|
||||
query: "Query",
|
||||
query: Query,
|
||||
cancel_query_id: str,
|
||||
) -> bool:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user