|
17 | 17 | from sqlalchemy.engine.default import DefaultDialect, DefaultExecutionContext
|
18 | 18 | from sqlalchemy.engine.url import URL
|
19 | 19 |
|
20 |
| -from trino import dbapi as trino_dbapi |
| 20 | +from trino import dbapi as trino_dbapi, logging |
21 | 21 | from trino.auth import BasicAuthentication
|
22 | 22 | from trino.dbapi import Cursor
|
| 23 | +from trino.exceptions import TrinoUserError |
23 | 24 | from trino.sqlalchemy import compiler, datatype, error
|
24 | 25 |
|
| 26 | +logger = logging.get_logger(__name__) |
| 27 | + |
25 | 28 |
|
26 | 29 | class TrinoDialect(DefaultDialect):
|
27 | 30 | name = "trino"
|
@@ -266,11 +269,15 @@ def has_sequence(self, connection: Connection, sequence_name: str, schema: str =
|
266 | 269 | """Trino has no support for sequence. Returns False indicate that given sequence does not exists."""
|
267 | 270 | return False
|
268 | 271 |
|
269 |
| - def _get_server_version_info(self, connection: Connection) -> Tuple[int, ...]: |
| 272 | + def _get_server_version_info(self, connection: Connection) -> Any: |
270 | 273 | query = "SELECT version()"
|
271 |
| - res = connection.execute(sql.text(query)) |
272 |
| - version = res.scalar() |
273 |
| - return tuple([version]) |
| 274 | + try: |
| 275 | + res = connection.execute(sql.text(query)) |
| 276 | + version = res.scalar() |
| 277 | + return tuple([version]) |
| 278 | + except TrinoUserError as e: |
| 279 | + logger.debug(f"Failed to get server version: {e.message}") |
| 280 | + return None |
274 | 281 |
|
275 | 282 | def _get_default_schema_name(self, connection: Connection) -> Optional[str]:
|
276 | 283 | dbapi_connection: trino_dbapi.Connection = connection.connection
|
|
0 commit comments