Skip to content

Commit

Permalink
feat(clickhouse): support Table.fillna
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist authored and cpcloud committed Oct 16, 2023
1 parent f5e06a6 commit 5633660
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 30 deletions.
3 changes: 3 additions & 0 deletions ibis/backends/clickhouse/compiler/core.py
Expand Up @@ -29,6 +29,7 @@
from ibis.backends.clickhouse.compiler.values import translate_val
from ibis.common.deferred import _
from ibis.expr.analysis import c, find_first_base_table, p, x, y
from ibis.expr.rewrites import rewrite_dropna, rewrite_fillna

if TYPE_CHECKING:
from collections.abc import Mapping
Expand Down Expand Up @@ -122,6 +123,8 @@ def fn(node, _, **kwargs):
| subtract_one_from_one_indexed_functions
| add_one_to_nth_value_input
| nullify_empty_string_results
| rewrite_fillna
| rewrite_dropna
)
# apply translate rules in topological order
node = op.map(fn)[op]
Expand Down
29 changes: 1 addition & 28 deletions ibis/backends/clickhouse/compiler/relations.py
Expand Up @@ -7,7 +7,7 @@

import ibis.common.exceptions as com
import ibis.expr.operations as ops
from ibis.backends.base.sqlglot import FALSE, NULL, STAR
from ibis.backends.base.sqlglot import STAR


@functools.singledispatch
Expand Down Expand Up @@ -200,33 +200,6 @@ def _distinct(op: ops.Distinct, *, table, **_):
return sg.select(STAR).distinct().from_(table)


@translate_rel.register
def _dropna(op: ops.DropNa, *, table, how, subset, **_):
colnames = op.schema.names
alias = table.alias_or_name

if subset is None:
columns = [sg.column(name, table=alias) for name in colnames]
else:
columns = subset

if columns:
func = sg.and_ if how == "any" else sg.or_
predicate = func(*(sg.not_(col.is_(NULL)) for col in columns))
elif how == "all":
predicate = FALSE
else:
predicate = None

if predicate is None:
return table

try:
return table.where(predicate)
except AttributeError:
return sg.select(STAR).from_(table).where(predicate)


@translate_rel.register
def _sql_string_view(op: ops.SQLStringView, query: str, **_: Any):
table = sg.table(op.name)
Expand Down
4 changes: 2 additions & 2 deletions ibis/backends/tests/test_generic.py
Expand Up @@ -425,7 +425,7 @@ def test_table_fillna_invalid(alltypes):
),
],
)
@pytest.mark.notimpl(["datafusion", "clickhouse"])
@pytest.mark.notimpl(["datafusion"])
def test_table_fillna_mapping(backend, alltypes, replacements):
table = alltypes.mutate(
int_col=alltypes.int_col.nullif(1),
Expand All @@ -440,7 +440,7 @@ def test_table_fillna_mapping(backend, alltypes, replacements):
backend.assert_frame_equal(result, expected, check_dtype=False)


@pytest.mark.notimpl(["datafusion", "clickhouse", "druid", "oracle"])
@pytest.mark.notimpl(["datafusion", "druid", "oracle"])
def test_table_fillna_scalar(backend, alltypes):
table = alltypes.mutate(
int_col=alltypes.int_col.nullif(1),
Expand Down

0 comments on commit 5633660

Please sign in to comment.