diff --git a/ibis/backends/base/sql/alchemy/registry.py b/ibis/backends/base/sql/alchemy/registry.py index ddde76fa8772..ca497bf1967c 100644 --- a/ibis/backends/base/sql/alchemy/registry.py +++ b/ibis/backends/base/sql/alchemy/registry.py @@ -520,6 +520,25 @@ def translate(t, expr): return translate +def _bitwise_op(operator): + def translate(t, expr): + op = expr.op() + left = t.translate(op.left) + right = t.translate(op.right) + return left.op(operator)(right) + + return translate + + +def _bitwise_not(t, expr): + op = expr.op() + arg = t.translate(op.arg) + return sa.sql.elements.UnaryExpression( + arg, + operator=sa.sql.operators.custom_op("~"), + ) + + sqlalchemy_operation_registry: Dict[Any, Any] = { ops.Alias: _alias, ops.And: fixed_arity(operator.and_, 2), @@ -645,6 +664,12 @@ def translate(t, expr): ), 3, ), + ops.BitwiseAnd: _bitwise_op("&"), + ops.BitwiseOr: _bitwise_op("|"), + ops.BitwiseXor: _bitwise_op("^"), + ops.BitwiseLeftShift: _bitwise_op("<<"), + ops.BitwiseRightShift: _bitwise_op(">>"), + ops.BitwiseNot: _bitwise_not, }