自己实现了一下 https://yq.aliyun.com/articles/457392/ 菜鸟物流订单统计的例子,读 kafka 写到 RDS, RDS
表没有主键,也没有唯一键。
INSERT INTO table_out select tms_company, count(distinct order_id) as
order_cnt from
(select order_id, LAST_VALUE(tms_company) AS tms_company from dwd_table
group by order_id)
group by tms_company;
总共发送了 4 条消息,顺序如下:
1 {"order_id":1,"tms_company":"zhongtong"} 数据库1条记录: zhongtong 1
2 {"order_id":1,"tms_company":"yuantong"} 数据库1条记录: yuantong 1 (上一条记录被删除了)
3 {"order_id":2,"tms_company":"yuantong"} 数据库2条记录: yuantong 1, yuantong 2
(增加了条记录,没有删除)
4 {"order_id":2,"tms_company":"zhongtong"} 数据库4条记录: yuantong 1, yuantong 2,
yuantong 1, zhongtong 1 (增加了两条记录,没有删除)
问题一:
第 2 条消息发送后,数据库的上一条记录被删除了。我的理解这应该是 RetractStream 的功能。当我看源码
https://github.com/apache/flink/tree/master/flink-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc
这里也没有 RetractionStream 的实现,哪里的代码把他删除了呢?
问题二:
第 3 条记录来了后,直接在数据库增加了 一条 yuantong 2, 为什么没把 yuantong 1, 删除呢?
第 4 条记录来了后,又在数据库里加了两条记录,为什么也没有删除之前的呢?
谢谢,
王磊
[email protected]