there is some code which runs when processElement gets called for first
time for any given key


if(state.read() == null)
{
    state.write(new Pojo());
}

rest of the code
...
Pojo a = state.read();


On Fri, Feb 18, 2022 at 3:24 PM Reuven Lax <[email protected]> wrote:

>
>
> On Fri, Feb 18, 2022 at 3:07 PM gaurav mishra <
> [email protected]> wrote:
>
>> Hi,
>> I have a stateful DoFn where I am storing a pojo. in my processElement I
>> am doing something like this -
>>
>> Pojo a = state.read();
>>
> This will return null if the state has never been written. When do you
> write the state?
>
>> .....
>> ....
>> a.setField1(123)
>> ....
>> end of function
>>
>> As you can see I don't have a state.write(a);
>>
>> when I read that statespec in my onTimer() method I get the correct value.
>>
>> Pojo a = state.read();
>> log.info(a.getField1()) // 123
>>
>> I would imagine that state.read() and state.write() are both network
>> calls. Without the .write() call statespec should have had stale data.
>> is my understanding correct wrong here wrt to read() and write() calls.
>> I was expecting log.info(a.getField1()) to print some old value here.
>>
>>
>>

Reply via email to