|
21 | 21 | import base64 |
22 | 22 | import threading |
23 | 23 | import logging |
| 24 | +import uuid |
24 | 25 |
|
25 | 26 | from google.protobuf.struct_pb2 import ListValue |
26 | 27 | from google.protobuf.struct_pb2 import Value |
@@ -298,6 +299,8 @@ def _make_value_pb(value): |
298 | 299 | return Value(string_value=base64.b64encode(value)) |
299 | 300 | if isinstance(value, Interval): |
300 | 301 | return Value(string_value=str(value)) |
| 302 | + if isinstance(value, uuid.UUID): |
| 303 | + return Value(string_value=str(value)) |
301 | 304 |
|
302 | 305 | raise ValueError("Unknown type: %s" % (value,)) |
303 | 306 |
|
@@ -399,6 +402,8 @@ def _get_type_decoder(field_type, field_name, column_info=None): |
399 | 402 | return _parse_numeric |
400 | 403 | elif type_code == TypeCode.JSON: |
401 | 404 | return _parse_json |
| 405 | + elif type_code == TypeCode.UUID: |
| 406 | + return _parse_uuid |
402 | 407 | elif type_code == TypeCode.PROTO: |
403 | 408 | return lambda value_pb: _parse_proto(value_pb, column_info, field_name) |
404 | 409 | elif type_code == TypeCode.ENUM: |
@@ -481,6 +486,10 @@ def _parse_json(value_pb): |
481 | 486 | return JsonObject.from_str(value_pb.string_value) |
482 | 487 |
|
483 | 488 |
|
| 489 | +def _parse_uuid(value_pb): |
| 490 | + return uuid.UUID(value_pb.string_value) |
| 491 | + |
| 492 | + |
484 | 493 | def _parse_proto(value_pb, column_info, field_name): |
485 | 494 | bytes_value = base64.b64decode(value_pb.string_value) |
486 | 495 | if column_info is not None and column_info.get(field_name) is not None: |
|
0 commit comments