@@ -204,6 +204,22 @@ def _get_columns(self, connection: Connection, table_name: str, schema: str = No
204
204
columns .append (column )
205
205
return columns
206
206
207
+ def _get_partitions (
208
+ self ,
209
+ connection : Connection ,
210
+ table_name : str ,
211
+ schema : str = None
212
+ ) -> List [Dict [str , List [Any ]]]:
213
+ schema = schema or self ._get_default_schema_name (connection )
214
+ query = dedent (
215
+ f"""
216
+ SELECT * FROM { schema } ."{ table_name } $partitions"
217
+ """
218
+ ).strip ()
219
+ res = connection .execute (sql .text (query ))
220
+ partition_names = [desc [0 ] for desc in res .cursor .description ]
221
+ return partition_names
222
+
207
223
def get_pk_constraint (self , connection : Connection , table_name : str , schema : str = None , ** kw ) -> Dict [str , Any ]:
208
224
"""Trino has no support for primary keys. Returns a dummy"""
209
225
return dict (name = None , constrained_columns = [])
@@ -299,15 +315,15 @@ def get_indexes(self, connection: Connection, table_name: str, schema: str = Non
299
315
300
316
partitioned_columns = None
301
317
try :
302
- partitioned_columns = self ._get_columns (connection , f"{ table_name } $partitions " , schema , ** kw )
318
+ partitioned_columns = self ._get_partitions (connection , f"{ table_name } " , schema )
303
319
except Exception as e :
304
320
# e.g. it's not a Hive table or an unpartitioned Hive table
305
321
logger .debug ("Couldn't fetch partition columns. schema: %s, table: %s, error: %s" , schema , table_name , e )
306
322
if not partitioned_columns :
307
323
return []
308
324
partition_index = dict (
309
325
name = "partition" ,
310
- column_names = [ col [ "name" ] for col in partitioned_columns ] ,
326
+ column_names = partitioned_columns ,
311
327
unique = False
312
328
)
313
329
return [partition_index ]
0 commit comments