Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit 679630f

Browse files
committed
chore: Migrate NaryRemoteFunctionOp operator to SQLGlot
1 parent 9c3bbc3 commit 679630f

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,17 @@ def _(
184184
return sge.func(func_name, left.expr, right.expr)
185185

186186

187+
@register_nary_op(ops.NaryRemoteFunctionOp, pass_op=True)
188+
def _(*operands: TypedExpr, op: ops.NaryRemoteFunctionOp) -> sge.Expression:
189+
routine_ref = op.function_def.routine_ref
190+
# Quote project, dataset, and routine IDs to avoid keyword clashes.
191+
func_name = (
192+
f"`{routine_ref.project}`.`{routine_ref.dataset_id}`.`{routine_ref.routine_id}`"
193+
)
194+
195+
return sge.func(func_name, *(operand.expr for operand in operands))
196+
197+
187198
@register_nary_op(ops.case_when_op)
188199
def _(*cases_and_outputs: TypedExpr) -> sge.Expression:
189200
# Need to upcast BOOL to INT if any output is numeric
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`float64_col`,
4+
`int64_col`,
5+
`string_col`
6+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
7+
), `bfcte_1` AS (
8+
SELECT
9+
*,
10+
`my_project`.`my_dataset`.`my_routine`(`int64_col`, `float64_col`, `string_col`) AS `bfcol_3`
11+
FROM `bfcte_0`
12+
)
13+
SELECT
14+
`bfcol_3` AS `int64_col`
15+
FROM `bfcte_1`

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,48 @@ def test_binary_remote_function_op(scalar_types_df: bpd.DataFrame, snapshot):
242242
snapshot.assert_match(sql, "out.sql")
243243

244244

245+
def test_nary_remote_function_op(scalar_types_df: bpd.DataFrame, snapshot):
246+
from google.cloud import bigquery
247+
248+
from bigframes.functions import udf_def
249+
250+
bf_df = scalar_types_df[["int64_col", "float64_col", "string_col"]]
251+
op = ops.NaryRemoteFunctionOp(
252+
function_def=udf_def.BigqueryUdf(
253+
routine_ref=bigquery.RoutineReference.from_string(
254+
"my_project.my_dataset.my_routine"
255+
),
256+
signature=udf_def.UdfSignature(
257+
input_types=(
258+
udf_def.UdfField(
259+
"x",
260+
bigquery.StandardSqlDataType(
261+
type_kind=bigquery.StandardSqlTypeNames.INT64
262+
),
263+
),
264+
udf_def.UdfField(
265+
"y",
266+
bigquery.StandardSqlDataType(
267+
type_kind=bigquery.StandardSqlTypeNames.FLOAT64
268+
),
269+
),
270+
udf_def.UdfField(
271+
"z",
272+
bigquery.StandardSqlDataType(
273+
type_kind=bigquery.StandardSqlTypeNames.STRING
274+
),
275+
),
276+
),
277+
output_bq_type=bigquery.StandardSqlDataType(
278+
type_kind=bigquery.StandardSqlTypeNames.FLOAT64
279+
),
280+
),
281+
)
282+
)
283+
sql = utils._apply_nary_op(bf_df, op, "int64_col", "float64_col", "string_col")
284+
snapshot.assert_match(sql, "out.sql")
285+
286+
245287
def test_case_when_op(scalar_types_df: bpd.DataFrame, snapshot):
246288
ops_map = {
247289
"single_case": ops.case_when_op.as_expr(

0 commit comments

Comments
 (0)