【问题标题】:Why are all elements printed although they are the same in mapWithState为什么所有元素都打印出来,尽管它们在 mapWithState 中是相同的
【发布时间】:2016-07-01 19:35:21
【问题描述】:

我正在向 JavaPairDStream 发送 3 次相同的对象。我正在更新它的状态,但它保存了 3 次。打印 JavaPairDStream 可以确认这一点。

Function3<InputMessageKey, Optional<InputMessage>, State<InputMessage>, Tuple2<InputMessageKey, InputMessage>> mappingFunction = new Function3<InputMessageKey, Optional<InputMessage>, State<InputMessage>, Tuple2<InputMessageKey, InputMessage>>() {
        @Override
        public Tuple2<InputMessageKey, InputMessage> call(InputMessageKey key, Optional<InputMessage> value, State<InputMessage> state) {
            InputMessage inputMessage = value.get();
            Tuple2<InputMessageKey, InputMessage> output = new Tuple2<>(key, inputMessage);
            state.update(inputMessage);
            return output;
        }
    };

打印流:

(com.input.InputMessageKey@220593a0,com.input.InputMessage@781bfd72)
(com.input.InputMessageKey@220593a0,com.input.InputMessage@781bfd72)
(com.input.InputMessageKey@220593a0,com.input.InputMessage@781bfd72)

【问题讨论】:

    标签: java apache-spark apache-kafka spark-streaming


    【解决方案1】:

    它没有保存三次。您将返回在函数末尾创建的 Tuple2 对象,这就是正在打印的内容。如果您想查看已保存的内部状态,请在图表中使用JavaMapWithStateDStream.stateSnapshots,而不是迭代mapWithState 的输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-28
      • 2012-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-03
      • 2012-10-29
      • 1970-01-01
      相关资源
      最近更新 更多