From 9df2cf2756d9bb189de719a80623064acfe65dea Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Thu, 21 Dec 2023 07:06:40 +0900 Subject: [PATCH] Suppress failure when reading $partitions system table in get_indexes Not all connectors have a `$partitions` table. This caused `get_indexes` to fail when called on a non-Hive (or non-partitioned Hive) table. Since Trino engine doesn't have concept of partitions there's no single way to fetch partition columns. One option is to parse the output of `SHOW CREATE TABLE` to identify them but the logic would differ based on what connector is being used. So we just opt to suppress the failure in case of a non-Hive or non-partitioned Hive table instead. --- trino/sqlalchemy/dialect.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/trino/sqlalchemy/dialect.py b/trino/sqlalchemy/dialect.py index 52da4ac3..edcc372c 100644 --- a/trino/sqlalchemy/dialect.py +++ b/trino/sqlalchemy/dialect.py @@ -297,7 +297,12 @@ def get_indexes(self, connection: Connection, table_name: str, schema: str = Non if not self.has_table(connection, table_name, schema): raise exc.NoSuchTableError(f"schema={schema}, table={table_name}") - partitioned_columns = self._get_columns(connection, f"{table_name}$partitions", schema, **kw) + partitioned_columns = None + try: + partitioned_columns = self._get_columns(connection, f"{table_name}$partitions", schema, **kw) + except Exception as e: + # e.g. it's not a Hive table or an unpartitioned Hive table + logger.debug("Couldn't fetch partition columns. schema: %s, table: %s, error: %s", schema, table_name, e) if not partitioned_columns: return [] partition_index = dict(