我在数据流 2.1 SDK 中有一个简单的管道。它从 pubsub 读取数据,然后对其应用 DoFn。
PCollection<MyClass> e = streamData.apply("ToE", ParDo.of(new MyDoFNClass()));
在此管道上出现以下错误:
java.lang.IllegalStateException: Unable to return a default Coder for ToEvents/ParMultiDo(MyDoFNClass).out0 [PCollection]. Correct one of the following root causes: No Coder has been manually specified; you may do so using .setCoder(). Inferring a Coder from the CoderRegistry failed: Unable to provide a Coder for com.X.X.model.MyClass.
MyDoFn 类如下:
@DefaultCoder(AvroCoder.class)
public class MyClass{
public long id;
public HashMap<String,HashSet<String>> a;
@SerializedName("a")
public Integer Id;
@SerializedName("ae")
public String ae;
}
最佳答案
找到解决方案只需要将 implements Serializable
添加到 MyClass
@DefaultCoder(AvroCoder.class)
public class MyClass implements Serializable {
public long id;
public HashMap<String,HashSet<String>> a;
@SerializedName("a")
public Integer Id;
@SerializedName("ae")
public String ae;
}
关于java.lang.IllegalStateException : Unable to return a default Coder in dataflow 2. X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47706013/