Repository: ibis-project/ibis

Issue:
bug(ClickHouse): incorrect implementation of 'list_tables' method
### What happened?

Incorrect implementation of 'list_tables' method in ClickHouse backend. How can I push my fix?
Correct version:

    def list_tables(self, like=None, database=None):
        if database is not None:
            data, _ = self.raw_sql("SELECT name FROM system.tables WHERE database = '{}'".format(database))
        elif self.con.connection.database is not None:
            data, _ = self.raw_sql(
                "SELECT name FROM system.tables WHERE database = '{}'".format(self.con.connection.database))
        else:
            data, _ = self.raw_sql("SELECT name FROM system.tables")
        if not data:
            return []
        tables = list(data[0])
        return self._filter_with_like(tables, like)



### What version of ibis are you using?

3.2.0

### What backend(s) are you using, if any?

ClickHouse

### Relevant log output

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct


Discussion:
In order to push a fix you will want to make a [Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request). The link to the github docs should help if you want to try it out!
![image](https://user-images.githubusercontent.com/117784139/203879747-0a81a876-9fc6-490c-b124-b4dc620d3f5d.png)

Should I request permission to push to remote? 
@kosavinads Please take a look at the link posted by @Ender-4029.
Make sure to include the rationale in your PR description as well as a test that fails without your changes and succeeds with your changes. We need a minimal record of _why_ the current implementation is wrong to prevent regressions.

Resolving patch:
diff --git a/ibis/backends/clickhouse/__init__.py b/ibis/backends/clickhouse/__init__.py
--- a/ibis/backends/clickhouse/__init__.py
+++ b/ibis/backends/clickhouse/__init__.py
@@ -134,11 +134,15 @@ def list_databases(self, like=None):
         return self._filter_with_like(databases, like)
 
     def list_tables(self, like=None, database=None):
-        data, _ = self.raw_sql('SHOW TABLES')
+        if database is not None:
+            query = f"SHOW TABLES FROM `{database}`"
+        else:
+            query = "SHOW TABLES"
+        data, _ = self.raw_sql(query)
         if not data:
             return []
-        databases = list(data[0])
-        return self._filter_with_like(databases, like)
+        tables = list(data[0])
+        return self._filter_with_like(tables, like)
 
     def raw_sql(
         self,


Test patch:
diff --git a/ibis/backends/clickhouse/tests/test_client.py b/ibis/backends/clickhouse/tests/test_client.py
--- a/ibis/backends/clickhouse/tests/test_client.py
+++ b/ibis/backends/clickhouse/tests/test_client.py
@@ -173,13 +173,16 @@ def test_get_schema_using_query(con, query, expected_schema):
     assert result == expected_schema
 
 
-def test_list_tables_empty(con, worker_id):
+def test_list_tables_database(con):
+    tables = con.list_tables()
+    tables2 = con.list_tables(database=con.current_database)
+    assert tables == tables2
+
+
+def test_list_tables_empty_database(con, worker_id):
     dbname = f"tmpdb_{worker_id}"
-    db = con.current_database
     con.raw_sql(f"CREATE DATABASE IF NOT EXISTS {dbname}")
     try:
-        con.raw_sql(f"USE {dbname}")
-        assert not con.list_tables()
+        assert not con.list_tables(database=dbname)
     finally:
-        con.raw_sql(f"USE {db}")
         con.raw_sql(f"DROP DATABASE IF EXISTS {dbname}")