Skip to content

Commit

Permalink
feat(clickhouse): implement covariance and correlation
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed Jun 16, 2022
1 parent d9faa4f commit a37c155
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 11 additions & 0 deletions ibis/backends/clickhouse/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ def formatter(translator, expr):
return formatter


def _corr(translator, expr):
op = expr.op()
if op.how == "pop":
raise ValueError(
"ClickHouse only implements `sample` correlation coefficient"
)
return _aggregate(translator, "corr", op.left, op.right, where=op.where)


def _call(translator, func, *args):
args_ = ', '.join(map(translator.translate, args))
return f'{func!s}({args_!s})'
Expand Down Expand Up @@ -714,6 +723,8 @@ def _struct_field(translator, expr):
ops.ArrayCollect: _agg('groupArray'),
ops.StandardDev: _agg_variance_like('stddev'),
ops.Variance: _agg_variance_like('var'),
ops.Covariance: _agg_variance_like('covar'),
ops.Correlation: _corr,
ops.GroupConcat: _group_concat,
ops.Count: _agg('count'),
ops.CountDistinct: _agg('uniq'),
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/tests/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def test_aggregate_grouped(
marks=[
pytest.mark.notimpl(
[
"clickhouse",
"dask",
"duckdb",
"impala",
Expand Down

0 comments on commit a37c155

Please sign in to comment.