在分配给KeyedStream中的组之前检查key是否为null
如果用户创建KeyedStream并按键分区(可能为null),则Flink作业将抛出
NullPointerExceptoin在运行时。但是,Flink抛出的NPE很难调试和理解
因为它不指向Flink作业中的位置。
建议:
添加前提条件,以检查密钥是否不为null,如果存在则抛出描述性错误
这是一个空值。
代码
DataStream <String> stream = env.fromCollection(Arrays.asList(“ aaa”,“ bbb”))
.map(x->(String)null)
.keyBy(x-> x); {code}
报错
Caused by: java.lang.NullPointerException
at org.apache.flink.runtime.state.KeyGroupRangeAssignment.assignToKeyGroup(KeyGroupRangeAssignment.java:59)
at org.apache.flink.runtime.state.KeyGroupRangeAssignment.assignKeyToParallelOperator(KeyGroupRangeAssignment.java:48)
at org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner.selectChannels(KeyGroupStreamPartitioner.java:63)
at org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner.selectChannels(KeyGroupStreamPartitioner.java:32)
at org.apache.flink.runtime.io.network.api.writer.RecordWriter.emit(RecordWriter.java:101)
at org.apache.flink.streaming.runtime.io.StreamRecordWriter.emit(StreamRecordWriter.java:81)
at org.apache.flink.streaming.runtime.io.RecordWriterOutput.pushToRecordWriter(RecordWriterOutput.java:107)
... 35 more
网友评论