根据Kafka Streams的documentation,我们只能通过定义下限和上限来应用KStream-to-KStream连接:
KStream<String, String> joined = left.join(right,
(leftValue, rightValue) -> ... , /* ValueJoiner */
JoinWindows.of(Duration.ofMinutes(5)),
Joined.with(
Serdes.String(), /* key */
Serdes.Long(), /* left value */
Serdes.Double()) /* right value */
);
这仅连接由连接窗口的长度定义的彼此接近的元素。但是,我正在寻找可以在Flink中完成的两个翻滚窗口:
DataStream<Integer> left = ...
DataStream<Integer> right = ...
left.join(right)
.where(<LeftKeySelector>)
.equalTo(<RightKeySelector>)
.window(TumblingEventTimeWindows.of(Time.milliseconds(2)))
.apply (new JoinFunction<Integer, Integer, String> (){
@Override
public String join(Integer first, Integer second) {
return first + "," + second;
}
});