Skip to content

Commit

Permalink
fix(clickhouse): handle empty IN and NOT IN expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed May 15, 2022
1 parent 27ae68a commit 2c892eb
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions ibis/backends/clickhouse/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,30 @@ def formatter(translator, expr):
return formatter


def _in(translator, expr):
op = expr.op()

left, right = op.args
if isinstance(right, ir.ListExpr) and not right:
return "FALSE"

left_ = _parenthesize(translator, left)
right_ = _parenthesize(translator, right)
return f"{left_} IN {right_}"


def _not_in(translator, expr):
op = expr.op()

left, right = op.args
if isinstance(right, ir.ListExpr) and not right:
return "TRUE"

left_ = _parenthesize(translator, left)
right_ = _parenthesize(translator, right)
return f"{left_} NOT IN {right_}"


def _call(translator, func, *args):
args_ = ', '.join(map(translator.translate, args))
return f'{func!s}({args_!s})'
Expand Down Expand Up @@ -720,8 +744,8 @@ def _string_right(translator, expr):
ops.Least: _varargs('least'),
ops.Where: _fixed_arity('if', 3),
ops.Between: _between,
ops.Contains: _binary_infix_op('IN'),
ops.NotContains: _binary_infix_op('NOT IN'),
ops.Contains: _in,
ops.NotContains: _not_in,
ops.SimpleCase: _simple_case,
ops.SearchedCase: _searched_case,
ops.TableColumn: _table_column,
Expand Down

0 comments on commit 2c892eb

Please sign in to comment.