code: def write_union(self, writer_schema, datum, encoder):
      # resolve union
      index_of_schema = -1
      for i, candidate_schema in enumerate(writer_schema.schemas):
          if Validate(candidate_schema, datum):
              index_of_schema = i
      if index_of_schema < 0:
          raise AvroTypeException(writer_schema, datum)
  
      # write data
      encoder.write_int(index_of_schema)
      self.write_data(
          writer_schema.schemas[index_of_schema], datum, encoder
      )
  
imports: import struct
  from avro.io import AvroTypeException, BinaryDecoder, BinaryEncoder, DatumReader, DatumWriter, SchemaResolutionException, Validate
label_desc: Use image node_id 4 for calling the FlinkAvroDatumWriter obj's underlying member method code with example usage: obj.write_union(writer_schema, datum, encoder) without return types