目录
DataStream API(函数编程)
window Join
join
对处于同一窗口的数据进行join
时间类型:processTime、eventTime
问题:1、不在同一窗口的数据无法join,
2、只能inner join
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.streaming.api.windowing.assigners.SlidingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
...
DataStream<Integer> orangeStream = ...
DataStream<Integer> greenStream = ...
orangeStream.join(greenStream)
.where(<KeySelector>) // 左侧key值
.equalTo(<KeySelector>) // 右侧key值
.window(SlidingEventTimeWindows.of(Time.milliseconds(2) /* size */, Time.milliseconds(1) /* slide */)) // 开窗方式 tumbing/sliding/session
.apply (new JoinFunction<Integer, Integer, String> (){
@Override
public String join(Integer first, Integer second) {
return first + "," + second;
}
});
coGroup
coGroup是join的底层方法,通过coGroup可以实现inner/left/right/full 四种join
时间类型:processTime、eventTime
问题:不在同一窗口的数据无法join
latedata.coGroup(stream)
.where(a->a.getStr("a"))
.equalTo(a->a.getStr("a"))
.window(TumblingEventTimeWindows.of(Time.seconds(10)))
.apply(new CoGroupFunction<JSONObject, JSONObject, Object>() {
@Override
public void coGroup(Iterable<JSONObject> iterable, Iterable<JSONObject> iterable1, Collector<Object> collector) throws Exception {
}
})
interval Join
为了解决window join的问题

本文详细介绍了 Apache Flink 中双流 Join 的多种方法,包括 windowJoin、join、coGroup 和 intervalJoin 在 DataStream API 中的应用,以及 Table API 下的 Regular Join、interval join 和 lookup join 的使用技巧。探讨了各种 Join 方法的特点、限制及适用场景。

最低0.47元/天 解锁文章
3181





