Generating a deduplicated event stream without a window

耗尽温柔 提交于 2019-12-11 09:11:11

问题


I'm trying to generate a stream of deduplicated events without specifying any window policy beyond that used for the deduplication. Using an output first every clause on my queries appears to have the desired effect, but not when those queries are inserting directly into a stream.

For the example given below, say that I'm trying to detect only the first honk from each car in a 4-hour window.

(define-event-type! "CarEvent"
   {:license_plate java.lang.String})

(define-event-type! "HonkEvent"
   {:volume java.lang.Integer}
   :supertypes #{"CarEvent"})

(define-variant! "HonkEventDeduplicated" "HonkEvent")

(define-statement! "context-IndividualCarContext"
  "create context IndividualCarContext partition by license_plate from CarEvent")

(define-statement! "populate-HonkEventDeduplicated"
  "context IndividualCarContext
   insert into HonkEventDeduplicated
   select * from HonkEvent
     group by license_plate
     output first every 4 hours")

However -- select * from HonkEventDeduplicated fires on every single honk event, even when the same car honks twice in a row.


回答1:


Instead of using output first every clause filtering, this can be done with the std:firstunique view:

(define-statement!
  "populate-HonkEventDeduplicated"
  "insert into HonkEventDeduplicated
  select * from HonkEvent.win:time(4 hours).std:firstunique(license_plate)")


来源:https://stackoverflow.com/questions/12310194/generating-a-deduplicated-event-stream-without-a-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!