Skip to content

Commit

Permalink
feat(bigquery): implement ops.ZeroIfNull
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 c5f2a1d commit f4c5607
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ibis/backends/bigquery/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ def _nullifzero(t, op):
return f"NULLIF({t.translate(op.arg)}, {casted})"


def _zeroifnull(t, op):
casted = bigquery_cast('0', op.output_dtype)
return f"COALESCE({t.translate(op.arg)}, {casted})"


def _array_agg(t, op):
arg = op.arg
if (where := op.where) is not None:
Expand Down Expand Up @@ -567,6 +572,7 @@ def _nth_value(t, op):
ops.IfNull: fixed_arity("IFNULL", 2),
ops.NullIf: fixed_arity("NULLIF", 2),
ops.NullIfZero: _nullifzero,
ops.ZeroIfNull: _zeroifnull,
ops.NotAny: bigquery_compile_notany,
ops.NotAll: bigquery_compile_notall,
# Reductions
Expand Down
4 changes: 2 additions & 2 deletions ibis/backends/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def test_logical_negation_column(backend, alltypes, df, op):
backend.assert_series_equal(result, expected, check_names=False)


@pytest.mark.notimpl(["bigquery", "datafusion"])
@pytest.mark.notimpl(["datafusion"])
@pytest.mark.parametrize(
("dtype", "zero", "expected"),
[("int64", 0, 1), ("float64", 0.0, 1.0)],
Expand All @@ -654,7 +654,7 @@ def test_zeroifnull_literals(con, dtype, zero, expected):
assert con.execute(ibis.literal(expected, type=dtype).zeroifnull()) == expected


@pytest.mark.notimpl(["bigquery", "datafusion"])
@pytest.mark.notimpl(["datafusion"])
@pytest.mark.min_version(
dask="2022.01.1",
reason="unsupported operation with later versions of pandas",
Expand Down

0 comments on commit f4c5607

Please sign in to comment.