@@ -204,6 +204,22 @@ def _get_columns(self, connection: Connection, table_name: str, schema: str = No
204204 columns .append (column )
205205 return columns
206206
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+
207223 def get_pk_constraint (self , connection : Connection , table_name : str , schema : str = None , ** kw ) -> Dict [str , Any ]:
208224 """Trino has no support for primary keys. Returns a dummy"""
209225 return dict (name = None , constrained_columns = [])
@@ -299,15 +315,15 @@ def get_indexes(self, connection: Connection, table_name: str, schema: str = Non
299315
300316 partitioned_columns = None
301317 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 )
303319 except Exception as e :
304320 # e.g. it's not a Hive table or an unpartitioned Hive table
305321 logger .debug ("Couldn't fetch partition columns. schema: %s, table: %s, error: %s" , schema , table_name , e )
306322 if not partitioned_columns :
307323 return []
308324 partition_index = dict (
309325 name = "partition" ,
310- column_names = [ col [ "name" ] for col in partitioned_columns ] ,
326+ column_names = partitioned_columns ,
311327 unique = False
312328 )
313329 return [partition_index ]
0 commit comments