Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bigframes/core/compile/sqlglot/expressions/generic_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ def _(
)


@register_binary_op(ops.fillna_op)
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
return sge.Coalesce(this=left.expr, expressions=[right.expr])


@register_nary_op(ops.case_when_op)
def _(*cases_and_outputs: TypedExpr) -> sge.Expression:
# Need to upcast BOOL to INT if any output is numeric
Expand Down
2 changes: 1 addition & 1 deletion tests/system/small/engines/test_generic_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def test_engines_coalesce_op(scalars_array_value: array_value.ArrayValue, engine
assert_equivalence_execution(arr.node, REFERENCE_ENGINE, engine)


@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
@pytest.mark.parametrize("engine", ["polars", "bq", "bq-sqlglot"], indirect=True)
def test_engines_fillna_op(scalars_array_value: array_value.ArrayValue, engine):
arr, _ = scalars_array_value.compute_values(
[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
WITH `bfcte_0` AS (
SELECT
`float64_col`,
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
COALESCE(`int64_col`, `float64_col`) AS `bfcol_2`
FROM `bfcte_0`
)
SELECT
`bfcol_2` AS `int64_col`
FROM `bfcte_1`
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ def test_clip(scalar_types_df: bpd.DataFrame, snapshot):
snapshot.assert_match(sql, "out.sql")


def test_fillna(scalar_types_df: bpd.DataFrame, snapshot):
bf_df = scalar_types_df[["int64_col", "float64_col"]]
sql = utils._apply_binary_op(bf_df, ops.fillna_op, "int64_col", "float64_col")
snapshot.assert_match(sql, "out.sql")


def test_hash(scalar_types_df: bpd.DataFrame, snapshot):
col_name = "string_col"
bf_df = scalar_types_df[[col_name]]
Expand Down