Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions google/cloud/bigquery/routine.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Routine(object):
"return_type": "returnType",
"type_": "routineType",
"description": "description",
"determinism_level": "determinismLevel",
}

def __init__(self, routine_ref, **kwargs):
Expand Down Expand Up @@ -253,6 +254,17 @@ def description(self):
def description(self, value):
self._properties[self._PROPERTY_TO_API_FIELD["description"]] = value

@property
def determinism_level(self):
"""Optional[str]: (experimental) The determinism level of the JavaScript UDF
if defined.
"""
return self._properties.get(self._PROPERTY_TO_API_FIELD["determinism_level"])

@determinism_level.setter
def determinism_level(self, value):
self._properties[self._PROPERTY_TO_API_FIELD["determinism_level"]] = value

@classmethod
def from_api_repr(cls, resource):
"""Factory: construct a routine given its API representation.
Expand Down
1 change: 1 addition & 0 deletions tests/system/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,7 @@ def test_create_routine(self):
)
]
routine.body = "return maxValue(arr)"
routine.determinism_level = "DETERMINISTIC"
Comment thread
plamut marked this conversation as resolved.
Outdated
query_string = "SELECT `{}`([-100.0, 3.14, 100.0, 42.0]) as max_value;".format(
str(routine.reference)
)
Expand Down
36 changes: 35 additions & 1 deletion tests/unit/routine/test_routine.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def test_ctor_w_properties(target_class):
)
type_ = "SCALAR_FUNCTION"
description = "A routine description."
determinism_level = "NOT_DETERMINISTIC"

actual_routine = target_class(
routine_id,
Expand All @@ -82,6 +83,7 @@ def test_ctor_w_properties(target_class):
return_type=return_type,
type_=type_,
description=description,
determinism_level=determinism_level,
)

ref = RoutineReference.from_string(routine_id)
Expand All @@ -92,6 +94,7 @@ def test_ctor_w_properties(target_class):
assert actual_routine.return_type == return_type
assert actual_routine.type_ == type_
assert actual_routine.description == description
assert actual_routine.determinism_level == "NOT_DETERMINISTIC"


def test_from_api_repr(target_class):
Expand Down Expand Up @@ -120,6 +123,7 @@ def test_from_api_repr(target_class):
"routineType": "SCALAR_FUNCTION",
"someNewField": "someValue",
"description": "A routine description.",
"determinismLevel": "DETERMINISTIC",
}
actual_routine = target_class.from_api_repr(resource)

Expand Down Expand Up @@ -152,6 +156,7 @@ def test_from_api_repr(target_class):
assert actual_routine.type_ == "SCALAR_FUNCTION"
assert actual_routine._properties["someNewField"] == "someValue"
assert actual_routine.description == "A routine description."
assert actual_routine.determinism_level == "DETERMINISTIC"


def test_from_api_repr_w_minimal_resource(target_class):
Expand All @@ -177,6 +182,7 @@ def test_from_api_repr_w_minimal_resource(target_class):
assert actual_routine.return_type is None
assert actual_routine.type_ is None
assert actual_routine.description is None
assert actual_routine.determinism_level is None


def test_from_api_repr_w_unknown_fields(target_class):
Expand Down Expand Up @@ -208,6 +214,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
"determinismLevel": "DETERMINISM_LEVEL_UNSPECIFIED",
},
["arguments"],
{"arguments": [{"name": "x", "dataType": {"typeKind": "INT64"}}]},
Expand All @@ -220,6 +227,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
"determinismLevel": "DETERMINISM_LEVEL_UNSPECIFIED",
},
["body"],
{"definitionBody": "x * 3"},
Expand All @@ -232,6 +240,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
"determinismLevel": "DETERMINISM_LEVEL_UNSPECIFIED",
},
["language"],
{"language": "SQL"},
Expand All @@ -244,6 +253,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
"determinismLevel": "DETERMINISM_LEVEL_UNSPECIFIED",
},
["return_type"],
{"returnType": {"typeKind": "INT64"}},
Expand All @@ -256,6 +266,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
"determinismLevel": "DETERMINISM_LEVEL_UNSPECIFIED",
},
["type_"],
{"routineType": "SCALAR_FUNCTION"},
Expand All @@ -268,20 +279,43 @@ def test_from_api_repr_w_unknown_fields(target_class):
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
"determinismLevel": "DETERMINISM_LEVEL_UNSPECIFIED",
},
["description"],
{"description": "A routine description."},
),
(
{
"arguments": [{"name": "x", "dataType": {"typeKind": "INT64"}}],
"definitionBody": "x * 3",
"language": "SQL",
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
"determinismLevel": "DETERMINISM_LEVEL_UNSPECIFIED",
},
["determinism_level"],
{"determinismLevel": "DETERMINISM_LEVEL_UNSPECIFIED"},
),
(
{},
["arguments", "language", "body", "type_", "return_type", "description"],
[
"arguments",
"language",
"body",
"type_",
"return_type",
"description",
"determinism_level",
],
{
"arguments": None,
"definitionBody": None,
"language": None,
"returnType": None,
"routineType": None,
"description": None,
"determinismLevel": None,
},
),
(
Expand Down