From 55b69b1a2e55f2b6655a60dd068870947a5b47e3 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Tue, 24 Jan 2023 01:22:39 +0100 Subject: [PATCH] feat(bigquery): implement bitwise operations --- ibis/backends/bigquery/registry.py | 6 ++++++ ibis/backends/tests/test_numeric.py | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ibis/backends/bigquery/registry.py b/ibis/backends/bigquery/registry.py index b19a167299b9..c1b08b018eb5 100644 --- a/ibis/backends/bigquery/registry.py +++ b/ibis/backends/bigquery/registry.py @@ -587,6 +587,12 @@ def _nth_value(t, op): ops.Clip: _clip, ops.Degrees: lambda t, op: f"(180 * {t.translate(op.arg)} / ACOS(-1))", ops.Radians: lambda t, op: f"(ACOS(-1) * {t.translate(op.arg)} / 180)", + ops.BitwiseNot: lambda t, op: f"~ {t.translate(op.arg)}", + ops.BitwiseXor: lambda t, op: f"{t.translate(op.left)} ^ {t.translate(op.right) }", + ops.BitwiseOr: lambda t, op: f"{t.translate(op.left)} | {t.translate(op.right) }", + ops.BitwiseAnd: lambda t, op: f"{t.translate(op.left)} & {t.translate(op.right) }", + ops.BitwiseLeftShift: lambda t, op: f"{t.translate(op.left)} << {t.translate(op.right) }", + ops.BitwiseRightShift: lambda t, op: f"{t.translate(op.left)} >> {t.translate(op.right) }", # Temporal functions ops.Date: unary("DATE"), ops.DateFromYMD: fixed_arity("DATE", 3), diff --git a/ibis/backends/tests/test_numeric.py b/ibis/backends/tests/test_numeric.py index 66d74bdb9fc2..d45bec0cdd95 100644 --- a/ibis/backends/tests/test_numeric.py +++ b/ibis/backends/tests/test_numeric.py @@ -614,7 +614,7 @@ def test_constants(con, const): param(lambda t: t.int_col, lambda _: 3, id="col_scalar"), ], ) -@pytest.mark.notimpl(["bigquery", "dask", "datafusion", "pandas", "snowflake"]) +@pytest.mark.notimpl(["dask", "datafusion", "pandas", "snowflake"]) def test_bitwise_columns(backend, con, alltypes, df, op, left_fn, right_fn): expr = op(left_fn(alltypes), right_fn(alltypes)).name("tmp") result = con.execute(expr) @@ -648,7 +648,7 @@ def test_bitwise_columns(backend, con, alltypes, df, op, left_fn, right_fn): param(rshift, lambda t: t.int_col, lambda _: 3, id="rshift_col_scalar"), ], ) -@pytest.mark.notimpl(["bigquery", "dask", "datafusion", "pandas"]) +@pytest.mark.notimpl(["dask", "datafusion", "pandas"]) @pyspark_no_bitshift def test_bitwise_shift(backend, alltypes, df, op, left_fn, right_fn): expr = op(left_fn(alltypes), right_fn(alltypes)).name("tmp") @@ -678,7 +678,7 @@ def test_bitwise_shift(backend, alltypes, df, op, left_fn, right_fn): ("left", "right"), [param(4, L(2), id="int_col"), param(L(4), 2, id="col_int")], ) -@pytest.mark.notimpl(["bigquery", "dask", "datafusion", "pandas"]) +@pytest.mark.notimpl(["dask", "datafusion", "pandas"]) def test_bitwise_scalars(con, op, left, right): expr = op(left, right) result = con.execute(expr) @@ -686,7 +686,7 @@ def test_bitwise_scalars(con, op, left, right): assert result == expected -@pytest.mark.notimpl(["bigquery", "dask", "datafusion", "pandas", "snowflake"]) +@pytest.mark.notimpl(["dask", "datafusion", "pandas", "snowflake"]) def test_bitwise_not_scalar(con): expr = ~L(2) result = con.execute(expr) @@ -694,7 +694,7 @@ def test_bitwise_not_scalar(con): assert result == expected -@pytest.mark.notimpl(["bigquery", "dask", "datafusion", "pandas", "snowflake"]) +@pytest.mark.notimpl(["dask", "datafusion", "pandas", "snowflake"]) def test_bitwise_not_col(backend, alltypes, df): expr = (~alltypes.int_col).name("tmp") result = expr.execute()