Skip to content

Commit e4e582a

Browse files
authored
perf(athena): use get_table_metadata in get_schema (#11574)
1 parent 40b73e7 commit e4e582a

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

ibis/backends/athena/__init__.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,26 +263,25 @@ def get_schema(
263263
sch.Schema
264264
Ibis schema
265265
"""
266+
compiler = self.compiler
266267
table = sg.table(
267-
table_name, db=database, catalog=catalog, quoted=self.compiler.quoted
268+
table_name, db=database, catalog=catalog, quoted=compiler.quoted
268269
)
269270
with self.con.cursor() as cur:
270-
tables = cur.list_table_metadata(
271-
catalog_name=catalog, schema_name=database, expression=table_name
272-
)
273-
274-
if not tables:
275-
raise com.TableNotFound(table.sql(self.dialect))
276-
277-
(table,) = tables
271+
try:
272+
table_meta = cur.get_table_metadata(
273+
catalog_name=catalog, schema_name=database, table_name=table_name
274+
)
275+
except pyathena.OperationalError as e:
276+
raise com.TableNotFound(table.sql(self.dialect)) from e
278277

279-
type_mapper = self.compiler.type_mapper
278+
type_mapper = compiler.type_mapper
280279
fields = {
281280
metacol.name: type_mapper.from_string(metacol.type)
282-
for metacol in table.columns
281+
for metacol in table_meta.columns
283282
}
284283

285-
for key in table.partition_keys:
284+
for key in table_meta.partition_keys:
286285
fields[key.name] = type_mapper.from_string(key.type)
287286

288287
return sch.Schema(fields)

0 commit comments

Comments
 (0)