Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bigquery): add description for routine entities #9785

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 bigquery/google/cloud/bigquery/routine.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Routine(object):
"reference": "routineReference",
"return_type": "returnType",
"type_": "routineType",
"description": "description",
}

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

@property
def description(self):
"""Union[str, None]: Description of the routine (defaults to
Copy link
Contributor

@plamut plamut Nov 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit)
Mypy docs recommend using the Optional shorthand instead of a Union with None.

Suggested change
"""Union[str, None]: Description of the routine (defaults to
"""Optional[str]: Description of the routine (defaults to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohk, should i change same in the other files which has description property like in dataset.py and model.py .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking it is not in scope of this PR, but if it's not too much work, it would be a welcome cleanup IMO. 👍

:data:`None`).
"""
return self._properties.get(self._PROPERTY_TO_API_FIELD["description"])

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

@classmethod
def from_api_repr(cls, resource):
"""Factory: construct a routine given its API representation.
Expand Down
32 changes: 31 additions & 1 deletion bigquery/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_kind=bigquery_v2.enums.StandardSqlDataType.TypeKind.INT64
)
type_ = "SCALAR_FUNCTION"
description = "A routine description."

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

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


def test_from_api_repr(target_class):
Expand Down Expand Up @@ -117,6 +120,7 @@ def test_from_api_repr(target_class):
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"someNewField": "someValue",
"description": "A routine description.",
}
actual_routine = target_class.from_api_repr(resource)

Expand Down Expand Up @@ -148,6 +152,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."


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


def test_from_api_repr_w_unknown_fields(target_class):
Expand Down Expand Up @@ -202,6 +208,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
"language": "SQL",
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
},
["arguments"],
{"arguments": [{"name": "x", "dataType": {"typeKind": "INT64"}}]},
Expand All @@ -213,6 +220,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
"language": "SQL",
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
},
["body"],
{"definitionBody": "x * 3"},
Expand All @@ -224,6 +232,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
"language": "SQL",
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
},
["language"],
{"language": "SQL"},
Expand All @@ -235,6 +244,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
"language": "SQL",
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
},
["return_type"],
{"returnType": {"typeKind": "INT64"}},
Expand All @@ -246,19 +256,33 @@ def test_from_api_repr_w_unknown_fields(target_class):
"language": "SQL",
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
},
["type_"],
{"routineType": "SCALAR_FUNCTION"},
),
(
{
"arguments": [{"name": "x", "dataType": {"typeKind": "INT64"}}],
"definitionBody": "x * 3",
"language": "SQL",
"returnType": {"typeKind": "INT64"},
"routineType": "SCALAR_FUNCTION",
"description": "A routine description.",
},
["description"],
{"description": "A routine description."},
),
(
{},
["arguments", "language", "body", "type_", "return_type"],
["arguments", "language", "body", "type_", "return_type", "description"],
{
"arguments": None,
"definitionBody": None,
"language": None,
"returnType": None,
"routineType": None,
"description": None,
},
),
(
Expand Down Expand Up @@ -299,6 +323,12 @@ def test_set_return_type_w_none(object_under_test):
assert object_under_test._properties["returnType"] is None


def test_set_description_w_none(object_under_test):
object_under_test.description = None
assert object_under_test.description is None
assert object_under_test._properties["description"] is None


def test_repr(target_class):
model = target_class("my-proj.my_dset.my_routine")
actual_routine = repr(model)
Expand Down