Skip to content

Commit 264ea95

Browse files
committed
Fix spurious warnings and bogus index when reflecting Iceberg tables
1 parent 24cc388 commit 264ea95

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

tests/integration/test_sqlalchemy_integration.py

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def trino_connection(run_trino, request):
4242
sqlalchemy_version() < "1.4",
4343
reason="columns argument to select() must be a Python list or other iterable"
4444
)
45+
@pytest.mark.skipif(trino_version() == 351, reason="connector name is not available in older Trino versions")
4546
@pytest.mark.parametrize('trino_connection', ['tpch'], indirect=True)
4647
def test_select_query(trino_connection):
4748
_, conn = trino_connection
@@ -71,6 +72,7 @@ def assert_column(table, column_name, column_type):
7172
sqlalchemy_version() < "1.4",
7273
reason="columns argument to select() must be a Python list or other iterable"
7374
)
75+
@pytest.mark.skipif(trino_version() == 351, reason="connector name is not available in older Trino versions")
7476
@pytest.mark.parametrize('trino_connection', ['system'], indirect=True)
7577
def test_select_specific_columns(trino_connection):
7678
_, conn = trino_connection
@@ -240,6 +242,7 @@ def test_insert_multiple_statements(trino_connection):
240242
sqlalchemy_version() < "1.4",
241243
reason="columns argument to select() must be a Python list or other iterable"
242244
)
245+
@pytest.mark.skipif(trino_version() == 351, reason="connector name is not available in older Trino versions")
243246
@pytest.mark.parametrize('trino_connection', ['tpch'], indirect=True)
244247
def test_operators(trino_connection):
245248
_, conn = trino_connection
@@ -260,6 +263,7 @@ def test_operators(trino_connection):
260263
sqlalchemy_version() < "1.4",
261264
reason="columns argument to select() must be a Python list or other iterable"
262265
)
266+
@pytest.mark.skipif(trino_version() == 351, reason="connector name is not available in older Trino versions")
263267
@pytest.mark.parametrize('trino_connection', ['tpch'], indirect=True)
264268
def test_conjunctions(trino_connection):
265269
_, conn = trino_connection
@@ -300,6 +304,7 @@ def test_textual_sql(trino_connection):
300304
sqlalchemy_version() < "1.4",
301305
reason="columns argument to select() must be a Python list or other iterable"
302306
)
307+
@pytest.mark.skipif(trino_version() == 351, reason="connector name is not available in older Trino versions")
303308
@pytest.mark.parametrize('trino_connection', ['tpch'], indirect=True)
304309
def test_alias(trino_connection):
305310
_, conn = trino_connection
@@ -323,6 +328,7 @@ def test_alias(trino_connection):
323328
sqlalchemy_version() < "1.4",
324329
reason="columns argument to select() must be a Python list or other iterable"
325330
)
331+
@pytest.mark.skipif(trino_version() == 351, reason="connector name is not available in older Trino versions")
326332
@pytest.mark.parametrize('trino_connection', ['tpch'], indirect=True)
327333
def test_subquery(trino_connection):
328334
_, conn = trino_connection
@@ -341,6 +347,7 @@ def test_subquery(trino_connection):
341347
sqlalchemy_version() < "1.4",
342348
reason="columns argument to select() must be a Python list or other iterable"
343349
)
350+
@pytest.mark.skipif(trino_version() == 351, reason="connector name is not available in older Trino versions")
344351
@pytest.mark.parametrize('trino_connection', ['tpch'], indirect=True)
345352
def test_joins(trino_connection):
346353
_, conn = trino_connection
@@ -360,6 +367,7 @@ def test_joins(trino_connection):
360367
sqlalchemy_version() < "1.4",
361368
reason="columns argument to select() must be a Python list or other iterable"
362369
)
370+
@pytest.mark.skipif(trino_version() == 351, reason="connector name is not available in older Trino versions")
363371
@pytest.mark.parametrize('trino_connection', ['tpch'], indirect=True)
364372
def test_cte(trino_connection):
365373
_, conn = trino_connection

trino/sqlalchemy/dialect.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ def _get_partitions(
229229
partition_names = [desc[0] for desc in res.cursor.description]
230230
return partition_names
231231

232+
def _get_connector_name(self, connection: Connection, catalog_name: str):
233+
query = dedent(
234+
"""
235+
SELECT
236+
"connector_name"
237+
FROM "system"."metadata"."catalogs"
238+
WHERE "catalog_name" = :catalog_name
239+
"""
240+
).strip()
241+
res = connection.execute(sql.text(query), {"catalog_name": catalog_name})
242+
return res.scalar()
243+
232244
def get_pk_constraint(self, connection: Connection, table_name: str, schema: str = None, **kw) -> Dict[str, Any]:
233245
"""Trino has no support for primary keys. Returns a dummy"""
234246
return dict(name=None, constrained_columns=[])
@@ -322,11 +334,20 @@ def get_indexes(self, connection: Connection, table_name: str, schema: str = Non
322334
if not self.has_table(connection, table_name, schema):
323335
raise exc.NoSuchTableError(f"schema={schema}, table={table_name}")
324336

337+
catalog_name = self._get_default_catalog_name(connection)
338+
if catalog_name is None:
339+
raise exc.NoSuchTableError("catalog is required in connection")
340+
connector_name = self._get_connector_name(connection, catalog_name)
341+
if connector_name is None:
342+
raise exc.NoSuchTableError("connector name is required")
343+
if connector_name != "hive":
344+
return []
345+
325346
partitioned_columns = None
326347
try:
327348
partitioned_columns = self._get_partitions(connection, f"{table_name}", schema)
328349
except Exception as e:
329-
# e.g. it's not a Hive table or an unpartitioned Hive table
350+
# e.g. it's an unpartitioned Hive table
330351
logger.debug("Couldn't fetch partition columns. schema: %s, table: %s, error: %s", schema, table_name, e)
331352
if not partitioned_columns:
332353
return []

0 commit comments

Comments
 (0)