Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit947f917

Browse files
committed
De-dup logic for converting None policy tags
1 parentc7b8c02 commit947f917

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

‎google/cloud/bigquery/schema.py‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Schemas for BigQuery tables / queries."""
1616

1717
importcollections
18+
fromtypingimportOptional
1819

1920
fromgoogle.cloud.bigquery_v2importtypes
2021

@@ -106,11 +107,25 @@ def __init__(
106107
self._properties["maxLength"]=max_length
107108
self._fields=tuple(fields)
108109

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()
114129

115130
@staticmethod
116131
def__get_int(api_repr,name):
@@ -138,9 +153,9 @@ def from_api_repr(cls, api_repr: dict) -> "SchemaField":
138153
description=api_repr.get("description",_DEFAULT_VALUE)
139154
fields=api_repr.get("fields", ())
140155

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+
)
144159

145160
returncls(
146161
field_type=field_type,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp