0

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.

Billy Jacobson
  • 1,608
  • 2
  • 13
  • 21

1 Answers1

2

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)))
Billy Jacobson
  • 1,608
  • 2
  • 13
  • 21