|
21 | 21 | from typing import Any, Optional, Dict, Union |
22 | 22 |
|
23 | 23 | from google.cloud.bigquery.table import _parse_schema_resource |
| 24 | +from google.cloud.bigquery import _helpers |
24 | 25 | from google.cloud.bigquery._helpers import _rows_from_json |
25 | | -from google.cloud.bigquery._helpers import _QUERY_PARAMS_FROM_JSON |
26 | 26 | from google.cloud.bigquery._helpers import _SCALAR_VALUE_TO_JSON_PARAM |
27 | 27 | from google.cloud.bigquery._helpers import _SUPPORTED_RANGE_ELEMENTS |
28 | 28 |
|
@@ -571,14 +571,19 @@ def from_api_repr(cls, resource: dict) -> "ScalarQueryParameter": |
571 | 571 | Returns: |
572 | 572 | google.cloud.bigquery.query.ScalarQueryParameter: Instance |
573 | 573 | """ |
| 574 | + # Import here to avoid circular imports. |
| 575 | + from google.cloud.bigquery import schema |
| 576 | + |
574 | 577 | name = resource.get("name") |
575 | 578 | type_ = resource["parameterType"]["type"] |
576 | 579 |
|
577 | 580 | # parameterValue might not be present if JSON resource originates |
578 | 581 | # from the back-end - the latter omits it for None values. |
579 | 582 | value = resource.get("parameterValue", {}).get("value") |
580 | 583 | if value is not None: |
581 | | - converted = _QUERY_PARAMS_FROM_JSON[type_](value, None) |
| 584 | + converted = _helpers.SCALAR_QUERY_PARAM_PARSER.to_py( |
| 585 | + value, schema.SchemaField(name, type_) |
| 586 | + ) |
582 | 587 | else: |
583 | 588 | converted = None |
584 | 589 |
|
@@ -693,13 +698,20 @@ def _from_api_repr_struct(cls, resource): |
693 | 698 |
|
694 | 699 | @classmethod |
695 | 700 | def _from_api_repr_scalar(cls, resource): |
| 701 | + """Converts REST resource into a list of scalar values.""" |
| 702 | + # Import here to avoid circular imports. |
| 703 | + from google.cloud.bigquery import schema |
| 704 | + |
696 | 705 | name = resource.get("name") |
697 | 706 | array_type = resource["parameterType"]["arrayType"]["type"] |
698 | 707 | parameter_value = resource.get("parameterValue", {}) |
699 | 708 | array_values = parameter_value.get("arrayValues", ()) |
700 | 709 | values = [value["value"] for value in array_values] |
701 | 710 | converted = [ |
702 | | - _QUERY_PARAMS_FROM_JSON[array_type](value, None) for value in values |
| 711 | + _helpers.SCALAR_QUERY_PARAM_PARSER.to_py( |
| 712 | + value, schema.SchemaField(name, array_type) |
| 713 | + ) |
| 714 | + for value in values |
703 | 715 | ] |
704 | 716 | return cls(name, array_type, converted) |
705 | 717 |
|
@@ -850,6 +862,9 @@ def from_api_repr(cls, resource: dict) -> "StructQueryParameter": |
850 | 862 | Returns: |
851 | 863 | google.cloud.bigquery.query.StructQueryParameter: Instance |
852 | 864 | """ |
| 865 | + # Import here to avoid circular imports. |
| 866 | + from google.cloud.bigquery import schema |
| 867 | + |
853 | 868 | name = resource.get("name") |
854 | 869 | instance = cls(name) |
855 | 870 | type_resources = {} |
@@ -877,7 +892,9 @@ def from_api_repr(cls, resource: dict) -> "StructQueryParameter": |
877 | 892 | converted = ArrayQueryParameter.from_api_repr(struct_resource) |
878 | 893 | else: |
879 | 894 | value = value["value"] |
880 | | - converted = _QUERY_PARAMS_FROM_JSON[type_](value, None) |
| 895 | + converted = _helpers.SCALAR_QUERY_PARAM_PARSER.to_py( |
| 896 | + value, schema.SchemaField(name, type_) |
| 897 | + ) |
881 | 898 | instance.struct_values[key] = converted |
882 | 899 | return instance |
883 | 900 |
|
|
0 commit comments