简体   繁体   中英

Apache Beam that uses time as an input

I'm looking to create a Beam input that executes every second and just outputs the time as an input. I know I can do a pcollection that is from numbers like this

p.apply(Create.of(1, 2, 3, 4, 5))
        .setCoder(VarIntCoder.of())

and I could just create a really large array of numbers and window them to be every second, but is there a better way to do this? Thanks.

Figured out that this can be done with GenerateSequence for bounded or unbounded sets. In order to get 1 data point out per second, I can use the withRate function and if I don't include a "to" then my pcollection will be unbounded.

p.apply(GenerateSequence.from(0).withRate(1, new Duration(1000)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM