1313# limitations under the License.
1414
1515from google .cloud import bigquery
16+ from google .cloud .bigquery .enums import RoundingMode
1617from google .cloud .bigquery .standard_sql import StandardSqlStructType
1718from google .cloud .bigquery .schema import (
1819 PolicyTagList ,
@@ -52,9 +53,12 @@ def test_constructor_defaults(self):
5253 self .assertEqual (field .fields , ())
5354 self .assertIsNone (field .policy_tags )
5455 self .assertIsNone (field .default_value_expression )
56+ self .assertEqual (field .rounding_mode , None )
57+ self .assertEqual (field .foreign_type_definition , None )
5558
5659 def test_constructor_explicit (self ):
5760 FIELD_DEFAULT_VALUE_EXPRESSION = "This is the default value for this field"
61+ ROUNDINGMODE = RoundingMode .ROUNDING_MODE_UNSPECIFIED
5862 field = self ._make_one (
5963 "test" ,
6064 "STRING" ,
@@ -67,6 +71,8 @@ def test_constructor_explicit(self):
6771 )
6872 ),
6973 default_value_expression = FIELD_DEFAULT_VALUE_EXPRESSION ,
74+ rounding_mode = ROUNDINGMODE ,
75+ foreign_type_definition = "INTEGER" ,
7076 )
7177 self .assertEqual (field .name , "test" )
7278 self .assertEqual (field .field_type , "STRING" )
@@ -83,9 +89,16 @@ def test_constructor_explicit(self):
8389 )
8490 ),
8591 )
92+ self .assertEqual (field .rounding_mode , ROUNDINGMODE .name )
93+ self .assertEqual (field .foreign_type_definition , "INTEGER" )
8694
8795 def test_constructor_explicit_none (self ):
88- field = self ._make_one ("test" , "STRING" , description = None , policy_tags = None )
96+ field = self ._make_one (
97+ "test" ,
98+ "STRING" ,
99+ description = None ,
100+ policy_tags = None ,
101+ )
89102 self .assertIsNone (field .description )
90103 self .assertIsNone (field .policy_tags )
91104
@@ -141,10 +154,18 @@ def test_to_api_repr(self):
141154 policy .to_api_repr (),
142155 {"names" : ["foo" , "bar" ]},
143156 )
157+ ROUNDINGMODE = RoundingMode .ROUNDING_MODE_UNSPECIFIED
144158
145159 field = self ._make_one (
146- "foo" , "INTEGER" , "NULLABLE" , description = "hello world" , policy_tags = policy
160+ "foo" ,
161+ "INTEGER" ,
162+ "NULLABLE" ,
163+ description = "hello world" ,
164+ policy_tags = policy ,
165+ rounding_mode = ROUNDINGMODE ,
166+ foreign_type_definition = "INTEGER" ,
147167 )
168+
148169 self .assertEqual (
149170 field .to_api_repr (),
150171 {
@@ -153,6 +174,8 @@ def test_to_api_repr(self):
153174 "type" : "INTEGER" ,
154175 "description" : "hello world" ,
155176 "policyTags" : {"names" : ["foo" , "bar" ]},
177+ "roundingMode" : "ROUNDING_MODE_UNSPECIFIED" ,
178+ "foreignTypeDefinition" : "INTEGER" ,
156179 },
157180 )
158181
@@ -186,6 +209,8 @@ def test_from_api_repr(self):
186209 "description" : "test_description" ,
187210 "name" : "foo" ,
188211 "type" : "record" ,
212+ "roundingMode" : "ROUNDING_MODE_UNSPECIFIED" ,
213+ "foreignTypeDefinition" : "INTEGER" ,
189214 }
190215 )
191216 self .assertEqual (field .name , "foo" )
@@ -197,6 +222,8 @@ def test_from_api_repr(self):
197222 self .assertEqual (field .fields [0 ].field_type , "INTEGER" )
198223 self .assertEqual (field .fields [0 ].mode , "NULLABLE" )
199224 self .assertEqual (field .range_element_type , None )
225+ self .assertEqual (field .rounding_mode , "ROUNDING_MODE_UNSPECIFIED" )
226+ self .assertEqual (field .foreign_type_definition , "INTEGER" )
200227
201228 def test_from_api_repr_policy (self ):
202229 field = self ._get_target_class ().from_api_repr (
@@ -1117,7 +1144,17 @@ def test_to_api_repr_parameterized(field, api):
11171144
11181145
11191146class TestForeignTypeInfo :
1120- """TODO: add doc string."""
1147+ """Tests metadata re: the foreign data type definition in field schema.
1148+
1149+ Specifies the system which defines the foreign data type.
1150+
1151+ TypeSystems are external systems, such as query engines or table formats,
1152+ that have their own data types.
1153+
1154+ TypeSystem may be:
1155+ TypeSystem not specified: TYPE_SYSTEM_UNSPECIFIED
1156+ Represents Hive data types: HIVE
1157+ """
11211158
11221159 @staticmethod
11231160 def _get_target_class ():
0 commit comments