From 58c42f99cc9c99aa3bed88f6d0840fa4be8755b5 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Thu, 1 Sep 2022 07:14:44 -0400 Subject: [PATCH] feat(sqlite): implement bitwise xor and bitwise not --- ibis/backends/sqlite/registry.py | 3 +++ ibis/backends/sqlite/udf.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/ibis/backends/sqlite/registry.py b/ibis/backends/sqlite/registry.py index d9038eed4809..b48d4304a2c7 100644 --- a/ibis/backends/sqlite/registry.py +++ b/ibis/backends/sqlite/registry.py @@ -359,5 +359,8 @@ def _time_from_hms(t, expr): ops.Degrees: unary(sa.func._ibis_sqlite_degrees), ops.Radians: unary(sa.func._ibis_sqlite_radians), ops.Clip: _clip(min_func=sa.func.min, max_func=sa.func.max), + # sqlite doesn't implement a native xor operator + ops.BitwiseXor: fixed_arity(sa.func._ibis_sqlite_xor, 2), + ops.BitwiseNot: unary(sa.func._ibis_sqlite_inv), } ) diff --git a/ibis/backends/sqlite/udf.py b/ibis/backends/sqlite/udf.py index 850afb940c37..5a74365e037b 100644 --- a/ibis/backends/sqlite/udf.py +++ b/ibis/backends/sqlite/udf.py @@ -291,6 +291,16 @@ def _ibis_sqlite_radians(x): return None if x is None else math.radians(x) +@udf +def _ibis_sqlite_xor(x, y): + return None if x is None or y is None else x ^ y + + +@udf +def _ibis_sqlite_inv(x): + return None if x is None else ~x + + class _ibis_sqlite_var: def __init__(self, offset): self.mean = 0.0