Skip to content

Commit

Permalink
fix(clickhouse): ensure that truncate works
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed Apr 7, 2023
1 parent 5a54489 commit 1639914
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ibis/backends/clickhouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def drop_database(self, name: str, *, force: bool = False) -> None:

def truncate_table(self, name: str, database: str | None = None) -> None:
ident = self._fully_qualified_name(name, database)
self.raw_sql(f"DELETE FROM {ident}")
self.raw_sql(f"TRUNCATE TABLE {ident}")

def drop_table(
self, name: str, database: str | None = None, force: bool = False
Expand Down
27 changes: 27 additions & 0 deletions ibis/backends/clickhouse/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pandas as pd
import pandas.testing as tm
import pytest
from clickhouse_driver.dbapi import OperationalError
from pytest import param

import ibis
Expand Down Expand Up @@ -260,3 +261,29 @@ def test_create_table_data(con, data, engine):
finally:
con.drop_table(name, force=True, database="tmptables")
assert name not in con.list_tables(database="tmptables")


@pytest.mark.parametrize(
"engine",
[
"File(Native)",
param(
"File(Parquet)",
marks=pytest.mark.xfail(
reason="Parquet file size is 0 bytes", raises=OperationalError
),
),
"Memory",
],
ids=["native", "mem", "parquet"],
)
def test_truncate_table(con, engine):
name = gen_name("clickhouse_create_table_data")
t = con.create_table(name, obj={"a": [1]}, engine=engine, database="tmptables")
try:
assert len(t.execute()) == 1
con.truncate_table(name, database="tmptables")
assert len(t.execute()) == 0
finally:
con.drop_table(name, force=True, database="tmptables")
assert name not in con.list_tables(database="tmptables")

0 comments on commit 1639914

Please sign in to comment.