@@ -254,6 +254,59 @@ def test_to_standard_sql_struct_type(self):
254254 standard_field = schema_field .to_standard_sql ()
255255 self .assertEqual (standard_field , expected_result )
256256
257+ def test_to_standard_sql_array_type_simple (self ):
258+ from google .cloud .bigquery_v2 import types
259+
260+ sql_type = self ._get_standard_sql_data_type_class ()
261+
262+ # construct expected result object
263+ expected_sql_type = sql_type (type_kind = sql_type .ARRAY )
264+ expected_sql_type .array_element_type .type_kind = sql_type .INT64
265+ expected_result = types .StandardSqlField (
266+ name = "valid_numbers" , type = expected_sql_type
267+ )
268+
269+ # construct "repeated" SchemaField object and convert to standard SQL
270+ schema_field = self ._make_one ("valid_numbers" , "INT64" , mode = "REPEATED" )
271+ standard_field = schema_field .to_standard_sql ()
272+
273+ self .assertEqual (standard_field , expected_result )
274+
275+ def test_to_standard_sql_array_type_struct (self ):
276+ from google .cloud .bigquery_v2 import types
277+
278+ sql_type = self ._get_standard_sql_data_type_class ()
279+
280+ # define person STRUCT
281+ name_field = types .StandardSqlField (
282+ name = "name" , type = sql_type (type_kind = sql_type .STRING )
283+ )
284+ age_field = types .StandardSqlField (
285+ name = "age" , type = sql_type (type_kind = sql_type .INT64 )
286+ )
287+ person_struct = types .StandardSqlField (
288+ name = "person_info" , type = sql_type (type_kind = sql_type .STRUCT )
289+ )
290+ person_struct .type .struct_type .fields .extend ([name_field , age_field ])
291+
292+ # define expected result - an ARRAY of person structs
293+ expected_sql_type = sql_type (
294+ type_kind = sql_type .ARRAY , array_element_type = person_struct .type
295+ )
296+ expected_result = types .StandardSqlField (
297+ name = "known_people" , type = expected_sql_type
298+ )
299+
300+ # construct legacy repeated SchemaField object
301+ sub_field1 = self ._make_one ("name" , "STRING" )
302+ sub_field2 = self ._make_one ("age" , "INTEGER" )
303+ schema_field = self ._make_one (
304+ "known_people" , "RECORD" , fields = (sub_field1 , sub_field2 ), mode = "REPEATED"
305+ )
306+
307+ standard_field = schema_field .to_standard_sql ()
308+ self .assertEqual (standard_field , expected_result )
309+
257310 def test_to_standard_sql_unknown_type (self ):
258311 sql_type = self ._get_standard_sql_data_type_class ()
259312 field = self ._make_one ("weird_field" , "TROOLEAN" )
0 commit comments