@@ -206,6 +206,43 @@ def test_avro_union_type_to_beam_type_with_string_long(self):
206206 expected_beam_type = schemas .typing_to_runner_api (Any )
207207 hc .assert_that (beam_type , hc .equal_to (expected_beam_type ))
208208
209+ def test_avro_union_type_to_beam_type_with_record_and_null (self ):
210+ record_type = {
211+ 'type' : 'record' ,
212+ 'name' : 'TestRecord' ,
213+ 'fields' : [{
214+ 'name' : 'field1' , 'type' : 'string'
215+ }, {
216+ 'name' : 'field2' , 'type' : 'int'
217+ }]
218+ }
219+ union_type = [record_type , 'null' ]
220+ beam_type = avro_union_type_to_beam_type (union_type )
221+ expected_beam_type = schemas .typing_to_runner_api (Any )
222+ hc .assert_that (beam_type , hc .equal_to (expected_beam_type ))
223+
224+ def test_avro_union_type_to_beam_type_with_nullable_annotated_string (self ):
225+ annotated_string_type = {"avro.java.string" : "String" , "type" : "string" }
226+ union_type = ['null' , annotated_string_type ]
227+
228+ beam_type = avro_union_type_to_beam_type (union_type )
229+
230+ expected_beam_type = schema_pb2 .FieldType (
231+ atomic_type = schema_pb2 .STRING , nullable = True )
232+ hc .assert_that (beam_type , hc .equal_to (expected_beam_type ))
233+
234+ def test_avro_union_type_to_beam_type_with_only_null (self ):
235+ union_type = ['null' ]
236+ beam_type = avro_union_type_to_beam_type (union_type )
237+ expected_beam_type = schemas .typing_to_runner_api (Any )
238+ hc .assert_that (beam_type , hc .equal_to (expected_beam_type ))
239+
240+ def test_avro_union_type_to_beam_type_with_multiple_types (self ):
241+ union_type = ['null' , 'string' , 'int' ]
242+ beam_type = avro_union_type_to_beam_type (union_type )
243+ expected_beam_type = schemas .typing_to_runner_api (Any )
244+ hc .assert_that (beam_type , hc .equal_to (expected_beam_type ))
245+
209246 def test_avro_schema_to_beam_and_back (self ):
210247 avro_schema = fastavro .parse_schema (json .loads (self .SCHEMA_STRING ))
211248 beam_schema = avro_schema_to_beam_schema (avro_schema )
0 commit comments