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

Commit 2196527

Browse files
fix mores tests
1 parent e2de96b commit 2196527

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

bigframes/functions/_function_client.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -687,19 +687,17 @@ def get_remote_function_specs(
687687
self, remote_function_name: str
688688
) -> udf_def.RemoteFunctionConfig | None:
689689
"""Check whether a remote function already exists for the udf."""
690-
routines = self._bq_client.list_routines(
691-
f"{self._gcp_project_id}.{self._bq_dataset}"
692-
)
693690
try:
694-
for routine in routines:
695-
routine = cast(bigquery.Routine, routine)
696-
if routine.reference.routine_id == remote_function_name:
697-
try:
698-
return udf_def.RemoteFunctionConfig.from_bq_routine(routine)
699-
except udf_def.ReturnTypeMissingError:
700-
# The remote function exists, but it's missing a return type.
701-
# Something is wrong with the function, so we should replace it.
702-
return None
691+
routine = self._bq_client.get_routine(
692+
f"{self._gcp_project_id}.{self._bq_dataset}.{remote_function_name}"
693+
)
694+
if routine.reference.routine_id == remote_function_name:
695+
try:
696+
return udf_def.RemoteFunctionConfig.from_bq_routine(routine)
697+
except udf_def.ReturnTypeMissingError:
698+
# The remote function exists, but it's missing a return type.
699+
# Something is wrong with the function, so we should replace it.
700+
return None
703701
except google.api_core.exceptions.NotFound:
704702
# The dataset might not exist, in which case the remote function doesn't, either.
705703
# Note: list_routines doesn't make an API request until we iterate on the response object.

bigframes/functions/function.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,21 @@ def _try_import_routine(
9191
def _try_import_row_routine(
9292
routine: bigquery.Routine, session: bigframes.Session
9393
) -> BigqueryCallableRowRoutine:
94-
udf_def = _routine_as_udf_def(routine)
94+
udf_def = _routine_as_udf_def(routine, is_row_processor=True)
95+
9596
is_remote = (
9697
hasattr(routine, "remote_function_options") and routine.remote_function_options
9798
)
9899
return BigqueryCallableRowRoutine(udf_def, session, is_managed=not is_remote)
99100

100101

101-
def _routine_as_udf_def(routine: bigquery.Routine) -> udf_def.BigqueryUdf:
102+
def _routine_as_udf_def(
103+
routine: bigquery.Routine, is_row_processor: bool = False
104+
) -> udf_def.BigqueryUdf:
102105
try:
103-
return udf_def.BigqueryUdf.from_routine(routine)
106+
return udf_def.BigqueryUdf.from_routine(
107+
routine, is_row_processor=is_row_processor
108+
)
104109
except udf_def.ReturnTypeMissingError:
105110
raise bf_formatting.create_exception_with_feedback_link(
106111
ValueError, "Function return type must be specified."
@@ -140,6 +145,7 @@ def read_gbq_function(
140145
ValueError, f"Unknown function '{routine_ref}'."
141146
)
142147

148+
# TODO(493293086): Deprecate is_row_processor.
143149
if is_row_processor:
144150
return _try_import_row_routine(routine, session)
145151
else:

bigframes/functions/udf_def.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,11 @@ def with_devirtualize(self) -> UdfSignature:
255255
output=self.output.emulating_type,
256256
)
257257

258+
# TODO(493293086): Deprecate is_row_processor.
258259
@classmethod
259-
def from_routine(cls, routine: bigquery.Routine) -> UdfSignature:
260+
def from_routine(
261+
cls, routine: bigquery.Routine, is_row_processor: bool = False
262+
) -> UdfSignature:
260263
import bigframes.functions._utils
261264

262265
## Handle return type
@@ -291,7 +294,20 @@ def from_routine(cls, routine: bigquery.Routine) -> UdfSignature:
291294

292295
## Handle input types
293296
udf_fields = []
297+
298+
if is_row_processor:
299+
if len(routine.arguments) != 1:
300+
raise ValueError(
301+
"Row processor functions must have exactly one input argument."
302+
)
303+
294304
for argument in routine.arguments:
305+
if is_row_processor:
306+
if argument.data_type.type_kind != "STRING":
307+
raise ValueError(
308+
"Row processor functions must have STRING input type."
309+
)
310+
udf_fields.append(UdfArg(argument.name, RowSeriesInputFieldV1()))
295311
udf_fields.append(UdfArg.from_sdk(argument))
296312

297313
return cls(
@@ -361,8 +377,12 @@ def with_devirtualize(self) -> BigqueryUdf:
361377
)
362378

363379
@classmethod
364-
def from_routine(cls, routine: bigquery.Routine) -> BigqueryUdf:
365-
signature = UdfSignature.from_routine(routine)
380+
def from_routine(
381+
cls, routine: bigquery.Routine, is_row_processor: bool = False
382+
) -> BigqueryUdf:
383+
signature = UdfSignature.from_routine(
384+
routine, is_row_processor=is_row_processor
385+
)
366386
return cls(routine.reference, signature=signature)
367387

368388

tests/system/large/functions/test_remote_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ def square(x):
17231723
gcf = session.cloudfunctionsclient.get_function(
17241724
name=square_remote_2.bigframes_cloud_function
17251725
)
1726-
assert gcf.service_config.available_cpu == 2.0
1726+
assert float(gcf.service_config.available_cpu) == 2.0
17271727
finally:
17281728
# clean up the gcp assets created for the remote function
17291729
if square_remote is not None:

0 commit comments

Comments
 (0)