我在flink项目中具有以下代码:
public class Test {
public static void main(String[] args) throws Exception {
// set up the execution environment
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Event> events =
env.readCsvFile(args[0]).pojoType(
Event.class,
"time",
"vid",
"speed",
"xWay",
"lane",
"dir",
"seg",
"pos"
);
System.out.println("----> " + events.count());
}
}
这是Event
类:
class Event {
public int time;
public int vid;
public int speed;
public int xWay;
public int lane;
public int dir;
public int seg;
public int pos;
public Event() { }
public Event(int time_in, int vid_in, int speed_in, int xWay_in, int lane_in, int dir_in, int seg_in, int pos_in) {
this.time = time_in;
this.vid = vid_in;
this.speed = speed_in;
this.xWay = xWay_in;
this.lane = lane_in;
this.dir = dir_in;
this.seg = seg_in;
this.pos = pos_in;
}
}
项目编译,但是当我运行它时,有一个错误:
java.lang.ClassCastException: org.apache.flink.api.java.typeutils.GenericTypeInfo cannot be cast to org.apache.flink.api.java.typeutils.PojoTypeInfo
CSV文件的8个整数值在每行中被一个逗号分隔。
文档具有以下示例:
DataSet<Person>> csvInput = env.readCsvFile("hdfs:///the/CSV/file")
.pojoType(Person.class, "name", "age", "zipcode");
我不知道Pojo定义是否错了,肯定是错误的。我使用map
和readTextFile
实现了我想要的东西,但这可能更昂贵。
ClassCastException
是一个错误,将很快修复并取代了一个更有意义的例外。Event
是GenericType
,而不是PojoType
。我认为原因可能是Event
是成员类,而不是全球可访问类。添加static
修饰符应解决问题。