Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spurious warnings and bogus index when reflecting Iceberg tables #520

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions trino/sqlalchemy/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _get_partitions(
connection: Connection,
table_name: str,
schema: str = None
) -> List[Dict[str, List[Any]]]:
) -> Optional[List[str]]:
schema = schema or self._get_default_schema_name(connection)
query = dedent(
f"""
Expand All @@ -227,6 +227,17 @@ def _get_partitions(
).strip()
res = connection.execute(sql.text(query))
partition_names = [desc[0] for desc in res.cursor.description]
data_types = [desc[1] for desc in res.cursor.description]
# Compare the column names and types to the shape of an Iceberg $partitions table
if (partition_names == ['partition', 'record_count', 'file_count', 'total_size', 'data']
and data_types[0].startswith('row(')
and data_types[1] == 'bigint'
and data_types[2] == 'bigint'
and data_types[3] == 'bigint'
and data_types[4].startswith('row(')):
# This is an Iceberg $partitions table - these match the partition metadata columns
return None
# This is a Hive table - these are the partition names
return partition_names

def get_pk_constraint(self, connection: Connection, table_name: str, schema: str = None, **kw) -> Dict[str, Any]:
Expand Down Expand Up @@ -326,7 +337,7 @@ def get_indexes(self, connection: Connection, table_name: str, schema: str = Non
try:
partitioned_columns = self._get_partitions(connection, f"{table_name}", schema)
except Exception as e:
# e.g. it's not a Hive table or an unpartitioned Hive table
# e.g. it's 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 []
Expand Down
Loading