Skip to content

Commit 6642b39

Browse files
committed
fix(pyspark): avoid potentially different field names produced by SQL by using python-native APIs
1 parent 83a68d5 commit 6642b39

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

ibis/backends/pyspark/__init__.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,11 @@ def version(self):
229229

230230
@property
231231
def current_database(self) -> str:
232-
[(db,)] = self._session.sql("SELECT CURRENT_DATABASE()").collect()
233-
return db
232+
return self._session.catalog.currentDatabase()
234233

235234
@property
236235
def current_catalog(self) -> str:
237-
[(catalog,)] = self._session.sql("SELECT CURRENT_CATALOG()").collect()
238-
return catalog
236+
return self._session.catalog.currentCatalog()
239237

240238
@contextlib.contextmanager
241239
def _active_catalog_database(self, catalog: str | None, db: str | None):
@@ -349,7 +347,7 @@ def _active_catalog(self, name: str | None):
349347
catalog_api.setCurrentDatabase(prev_database)
350348

351349
def list_catalogs(self, *, like: str | None = None) -> list[str]:
352-
catalogs = [res.catalog for res in self._session.sql("SHOW CATALOGS").collect()]
350+
catalogs = [cat.name for cat in self._session.catalog.listCatalogs()]
353351
return self._filter_with_like(catalogs, like)
354352

355353
def list_databases(
@@ -378,12 +376,11 @@ def list_tables(
378376
"""
379377
table_loc = self._to_sqlglot_table(database)
380378
catalog, db = self._to_catalog_db_tuple(table_loc)
379+
if db is None:
380+
db = self.current_database
381381
with self._active_catalog(catalog):
382382
tables = [
383-
row.tableName
384-
for row in self._session.sql(
385-
f"SHOW TABLES IN {db or self.current_database}"
386-
).collect()
383+
table.name for table in self._session.catalog.listTables(dbName=db)
387384
]
388385
return self._filter_with_like(tables, like)
389386

0 commit comments

Comments
 (0)