diff --git a/ibis/backends/clickhouse/__init__.py b/ibis/backends/clickhouse/__init__.py index 48776e36b2bc..7e4de6405d90 100644 --- a/ibis/backends/clickhouse/__init__.py +++ b/ibis/backends/clickhouse/__init__.py @@ -583,14 +583,17 @@ def create_table( Table The new table """ - if temp: - raise com.IbisError( - "ClickHouse temporary tables are not yet supported due to a bug in `clickhouse_driver`" - ) - tmp = "TEMPORARY " * temp replace = "OR REPLACE " * overwrite - table = self._fully_qualified_name(name, database) + + if temp and overwrite: + raise com.IbisInputError("Cannot specify both temp and overwrite") + + if not temp: + table = self._fully_qualified_name(name, database) + else: + table = name + database = None code = f"CREATE {replace}{tmp}TABLE {table}" if obj is None and schema is None: @@ -658,3 +661,9 @@ def drop_view( if_exists = "IF EXISTS " * force with closing(self.raw_sql(f"DROP VIEW {if_exists}{name}")): pass + + def _load_into_cache(self, name, expr): + self.create_table(name, expr, schema=expr.schema(), temp=True) + + def _clean_up_cached_table(self, op): + self.drop_table(op.name) diff --git a/ibis/backends/tests/test_client.py b/ibis/backends/tests/test_client.py index da2ba40379e1..8b7e535ba6f0 100644 --- a/ibis/backends/tests/test_client.py +++ b/ibis/backends/tests/test_client.py @@ -1140,7 +1140,7 @@ def test_create_table_timestamp(con, temp_table): assert result == schema -@mark.notimpl(["clickhouse", "datafusion", "bigquery", "impala", "trino", "druid"]) +@mark.notimpl(["datafusion", "bigquery", "impala", "trino", "druid"]) @mark.never( ["mssql"], reason="mssql supports support temporary tables through naming conventions", @@ -1157,7 +1157,7 @@ def test_persist_expression_ref_count(con, alltypes): assert con._query_cache.refs[op] == 1 -@mark.notimpl(["clickhouse", "datafusion", "bigquery", "impala", "trino", "druid"]) +@mark.notimpl(["datafusion", "bigquery", "impala", "trino", "druid"]) @mark.never( ["mssql"], reason="mssql supports support temporary tables through naming conventions", @@ -1168,7 +1168,7 @@ def test_persist_expression(alltypes): tm.assert_frame_equal(non_persisted_table.to_pandas(), persisted_table.to_pandas()) -@mark.notimpl(["clickhouse", "datafusion", "bigquery", "impala", "trino", "druid"]) +@mark.notimpl(["datafusion", "bigquery", "impala", "trino", "druid"]) @mark.never( ["mssql"], reason="mssql supports support temporary tables through naming conventions", @@ -1181,7 +1181,7 @@ def test_persist_expression_contextmanager(alltypes): tm.assert_frame_equal(non_cached_table.to_pandas(), cached_table.to_pandas()) -@mark.notimpl(["clickhouse", "datafusion", "bigquery", "impala", "trino", "druid"]) +@mark.notimpl(["datafusion", "bigquery", "impala", "trino", "druid"]) @mark.never( ["mssql"], reason="mssql supports support temporary tables through naming conventions", @@ -1197,7 +1197,7 @@ def test_persist_expression_contextmanager_ref_count(con, alltypes): assert con._query_cache.refs[op] == 0 -@mark.notimpl(["clickhouse", "datafusion", "bigquery", "impala", "trino", "druid"]) +@mark.notimpl(["datafusion", "bigquery", "impala", "trino", "druid"]) @mark.never( ["mssql"], reason="mssql supports support temporary tables through naming conventions", @@ -1230,7 +1230,7 @@ def test_persist_expression_multiple_refs(con, alltypes): assert name2 not in con.list_tables() -@mark.notimpl(["clickhouse", "datafusion", "bigquery", "impala", "trino", "druid"]) +@mark.notimpl(["datafusion", "bigquery", "impala", "trino", "druid"]) @mark.never( ["mssql"], reason="mssql supports support temporary tables through naming conventions", @@ -1244,7 +1244,7 @@ def test_persist_expression_repeated_cache(alltypes): assert not nested_cached_table.to_pandas().empty -@mark.notimpl(["clickhouse", "datafusion", "bigquery", "impala", "trino", "druid"]) +@mark.notimpl(["datafusion", "bigquery", "impala", "trino", "druid"]) @mark.never( ["mssql"], reason="mssql supports support temporary tables through naming conventions",