Skip to content

Commit

Permalink
feat(clickhouse): implement table union
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Mar 18, 2022
1 parent a5b7293 commit e0008d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions ibis/backends/clickhouse/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
TableSetFormatter,
)

from ..base.sql.compiler.query_builder import Union
from .registry import operation_registry


class ClickhouseUnion(Union):
@staticmethod
def keyword(distinct):
return 'UNION DISTINCT' if distinct else 'UNION ALL'


class ClickhouseSelectBuilder(SelectBuilder):
def _convert_group_by(self, exprs):
return exprs
Expand Down Expand Up @@ -116,3 +123,4 @@ class ClickhouseCompiler(Compiler):
table_set_formatter_class = ClickhouseTableSetFormatter
select_builder_class = ClickhouseSelectBuilder
select_class = ClickhouseSelect
union_class = ClickhouseUnion
4 changes: 2 additions & 2 deletions ibis/backends/tests/test_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@pytest.mark.parametrize('distinct', [False, True])
@pytest.mark.notimpl(["clickhouse", "datafusion"])
@pytest.mark.notimpl(["datafusion"])
def test_union(backend, alltypes, df, distinct):
result = alltypes.union(alltypes, distinct=distinct).execute()
expected = df if distinct else pd.concat([df, df], axis=0)
Expand All @@ -29,7 +29,7 @@ def test_union(backend, alltypes, df, distinct):
),
],
)
@pytest.mark.notimpl(["clickhouse", "datafusion"])
@pytest.mark.notimpl(["datafusion"])
def test_union_no_sort(backend, alltypes, df, distinct):
result = alltypes.union(alltypes, distinct=distinct).execute()
expected = df if distinct else pd.concat([df, df], axis=0)
Expand Down

0 comments on commit e0008d7

Please sign in to comment.