TTL设置

image.png
最佳实践:显示要用请配置State TTL Config,在精确性和大小之间的权衡。

  1. streamQueryConfig.withIdleStateRetentionTime(Time.day(1), Time.day(2))

Group Windows

  1. TUMBLE(t, INTERVAL '2' HOUR)
  2. HOP(t, INTERVAL '2' HOUR, INTERVAL '1' HOUR)
  3. SESSION(t, INTERVAL '30' MINUTE)
  1. SELECT user, TUMBLE_END(ctime, INTERVAL '1' HOURS) AS end_time, COUNT(url) AS cnt
  2. FROM click GROUP BY user TUMBLE(ctime, INTERVAL '1' HOURS);

Group Aggregation

每来一条都更新一次结果。后面最好接幂等Sink,MySQL和HBase这类。要不然会出现一大堆历史数据(可能根本不需要)。

  1. SELECT user, COUNT(url) as cnt FROM click GROUP BY user;
  1. INSERT INTO sink
  2. SELECT * FROM source;

Over Window

https://help.aliyun.com/document_detail/62514.html?spm=a2c4g.11186623.6.765.613260bcR4TzE4

SQL 子句优先级

image.png