Skip to content

Commit

Permalink
feat(bigquery): add description for routine entities (#9785)
Browse files Browse the repository at this point in the history
* feat(bigquery): add description for routine entities

* feat(bigquery): use the Optional shorthand instead of a Union with None
  • Loading branch information
HemangChothani authored and tswast committed Nov 19, 2019
1 parent 0249a34 commit 0b69ee0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bigquery/google/cloud/bigquery/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def default_table_expiration_ms(self, value):

@property
def description(self):
"""Union[str, None]: Description of the dataset as set by the user
"""Optional[str]: Description of the dataset as set by the user
(defaults to :data:`None`).
Raises:
Expand Down
2 changes: 1 addition & 1 deletion bigquery/google/cloud/bigquery/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def expires(self, value):

@property
def description(self):
"""Union[str, None]: Description of the model (defaults to
"""Optional[str]: Description of the model (defaults to
:data:`None`).
"""
return self._properties.get("description")
Expand Down
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):
"""Optional[str]: Description of the routine (defaults to
: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

0 comments on commit 0b69ee0

Please sign in to comment.