Hi,
How do I serialize an array of primitive type in avro. Is it allowed ?
The schema I have prepared is as below and ‘pnl’ is an array of bytes.
{
"type" : "record",
"name" : "tradeDim",
"fields" : [
{
"name" : "tradeId",
"type" : "int"
},
{
"name" : "pnl",
"type" : {
"type" : "array",
"items" : "byte"
}
} ]
}
DatumWriter<GenericRecord> datumWriter = new
GenericDatumWriter<GenericRecord>(avroSchema);
DataFileWriter dataFileWriter = new DataFileWriter<GenericRecord>(datumWriter);
byte arr[] = { 1,0,5,6,7,8,9 };
Trade tradeObj = new Trade(123, arr);
GenericRecord tradeObj = new GenericData.Record(avroSchema);
tradeObj.put("tradeId", trade.tradeId);
tradeObj.put("pnl", trade.pnl);
dataFileWriter.append(tradeObj);
dataFileWriter.close();
class Trade {
int tradeId;
byte[] pnl;
public Trade(int tradeId, byte[] pnl) { this.tradeId = tradeId; this.pnl =
pnl; }
}
The error message seems to indicate that it is expecting a collection.
org.apache.avro.file.DataFileWriter$AppendWriteException:
java.lang.ClassCastException: [B cannot be cast to java.util.Collection
-regards
Seemanto Barua
212.298.4097
PLEASE READ: This message is for the named person's use only. It may contain
confidential, proprietary or legally privileged information. No confidentiality
or privilege is waived or lost by any mistransmission. If you receive this
message in error, please delete it and all copies from your system, destroy any
hard copies and notify the sender. You must not, directly or indirectly, use,
disclose, distribute, print, or copy any part of this message if you are not
the intended recipient. Nomura Holding America Inc., Nomura Securities
International, Inc, and their respective subsidiaries each reserve the right to
monitor all e-mail communications through its networks. Any views expressed in
this message are those of the individual sender, except where the message
states otherwise and the sender is authorized to state the views of such
entity. Unless otherwise stated, any pricing information in this message is
indicative only, is subject to change and does not constitute an offer to deal
at any price quoted. Any reference to the terms of executed transactions should
be treated as preliminary only and subject to our formal written confirmation.