Skip to content

Commit

Permalink
feat(bigquery): implement bitwise operations
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-kwitt authored and cpcloud committed Jan 24, 2023
1 parent f4c5607 commit 55b69b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions ibis/backends/bigquery/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
10 changes: 5 additions & 5 deletions ibis/backends/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -678,23 +678,23 @@ 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)
expected = op(4, 2)
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)
expected = -3
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()
Expand Down

0 comments on commit 55b69b1

Please sign in to comment.