简体   繁体   English

Flink State 跨多个Transformer

[英]Flink State Across multiple Transformers

How can I access a state using the same-id across multiple transformers, for example the following stores an Order object via ValueState in OrderMapper class:我如何在多个转换器中使用相同的 ID 访问 state,例如,以下通过 OrderMapper class 中的 ValueState 存储订单 object:

env.addSource(source1()).keyBy(Order::getId).flatMap(new OrderMapper()).addSink(sink1());

Now I would like to access the same Order object via a SubOrderMapper class:现在我想通过 SubOrderMapper class 访问相同的订单 object:

env.addSource(source2()).keyBy(SubOrder::getOrderId).flatMap(new SubOrderMapper()).addSink(sink2());

Edit: Looks like it's not possible to have state maintained across multiple operators, is there a way to have one operator accept multiple inputs, lets say 5 sources?编辑:看起来不可能跨多个操作员维护 state,有没有办法让一个操作员接受多个输入,比如 5 个来源?

Take a look at CoProcessFunction看看 CoProcessFunction

To realize low-level operations on two inputs, applications can use CoProcessFunction or KeyedCoProcessFunction.要实现对两个输入的低级操作,应用程序可以使用 CoProcessFunction 或 KeyedCoProcessFunction。 This function is bound to two different inputs and gets individual calls to processElement1(...) and processElement2(...) for records from the two different inputs.此 function 绑定到两个不同的输入,并针对来自两个不同输入的记录分别调用 processElement1(...) 和 processElement2(...)。

Also side outputs might be useful for you.侧面输出也可能对您有用。 side output 侧面 output

Edit: Union operator my be an option.编辑:联合运营商我是一个选择。 Union 联盟

You can create a custom EitherOfFive class that contains one of your five different stream values (I'm assuming they are all different).您可以创建一个自定义EitherOfFive class,其中包含五个不同的 stream 值之一(我假设它们都不同)。 See Flink's Either class for the one of two case.对于两种情况之一,请参见 Flink 的Either class。

Each input stream would use a Map function that converts the input class type to an EitherOfFive type.每个输入 stream 将使用 Map function 将输入 class 类型转换为EitherOfFive类型。

There would be a getKey() method that would figure out (based on which of the five values is actually set) what key to return.将有一个getKey()方法可以确定(基于实际设置了五个值中的哪一个)要返回的键。 And then you can have a single KeyedProcessFunction that takes as input this EitherOfFive type.然后您可以有一个 KeyedProcessFunction 将此EitherOfFive类型作为输入。

If the output is always the same, then you're all set.如果 output 始终相同,那么一切就绪。 Otherwise you'll want side outputs, one per type, that feed the five different sinks.否则,您将需要侧输出,每种类型一个,为五个不同的接收器供电。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM