Skip to content

Commit 9bbc0cd

Browse files
committed
chore: Migrate fillna_op operator to SQLGlot
1 parent ef5e83a commit 9bbc0cd

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

bigframes/core/compile/sqlglot/expressions/generic_ops.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import bigframes.core.compile.sqlglot.scalar_compiler as scalar_compiler
2525

2626
register_unary_op = scalar_compiler.scalar_op_compiler.register_unary_op
27+
register_binary_op = scalar_compiler.scalar_op_compiler.register_binary_op
2728
register_nary_op = scalar_compiler.scalar_op_compiler.register_nary_op
2829
register_ternary_op = scalar_compiler.scalar_op_compiler.register_ternary_op
2930

@@ -133,6 +134,11 @@ def _(
133134
)
134135

135136

137+
@register_binary_op(ops.fillna_op)
138+
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
139+
return sge.Coalesce(this=left.expr, expressions=[right.expr])
140+
141+
136142
@register_nary_op(ops.case_when_op)
137143
def _(*cases_and_outputs: TypedExpr) -> sge.Expression:
138144
# Need to upcast BOOL to INT if any output is numeric
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`int64_col` AS `bfcol_0`,
4+
`float64_col` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
*,
9+
COALESCE(`bfcol_0`, `bfcol_1`) AS `bfcol_2`
10+
FROM `bfcte_0`
11+
)
12+
SELECT
13+
`bfcol_2` AS `int64_col`
14+
FROM `bfcte_1`

tests/unit/core/compile/sqlglot/expressions/test_generic_ops.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ def test_clip(scalar_types_df: bpd.DataFrame, snapshot):
225225
snapshot.assert_match(sql, "out.sql")
226226

227227

228+
def test_fillna(scalar_types_df: bpd.DataFrame, snapshot):
229+
bf_df = scalar_types_df[["int64_col", "float64_col"]]
230+
sql = utils._apply_binary_op(bf_df, ops.fillna_op, "int64_col", "float64_col")
231+
snapshot.assert_match(sql, "out.sql")
232+
233+
228234
def test_hash(scalar_types_df: bpd.DataFrame, snapshot):
229235
col_name = "string_col"
230236
bf_df = scalar_types_df[[col_name]]

0 commit comments

Comments
 (0)