Skip to content

Commit

Permalink
feat(clickhouse): implement trig and math functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed May 19, 2022
1 parent 16803e1 commit c56440a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ibis/backends/clickhouse/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ def _string_right(translator, expr):
return f"substring({arg}, -({nchars}))"


def _cotangent(translator, expr):
op = expr.op()
arg = translator.translate(op.arg)
return f"cos({arg}) / sin({arg})"


# TODO: clickhouse uses different string functions
# for ascii and utf-8 encodings,

Expand Down Expand Up @@ -630,6 +636,16 @@ def _string_right(translator, expr):
ops.Ln: _unary('log'),
ops.Log2: _unary('log2'),
ops.Log10: _unary('log10'),
ops.Acos: _unary("acos"),
ops.Asin: _unary("asin"),
ops.Atan: _unary("atan"),
ops.Atan2: _fixed_arity("atan2", 2),
ops.Cos: _unary("cos"),
ops.Cot: _cotangent,
ops.Sin: _unary("sin"),
ops.Tan: _unary("tan"),
ops.Pi: _fixed_arity("pi", 0),
ops.E: _fixed_arity("e", 0),
# Unary aggregates
ops.CMSMedian: _agg('median'),
# TODO: there is also a `uniq` function which is the
Expand Down

0 comments on commit c56440a

Please sign in to comment.