Hi Max,

you can use keyed state on an operator with parallelism 1 if you assign a
default key with a KeySelector:

stream.keyBy(new NullByteKeySelector)

with NullByteKeySelector defined as

public class NullByteKeySelector<T> implements KeySelector<T, Byte> {

   private static final long serialVersionUID = 614256539098549020L;

   public Byte getKey(T value) throws Exception {
      return 0;

With this trick, all records are assigned to the same key and you can use
keyed state and timers.

Best, Fabian

2018-02-13 9:59 GMT+01:00 m@xi <makisnt...@gmail.com>:

> Hello XingCan,
> Finally, I did it with union.
> Now inside the processElement() function of my CoProcessFunction I am
> setting a timer and periodically I want to print out some data through the
> onTimer() function.
> Below I attach the image stating the following: "Caused by:
> java.lang.UnsupportedOperationException: Setting timers is only supported
> on
> a keyed streams."
> <http://apache-flink-user-mailing-list-archive.2336050.
> n4.nabble.com/file/t1161/Screen_Shot_2018-02-13_at_16.png>
> My CoProcessFunction is an operator with parallelism=1 (I also use
> forceNonParallel()) to make sure about that. Thus, I am not using a Keyed
> State.
> Is the Keyed State the only way of using Timers?
> Furthermore, I must confess that the API is not so clear for the Managed
> Operator State, so I am currently NOT implementing any CheckpointedFunction
> etc etc.
> Is my application going to return the correct results, if I assume no
> failures etc etc.?
> Thanks in advance.
> Best,
> Max
> --
> Sent from: http://apache-flink-user-mailing-list-archive.2336050.
> n4.nabble.com/

Reply via email to