Skip to content

Commit

Permalink
feat(clickhouse): support caching tables with the .cache() method
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed Aug 13, 2023
1 parent 5f88102 commit 621bdac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
21 changes: 15 additions & 6 deletions ibis/backends/clickhouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
14 changes: 7 additions & 7 deletions ibis/backends/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 621bdac

Please sign in to comment.