Use a class the implements java.util.Collection. One example would be
ArrayList<byte>.
Sam
On Tuesday, November 3, 2015 8:59 AM, "[email protected]"
<[email protected]> wrote:
<!--#yiv8669435112 _filtered #yiv8669435112 {font-family:SimSun;panose-1:2 1
6 0 3 1 1 1 1 1;} _filtered #yiv8669435112 {font-family:SimSun;panose-1:2 1 6 0
3 1 1 1 1 1;} _filtered #yiv8669435112 {font-family:Calibri;panose-1:2 15 5 2 2
2 4 3 2 4;} _filtered #yiv8669435112 {panose-1:2 1 6 0 3 1 1 1 1
1;}#yiv8669435112 #yiv8669435112 p.yiv8669435112MsoNormal, #yiv8669435112
li.yiv8669435112MsoNormal, #yiv8669435112 div.yiv8669435112MsoNormal
{margin:0in;margin-bottom:.0001pt;font-size:11.0pt;font-family:"Calibri",
"sans-serif";}#yiv8669435112 a:link, #yiv8669435112
span.yiv8669435112MsoHyperlink
{color:blue;text-decoration:underline;}#yiv8669435112 a:visited, #yiv8669435112
span.yiv8669435112MsoHyperlinkFollowed
{color:purple;text-decoration:underline;}#yiv8669435112 pre
{margin:0in;margin-bottom:.0001pt;font-size:10.0pt;font-family:"Courier
New";}#yiv8669435112 span.yiv8669435112EmailStyle17 {font-family:"Calibri",
"sans-serif";color:windowtext;}#yiv8669435112
span.yiv8669435112HTMLPreformattedChar {font-family:"Courier
New";}#yiv8669435112 .yiv8669435112MsoChpDefault {} _filtered #yiv8669435112
{margin:1.0in 1.0in 1.0in 1.0in;}#yiv8669435112 div.yiv8669435112WordSection1
{}-->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.