Generating a deduplicated event stream without a w

2019-07-29 04:53发布

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.

标签: esper
1条回答
对你真心纯属浪费
2楼-- · 2019-07-29 05:33

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)")
查看更多
登录 后发表回答