10BC0 feat(bigquery): add description for routine entities (#9785) · googleapis/google-cloud-python@0b69ee0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b69ee0

Browse files
HemangChothanitswast
authored andcommitted
feat(bigquery): add description for routine entities (#9785)
* feat(bigquery): add description for routine entities * feat(bigquery): use the Optional shorthand instead of a Union with None
1 parent 0249a34 commit 0b69ee0

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

bigquery/google/cloud/bigquery/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def default_table_expiration_ms(self, value):
509509

510510
@property
511511
def description(self):
512-
"""Union[str, None]: Description of the dataset as set by the user
512+
"""Optional[str]: Description of the dataset as set by the user
513513
(defaults to :data:`None`).
514514
515515
Raises:

bigquery/google/cloud/bigquery/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def expires(self, value):
217217

218218
@property
219219
def description(self):
220-
"""Union[str, None]: Description of the model (defaults to
220+
"""Optional[str]: Description of the model (defaults to
221221
:data:`None`).
222222
"""
223223
return self._properties.get("description")

bigquery/google/cloud/bigquery/routine.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Routine(object):
5050
"reference": "routineReference",
5151
"return_type": "returnType",
5252
"type_": "routineType",
53+
"description": "description",
5354
}
5455

5556
def __init__(self, routine_ref, **kwargs):
@@ -239,6 +240,17 @@ def body(self):
239240
def body(self, value):
240241
self._properties[self._PROPERTY_TO_API_FIELD["body"]] = value
241242

243+
@property
244+
def description(self):
245+
"""Optional[str]: Description of the routine (defaults to
246+
:data:`None`).
247+
"""
248+
return self._properties.get(self._PROPERTY_TO_API_FIELD["description"])
249+
250+
@description.setter
251+
def description(self, value):
252+
self._properties[self._PROPERTY_TO_API_FIELD["description"]] = value
253+
242254
@classmethod
243255
def from_api_repr(cls, resource):
244256
"""Factory: construct a routine given its API representation.

bigquery/tests/unit/routine/test_routine.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def test_ctor_w_properties(target_class):
7373
type_kind=bigquery_v2.enums.StandardSqlDataType.TypeKind.INT64
7474
)
7575
type_ = "SCALAR_FUNCTION"
76+
description = "A routine description."
7677

7778
actual_routine = target_class(
7879
routine_id,
@@ -81,6 +82,7 @@ def test_ctor_w_properties(target_class):
8182
language=language,
8283
return_type=return_type,
8384
type_=type_,
85+
description=description,
8486
)
8587

8688
ref = RoutineReference.from_string(routine_id)
@@ -90,6 +92,7 @@ def test_ctor_w_properties(target_class):
9092
assert actual_routine.language == language
9193
assert actual_routine.return_type == return_type
9294
assert actual_routine.type_ == type_
95+
assert actual_routine.description == description
9396

9497

9598
def test_from_api_repr(target_class):
@@ -117,6 +120,7 @@ def test_from_api_repr(target_class):
117120
"returnType": {"typeKind": "INT64"},
118121
"routineType": "SCALAR_FUNCTION",
119122
"someNewField": "someValue",
123+
"description": "A routine description.",
120124
}
121125
actual_routine = target_class.from_api_repr(resource)
122126

@@ -148,6 +152,7 @@ def test_from_api_repr(target_class):
148152
)
149153
assert actual_routine.type_ == 402E "SCALAR_FUNCTION"
150154
assert actual_routine._properties["someNewField"] == "someValue"
155+
assert actual_routine.description == "A routine description."
151156

152157

153158
def test_from_api_repr_w_minimal_resource(target_class):
@@ -172,6 +177,7 @@ def test_from_api_repr_w_minimal_resource(target_class):
172177
assert actual_routine.language is None
173178
assert actual_routine.return_type is None
174179
assert actual_routine.type_ is None
180+
assert actual_routine.description is None
175181

176182

177183
def test_from_api_repr_w_unknown_fields(target_class):
@@ -202,6 +208,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
202208
"language": "SQL",
203209
"returnType": {"typeKind": "INT64"},
204210
"routineType": "SCALAR_FUNCTION",
211+
"description": "A routine description.",
205212
},
206213
["arguments"],
207214
{"arguments": [{"name": "x", "dataType": {"typeKind": "INT64"}}]},
@@ -213,6 +220,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
213220
"language": "SQL",
214221
"returnType": {"typeKind": "INT64"},
215222
"routineType": "SCALAR_FUNCTION",
223+
"description": "A routine description.",
216224
},
217225
["body"],
218226
{"definitionBody": "x * 3"},
@@ -224,6 +232,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
224232
"language": "SQL",
225233
"returnType": {"typeKind": "INT64"},
226234
"routineType": "SCALAR_FUNCTION",
235+
"description": "A routine description.",
227236
},
228237
["language"],
229238
{"language": "SQL"},
@@ -235,6 +244,7 @@ def test_from_api_repr_w_unknown_fields(target_class):
235244
"language": "SQL",
236245
"returnType": {"typeKind": "INT64"},
237246
"routineType": "SCALAR_FUNCTION",
247+
"description": "A routine description.",
238248
},
239249
["return_type"],
240250
{"returnType": {"typeKind": "INT64"}},
@@ -246,19 +256,33 @@ def test_from_api_repr_w_unknown_fields(target_class):
246256
"language": "SQL",
247257
"returnType": {"typeKind": "INT64"},
248258
"routineType": "SCALAR_FUNCTION",
259+
"description": "A routine description.",
249260
},
250261
["type_"],
251262
{"routineType": "SCALAR_FUNCTION"},
252263
),
264+
(
265+
{
266+
"arguments": [{"name": "x", "dataType": {"typeKind": "INT64"}}],
267+
"definitionBody": "x * 3",
268+
CB92 "language": "SQL",
269+
"returnType": {"typeKind": "INT64"},
270+
"routineType": "SCALAR_FUNCTION",
271+
"description": "A routine description.",
272+
},
273+
["description"],
274+
{"description": "A routine description."},
275+
),
253276
(
254277
{},
255-
["arguments", "language", "body", "type_", "return_type"],
278+
["arguments", "language", "body", "type_", "return_type", "description"],
256279
{
257280
"arguments": None,
258281
"definitionBody": None,
259282
"language": None,
260283
"returnType": None,
261284
"routineType": None,
285+
"description": None,
262286
},
263287
),
264288
(
@@ -299,6 +323,12 @@ def test_set_return_type_w_none(object_under_test):
299323
assert object_under_test._properties["returnType"] is None
300324

301325

326+
def test_set_description_w_none(object_under_test):
327+
object_under_test.description = None
328+
assert object_under_test.description is None
329+
assert object_under_test._properties["description"] is None
330+
331+
302332
def test_repr(target_class):
303333
model = target_class("my-proj.my_dset.my_routine")
304334
actual_routine = repr(model)

0 commit comments

Comments
 (0)
0