Skip to content

Commit

Permalink
feat(sqlalchemy): implement bitwise operator translation
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed Sep 5, 2022
1 parent 7fc5073 commit bd9f64c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ibis/backends/base/sql/alchemy/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
}


Expand Down

0 comments on commit bd9f64c

Please sign in to comment.