如何在Apache Flink中连接两个流 [英] How to concatenate two streams in Apache Flink

查看:415
本文介绍了如何在Apache Flink中连接两个流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我想在单个中组成1, 2, 34, 5的流,因此结果应该是:1, 2, 3, 4, 5.换句话说:如果第一个来源已用尽,请从第二个来源获取元素.我最接近的尝试是

不幸的是,该尝试并没有保留商品的顺序,

E.g. i want to compose stream of 1, 2, 3 and 4, 5 in single one, so result should be: 1, 2, 3, 4, 5. In other words: if first source is exhausted - get elements from second one. My closest attempt, which unfortunately does not preserve items order, is:

val a = streamEnvironment.fromElements(1, 2, 3)

val b = streamEnvironment.fromElements(4, 5)

val c = a.union(b)

c.map(x => println(s"X=$x")) // X=4, 5, 1, 2, 3 or something like that

也进行了类似的尝试,包括日期时间,但结果相同.

Also did similar attempt with datetime included, but with same result.

推荐答案

目前无法实现,至少在高级DataStream API中无法实现.

This is not possible right now, at least not with the high level DataStream API.

可能有可能实现一个低级运算符,该运算符首先读取输入,然后读取其他输入.但是,这将完全阻止一个输入,这与Flink处理水印和执行检查点的方式不能很好地配合.

It might be possible to implement a low-level operator that first reads on input and then the other input. However, this will completely block one input which does not work well with the way that Flink handles watermarks and performs checkpoints.

将来,将可以使用所谓的侧面输入.

In the future, this will be possible using so-called side inputs.

这篇关于如何在Apache Flink中连接两个流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆