我实现了一个运算符,用于将avro byte[]反序列化为Object。之后,我将对象发送到ConsoleOutputOperator。
public final transient DefaultInputPort<byte[]> input = new DefaultInputPort<byte[]>() {
@Override
public void process(byte[] tuple) {
SpecificDatumReader reader = new SpecificDatumReader<T>(User.getClassSchema());
BinaryDecoder binaryDecoder = DecoderFactory.get().binaryDecoder(tuple, null);
try {
binaryDecoder.readInt();
obj = (T) reader.read(null, binaryDecoder);
} catch (IOException e) {
errorCount++;
LOG.error("Avro decoder error.");
}
if (obj != null) {
output.emit(""+obj);
recordCount++;
}else if (errorPort.isConnected()) {
errorPort.emit(obj);
errorCount++;
}
}
};
但是,我犯了这个错误。
2016-05-09 10:53:21,481 ERROR com.datatorrent.stram.engine.StreamingContainer: deploy request failed
com.esotericsoftware.kryo.KryoException: Class cannot be created (missing no-arg constructor): org.apache.avro.generic.GenericData$Array
Serialization trace:
user (com.log.avro.User)
obj (com.log.avro.AvroOperator)
at com.esotericsoftware.kryo.Kryo$DefaultInstantiatorStrategy.newInstantiatorOf(Kryo.java:1228)
at com.esotericsoftware.kryo.Kryo.newInstantiator(Kryo.java:1049)
at com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:1058)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.create(CollectionSerializer.java:89)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:93)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:22)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:679)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:106)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:528)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:679)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:106)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:528)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:761)
at com.datatorrent.common.util.FSStorageAgent.retrieve(FSStorageAgent.java:193)
at com.datatorrent.common.util.FSStorageAgent.load(FSStorageAgent.java:137)
at com.datatorrent.stram.engine.StreamingContainer.deployNodes(StreamingContainer.java:894)
at com.datatorrent.stram.engine.StreamingContainer.deploy(StreamingContainer.java:843)
at com.datatorrent.stram.engine.StreamingContainer.processHeartbeatResponse(StreamingContainer.java:801)
at com.datatorrent.stram.engine.StreamingContainer.heartbeatLoop(StreamingContainer.java:694)
at com.datatorrent.stram.engine.StreamingContainer.main(StreamingContainer.java:312)
我认为它不支持"ArrayList"。
kryo.readObject(input, ArrayList.class);
如何修复此错误?
看看:http://avro.apache.org/docs/1.8.0/api/java/org/apache/avro/generic/GenericData.html
您会注意到GenericData.Array没有Kryo序列化/反序列化所需的默认构造函数(即没有参数的构造函数)。
您可以使用注释:@DefaultSerializer(JavaSerializer.class)如果类是Java可序列化的,如中所述:library/src/main/java/com/datatorrent/lib/codec/KryoJdkContainer.java在Apex Malhar。
请查看:http://docs.datatorrent.com/troubleshooting/#application-引发以下kryo异常了解更多选项。