Skip to content
Open
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: 4 additions & 1 deletion bigframes/functions/_function_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,10 @@ def provision_bq_remote_function(
# makes their naming more stable for the same udf code
session_id = None if name else self._session.session_id
cloud_function_name = _utils.get_cloud_function_name(
function_hash, session_id, uniq_suffix
function_hash,
user_given_name=name,
session_id=session_id,
uniq_suffix=uniq_suffix,
)
cf_endpoint = self.get_cloud_function_endpoint(cloud_function_name)

Expand Down
9 changes: 8 additions & 1 deletion bigframes/functions/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,16 @@ def routine_ref_to_string_for_query(routine_ref: bigquery.RoutineReference) -> s
return f"`{routine_ref.project}.{routine_ref.dataset_id}`.{routine_ref.routine_id}"


def get_cloud_function_name(function_hash, session_id=None, uniq_suffix=None):
def get_cloud_function_name(
function_hash: str,
user_given_name: Optional[str] = None,
session_id: Optional[str] = None,
uniq_suffix: Optional[str] = None,
):
"Get a name for the cloud function for the given user defined function."
parts = [_BIGFRAMES_FUNCTION_PREFIX]
if user_given_name:
parts.append(user_given_name)
if session_id:
parts.append(session_id)
parts.append(function_hash)
Expand Down
2 changes: 1 addition & 1 deletion tests/system/large/functions/test_remote_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def add_one(x):
package_requirements = bff_utils.get_updated_package_requirements()
add_one_uniq_hash = bff_utils.get_hash(add_one_uniq, package_requirements)
add_one_uniq_cf_name = bff_utils.get_cloud_function_name(
add_one_uniq_hash, session.session_id
add_one_uniq_hash, session_id=session.session_id
)

# There should be no cloud function yet for the unique udf
Expand Down
21 changes: 16 additions & 5 deletions tests/unit/functions/test_remote_function_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,48 @@ def test_get_remote_function_locations(


@pytest.mark.parametrize(
"func_hash, session_id, uniq_suffix, expected_name",
"func_hash, user_given_name, session_id, uniq_suffix, expected_name",
[
(
"hash123",
"my_func",
None,
None,
"bigframes-hash123",
"bigframes-my_func-hash123",
),
(
"hash456",
None,
"session789",
None,
"bigframes-session789-hash456",
),
(
"hash123",
None,
None,
"suffixABC",
"bigframes-hash123-suffixABC",
),
(
"hash456",
"really_cool_udf",
"session789",
"suffixDEF",
"bigframes-session789-hash456-suffixDEF",
"bigframes-really_cool_udf-session789-hash456-suffixDEF",
),
],
)
def test_get_cloud_function_name(func_hash, session_id, uniq_suffix, expected_name):
def test_get_cloud_function_name(
func_hash, user_given_name, session_id, uniq_suffix, expected_name
):
"""Tests the construction of the cloud function name from its parts."""
result = _utils.get_cloud_function_name(func_hash, session_id, uniq_suffix)
result = _utils.get_cloud_function_name(
func_hash,
user_given_name=user_given_name,
session_id=session_id,
uniq_suffix=uniq_suffix,
)

assert result == expected_name

Expand Down
Loading