@@ -52,6 +52,8 @@ class StandardSqlDataType:
52
52
The type of the array's elements, if type_kind is ARRAY.
53
53
struct_type:
54
54
The fields of this struct, in order, if type_kind is STRUCT.
55
+ range_element_type:
56
+ The type of the range's elements, if type_kind = "RANGE".
55
57
"""
56
58
57
59
def __init__ (
@@ -61,12 +63,14 @@ def __init__(
61
63
] = StandardSqlTypeNames .TYPE_KIND_UNSPECIFIED ,
62
64
array_element_type : Optional ["StandardSqlDataType" ] = None ,
63
65
struct_type : Optional ["StandardSqlStructType" ] = None ,
66
+ range_element_type : Optional ["StandardSqlDataType" ] = None ,
64
67
):
65
68
self ._properties : Dict [str , Any ] = {}
66
69
67
70
self .type_kind = type_kind
68
71
self .array_element_type = array_element_type
69
72
self .struct_type = struct_type
73
+ self .range_element_type = range_element_type
70
74
71
75
@property
72
76
def type_kind (self ) -> Optional [StandardSqlTypeNames ]:
@@ -127,6 +131,28 @@ def struct_type(self, value: Optional["StandardSqlStructType"]):
127
131
else :
128
132
self ._properties ["structType" ] = struct_type
129
133
134
+ @property
135
+ def range_element_type (self ) -> Optional ["StandardSqlDataType" ]:
136
+ """The type of the range's elements, if type_kind = "RANGE". Must be
137
+ one of DATETIME, DATE, or TIMESTAMP."""
138
+ range_element_info = self ._properties .get ("rangeElementType" )
139
+
140
+ if range_element_info is None :
141
+ return None
142
+
143
+ result = StandardSqlDataType ()
144
+ result ._properties = range_element_info # We do not use a copy on purpose.
145
+ return result
146
+
147
+ @struct_type .setter
148
+ def range_element_type (self , value : Optional ["StandardSqlDataType" ]):
149
+ range_element_type = None if value is None else value .to_api_repr ()
150
+
151
+ if range_element_type is None :
152
+ self ._properties .pop ("rangeElementType" , None )
153
+ else :
154
+ self ._properties ["rangeElementType" ] = range_element_type
155
+
130
156
def to_api_repr (self ) -> Dict [str , Any ]:
131
157
"""Construct the API resource representation of this SQL data type."""
132
158
return copy .deepcopy (self ._properties )
@@ -155,7 +181,13 @@ def from_api_repr(cls, resource: Dict[str, Any]):
155
181
if struct_info :
156
182
struct_type = StandardSqlStructType .from_api_repr (struct_info )
157
183
158
- return cls (type_kind , array_element_type , struct_type )
184
+ range_element_type = None
185
+ if type_kind == StandardSqlTypeNames .RANGE :
186
+ range_element_info = resource .get ("rangeElementType" )
187
+ if range_element_info :
188
+ range_element_type = cls .from_api_repr (range_element_info )
189
+
190
+ return cls (type_kind , array_element_type , struct_type , range_element_type )
159
191
160
192
def __eq__ (self , other ):
161
193
if not isinstance (other , StandardSqlDataType ):
@@ -165,6 +197,7 @@ def __eq__(self, other):
165
197
self .type_kind == other .type_kind
166
198
and self .array_element_type == other .array_element_type
167
199
and self .struct_type == other .struct_type
200
+ and self .range_element_type == other .range_element_type
168
201
)
169
202
170
203
def __str__ (self ):
0 commit comments