Skip to content

Commit 08900c3

Browse files
committed
fix(clickhouse): fix listing tables from databases with no tables
1 parent 8a747fb commit 08900c3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

ibis/backends/clickhouse/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,16 @@ def current_database(self):
109109

110110
def list_databases(self, like=None):
111111
data, _ = self.raw_sql('SELECT name FROM system.databases')
112+
# in theory this should never be empty
113+
if not data: # pragma: no cover
114+
return []
112115
databases = list(data[0])
113116
return self._filter_with_like(databases, like)
114117

115118
def list_tables(self, like=None, database=None):
116119
data, _ = self.raw_sql('SHOW TABLES')
120+
if not data:
121+
return []
117122
databases = list(data[0])
118123
return self._filter_with_like(databases, like)
119124

ibis/backends/clickhouse/tests/test_client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,15 @@ def test_insert_with_more_columns(temporary_alltypes, df):
173173
def test_get_schema_using_query(con, query, expected_schema):
174174
result = con._get_schema_using_query(query)
175175
assert result == expected_schema
176+
177+
178+
def test_list_tables_empty(con, worker_id):
179+
dbname = f"tmpdb_{worker_id}"
180+
db = con.current_database
181+
con.raw_sql(f"CREATE DATABASE IF NOT EXISTS {dbname}")
182+
try:
183+
con.raw_sql(f"USE {dbname}")
184+
assert not con.list_tables()
185+
finally:
186+
con.raw_sql(f"USE {db}")
187+
con.raw_sql(f"DROP DATABASE IF EXISTS {dbname}")

0 commit comments

Comments
 (0)