benkonz commented on code in PR #30770:
URL: https://github.com/apache/beam/pull/30770#discussion_r1544657024


##########
sdks/python/apache_beam/io/avroio.py:
##########
@@ -649,7 +684,11 @@ def beam_schema_to_avro_schema(
 def beam_type_to_avro_type(beam_type: schema_pb2.FieldType) -> _AvroSchemaType:
   type_info = beam_type.WhichOneof("type_info")
   if type_info == "atomic_type":
-    return {'type': BEAM_PRIMITIVES_TO_AVRO_PRIMITIVES[beam_type.atomic_type]}
+    avro_primitive = BEAM_PRIMITIVES_TO_AVRO_PRIMITIVES[beam_type.atomic_type]
+    if beam_type.nullable:
+      return ['null', avro_primitive]

Review Comment:
   @ahmedabu98 the `{'type': ` part of the avro schema is already added by 
[this](https://github.com/apache/beam/pull/30770/files#diff-b3f25837e1aac65e032c60b59b739f55f328ad1913e45394f5c2816d5dcf9399R716)
 line, so adding if we added `return { 'type': ['null', avro_primitive] }`, the 
final output of the function would look something like `{ type: { 'type': 
['null', 'string'] } } `.
   
   When I tested the code above, I got a `TypeError: unhashable type: 'list'` 
exception from `fastavro/_schema.pyx:475: in fastavro._schema.parse_field`. 
Maybe `return {'type': avro_primitive}` on 
[691](https://github.com/apache/beam/pull/30770/files#diff-b3f25837e1aac65e032c60b59b739f55f328ad1913e45394f5c2816d5dcf9399R691)
 should be `return avro_primitive`? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to