Spark流,如何将不同的流合并为一个流

时间:2014-08-21 17:36:09

标签: java apache-spark

我是新手,现在我想将两个流转换为一起,例如JavaNetworkWordCount 例如,我收到两个不同的流:

JavaStreamingContext jssc = new JavaStreamingContext("local[2]", "JavaNetworkWordCount",new Duration(1000));
JavaReceiverInputDStream<String> lines1 = jssc.socketTextStream(ip1, port1);
JavaReceiverInputDStream<String> lines2 = jssc.socketTextStream(ip2, port2);
//can I union them like this in one driver program:
JavaDStream<String> words = lines1.union(lines2);
words = lines.flatMap(
  new FlatMapFunction<String, String>() {
    @Override public Iterable<String> call(String x) {
      return Arrays.asList(x.split(" "));
    }
  });
</code>

然后进行其他转换和动作。我测试了它并且失败了。 我曾阅读过spark文档,找不到一个例子。

1 个答案:

答案 0 :(得分:2)