Skip to content

Commit e6e4e31

Browse files
committed
resolve the comments
1 parent 508b017 commit e6e4e31

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,10 @@ def _(expr: TypedExpr, op: ops.RemoteFunctionOp) -> sge.Expression:
150150
func = sge.func(func_name, expr.expr)
151151

152152
if not op.apply_on_null:
153-
return sge.Case(
154-
ifs=[
155-
sge.If(
156-
this=sge.Is(this=expr.expr, expression=sge.Null()), true=expr.expr
157-
)
158-
],
159-
default=func,
153+
return sge.If(
154+
this=sge.Is(this=expr.expr, expression=sge.Null()),
155+
true=expr.expr,
156+
false=func,
160157
)
161158

162159
return func

tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_remote_function_op/out.sql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ WITH `bfcte_0` AS (
55
), `bfcte_1` AS (
66
SELECT
77
*,
8-
`my_project`.`my_dataset`.`my_routine`(`int64_col`) AS `bfcol_1`
8+
`my_project`.`my_dataset`.`my_routine`(`int64_col`) AS `bfcol_1`,
9+
IF(
10+
`int64_col` IS NULL,
11+
`int64_col`,
12+
`my_project`.`my_dataset`.`my_routine`(`int64_col`)
13+
) AS `bfcol_2`
914
FROM `bfcte_0`
1015
)
1116
SELECT
12-
`bfcol_1` AS `int64_col`
17+
`bfcol_1` AS `apply_on_null_true`,
18+
`bfcol_2` AS `apply_on_null_false`
1319
FROM `bfcte_1`

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -174,28 +174,33 @@ def test_remote_function_op(scalar_types_df: bpd.DataFrame, snapshot):
174174
from bigframes.functions import udf_def
175175

176176
bf_df = scalar_types_df[["int64_col"]]
177-
op = ops.RemoteFunctionOp(
178-
function_def=udf_def.BigqueryUdf(
179-
routine_ref=bigquery.RoutineReference.from_string(
180-
"my_project.my_dataset.my_routine"
181-
),
182-
signature=udf_def.UdfSignature(
183-
input_types=(
184-
udf_def.UdfField(
185-
"x",
186-
bigquery.StandardSqlDataType(
187-
type_kind=bigquery.StandardSqlTypeNames.INT64
188-
),
177+
function_def = udf_def.BigqueryUdf(
178+
routine_ref=bigquery.RoutineReference.from_string(
179+
"my_project.my_dataset.my_routine"
180+
),
181+
signature=udf_def.UdfSignature(
182+
input_types=(
183+
udf_def.UdfField(
184+
"x",
185+
bigquery.StandardSqlDataType(
186+
type_kind=bigquery.StandardSqlTypeNames.INT64
189187
),
190188
),
191-
output_bq_type=bigquery.StandardSqlDataType(
192-
type_kind=bigquery.StandardSqlTypeNames.FLOAT64
193-
),
189+
),
190+
output_bq_type=bigquery.StandardSqlDataType(
191+
type_kind=bigquery.StandardSqlTypeNames.FLOAT64
194192
),
195193
),
196-
apply_on_null=True,
197194
)
198-
sql = utils._apply_ops_to_sql(bf_df, [op.as_expr("int64_col")], ["int64_col"])
195+
ops_map = {
196+
"apply_on_null_true": ops.RemoteFunctionOp(
197+
function_def=function_def, apply_on_null=True
198+
).as_expr("int64_col"),
199+
"apply_on_null_false": ops.RemoteFunctionOp(
200+
function_def=function_def, apply_on_null=False
201+
).as_expr("int64_col"),
202+
}
203+
sql = utils._apply_ops_to_sql(bf_df, list(ops_map.values()), list(ops_map.keys()))
199204
snapshot.assert_match(sql, "out.sql")
200205

201206

0 commit comments

Comments
 (0)