|
15 | 15 | """Schemas for BigQuery tables / queries.""" |
16 | 16 |
|
17 | 17 | importcollections |
| 18 | +fromtypingimportOptional |
18 | 19 |
|
19 | 20 | fromgoogle.cloud.bigquery_v2importtypes |
20 | 21 |
|
@@ -106,11 +107,25 @@ def __init__( |
106 | 107 | self._properties["maxLength"]=max_length |
107 | 108 | self._fields=tuple(fields) |
108 | 109 |
|
109 | | -ifpolicy_tagsisNone: |
110 | | -is_record=field_typeisnotNoneandfield_type.upper()in_STRUCT_TYPES |
111 | | -self._policy_tags=Noneifis_recordelsePolicyTagList() |
112 | | -else: |
113 | | -self._policy_tags=policy_tags |
| 110 | +self._policy_tags=self._determine_policy_tags(field_type,policy_tags) |
| 111 | + |
| 112 | +@staticmethod |
| 113 | +def_determine_policy_tags( |
| 114 | +field_type:str,given_policy_tags |
| 115 | + )->Optional["PolicyTagList"]: |
| 116 | +"""Return the given policy tags, or their suitable representation if `None`. |
| 117 | +
|
| 118 | + Args: |
| 119 | + field_type: The type of the schema field. |
| 120 | + given_policy_tags: The policy tags to maybe ajdust. |
| 121 | + """ |
| 122 | +ifgiven_policy_tagsisnotNone: |
| 123 | +returngiven_policy_tags |
| 124 | + |
| 125 | +iffield_typeisnotNoneandfield_type.upper()in_STRUCT_TYPES: |
| 126 | +returnNone |
| 127 | + |
| 128 | +returnPolicyTagList() |
114 | 129 |
|
115 | 130 | @staticmethod |
116 | 131 | def__get_int(api_repr,name): |
@@ -138,9 +153,9 @@ def from_api_repr(cls, api_repr: dict) -> "SchemaField": |
138 | 153 | description=api_repr.get("description",_DEFAULT_VALUE) |
139 | 154 | fields=api_repr.get("fields", ()) |
140 | 155 |
|
141 | | -policy_tags=PolicyTagList.from_api_repr(api_repr.get("policyTags")) |
142 | | -ifpolicy_tagsisNoneandfield_typenotin_STRUCT_TYPES: |
143 | | -policy_tags=PolicyTagList() |
| 156 | +policy_tags=cls._determine_policy_tags( |
| 157 | +field_type,PolicyTagList.from_api_repr(api_repr.get("policyTags")) |
| 158 | + ) |
144 | 159 |
|
145 | 160 | returncls( |
146 | 161 | field_type=field_type, |
|