11
11
from . import dbapi as trino_dbapi
12
12
from . import error
13
13
from . import result
14
- from . import types
15
14
16
15
17
16
class TrinoExecutionContext (DefaultExecutionContext ):
@@ -89,13 +88,13 @@ def create_connect_args(self, url: URL) -> Tuple[List[Any], Dict[str, Any]]:
89
88
return args , kwargs
90
89
91
90
def get_columns (self , connection : Connection ,
92
- table_name : str , schema : str = None , ** kw ) -> List [types . ColumnInfo ]:
91
+ table_name : str , schema : str = None , ** kw ) -> List [Dict [ str , Any ] ]:
93
92
full_table = self ._get_full_table (table_name , schema )
94
93
try :
95
94
rows = self ._get_table_columns (connection , full_table )
96
95
columns = []
97
96
for row in rows :
98
- columns .append (types . ColumnInfo (
97
+ columns .append (dict (
99
98
name = row .Column ,
100
99
type = compiler .parse_sqltype (row .Type , row .Column ),
101
100
nullable = getattr (row , 'Null' , True ),
@@ -108,18 +107,18 @@ def get_columns(self, connection: Connection,
108
107
raise
109
108
110
109
def get_pk_constraint (self , connection : Connection ,
111
- table_name : str , schema : str = None , ** kw ) -> types . PrimaryKeyInfo :
110
+ table_name : str , schema : str = None , ** kw ) -> Dict [ str , Any ] :
112
111
"""Trino has no support for primary keys. Returns a dummy"""
113
- return types . PrimaryKeyInfo (name = None , constrained_columns = [])
112
+ return dict (name = None , constrained_columns = [])
114
113
115
114
get_primary_keys = get_pk_constraint
116
115
117
116
def get_foreign_keys (self , connection : Connection ,
118
- table_name : str , schema : str = None , ** kw ) -> List [types . ForeignKeyInfo ]:
117
+ table_name : str , schema : str = None , ** kw ) -> List [Dict [ str , Any ] ]:
119
118
"""Trino has no support for foreign keys. Returns an empty list."""
120
119
return []
121
120
122
- def get_schema_names (self , connection : Connection , ** kw ):
121
+ def get_schema_names (self , connection : Connection , ** kw ) -> List [ str ] :
123
122
query = "SHOW SCHEMAS"
124
123
res = connection .execute (sql .text (query ))
125
124
return [row .Schema for row in res ]
@@ -151,7 +150,7 @@ def get_temp_view_names(self, connection: Connection, schema: str = None, **kw)
151
150
"""Trino has no support for temporary views. Returns an empty list."""
152
151
return []
153
152
154
- def get_view_definition (self , connection : Connection , view_name : str , schema : str = None , ** kw ):
153
+ def get_view_definition (self , connection : Connection , view_name : str , schema : str = None , ** kw ) -> str :
155
154
full_view = self ._get_full_table (view_name , schema )
156
155
query = f"SHOW CREATE VIEW { full_view } "
157
156
try :
@@ -163,16 +162,16 @@ def get_view_definition(self, connection: Connection, view_name: str, schema: st
163
162
raise
164
163
165
164
def get_indexes (self , connection : Connection ,
166
- table_name : str , schema : str = None , ** kw ) -> List [types . IndexInfo ]:
165
+ table_name : str , schema : str = None , ** kw ) -> List [Dict [ str , Any ] ]:
167
166
pass
168
167
169
168
def get_unique_constraints (self , connection : Connection ,
170
- table_name : str , schema : str = None , ** kw ) -> List [types . UniqueConstraintInfo ]:
169
+ table_name : str , schema : str = None , ** kw ) -> List [Dict [ str , Any ] ]:
171
170
"""Trino has no support for unique constraints. Returns an empty list."""
172
171
return []
173
172
174
173
def get_check_constraints (self , connection : Connection ,
175
- table_name : str , schema : str = None , ** kw ) -> List [types . CheckConstraintInfo ]:
174
+ table_name : str , schema : str = None , ** kw ) -> List [Dict [ str , Any ] ]:
176
175
"""Trino has no support for check constraints. Returns an empty list."""
177
176
return []
178
177
@@ -209,7 +208,7 @@ def has_sequence(self, connection: Connection,
209
208
"""Trino has no support for sequence. Returns False indicate that given sequence does not exists."""
210
209
return False
211
210
212
- def _get_server_version_info (self , connection : Connection ):
211
+ def _get_server_version_info (self , connection : Connection ) -> Tuple [ int , ...] :
213
212
query = dedent ("""
214
213
SELECT *
215
214
FROM system.runtime.nodes
@@ -219,7 +218,7 @@ def _get_server_version_info(self, connection: Connection):
219
218
version = int (res .node_version )
220
219
return tuple ([version ])
221
220
222
- def _get_default_schema_name (self , connection : Connection ):
221
+ def _get_default_schema_name (self , connection : Connection ) -> Optional [ str ] :
223
222
dbapi_connection : trino_dbapi .Connection = connection .connection
224
223
return dbapi_connection .schema
225
224
@@ -244,7 +243,7 @@ def do_commit_twophase(self, connection: Connection, xid,
244
243
def do_recover_twophase (self , connection : Connection ) -> None :
245
244
pass
246
245
247
- def set_isolation_level (self , dbapi_conn : trino_dbapi .Connection , level ):
246
+ def set_isolation_level (self , dbapi_conn : trino_dbapi .Connection , level ) -> None :
248
247
dbapi_conn ._isolation_level = getattr (trino_dbapi .IsolationLevel , level )
249
248
250
249
def get_isolation_level (self , dbapi_conn : trino_dbapi .Connection ) -> str :
@@ -260,7 +259,7 @@ def _get_table_columns(connection: Connection, full_table: str):
260
259
stmt = sql .text (f'SHOW COLUMNS FROM { full_table } ' )
261
260
return connection .execute (stmt )
262
261
263
- def _get_full_table (self , table_name : str , schema : str = None , quote : bool = True ):
262
+ def _get_full_table (self , table_name : str , schema : str = None , quote : bool = True ) -> str :
264
263
table_part = self .identifier_preparer .quote_identifier (table_name ) if quote else table_name
265
264
if schema :
266
265
schema_part = self .identifier_preparer .quote_identifier (schema ) if quote else schema
0 commit comments