flink-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominik WosiƄski <wos...@gmail.com>
Subject Re: Initial value of ValueStates of primitive types
Date Fri, 17 Aug 2018 09:57:06 GMT

After you call, by default values you mean after you call :


If so, the default value will be state with *value() *of null, as described
in :

 * Returns the current value for the state. When the state is not
 * partitioned the returned value is the same for all inputs in a given
 * operator instance. If state partitioning is applied, the value returned
 * depends on the current operator input, as the operator maintains an
 * independent state for each partition.
 * <p>If you didn't specify a default value when creating the {@link
 * this will return {@code null} when to value was previously set
using {@link #update(Object)}.
 * @return The state value corresponding to the current input.
 * @throws IOException Thrown if the system cannot access the state.
T value() throws IOException;

For the *MapState* it should be an empty map with no keys present.

Funny thing is that there is an implicit conversion between null values
returned by state, so assume you have defined :

private lazy val *test*: ValueState[Boolean] =
getRuntimeContext.getState(new ValueStateDescriptor[Boolean]("test",

If you will now do :


It will indeed print the *null*.
But if You will do  :

val myTest = test.value()

It will now print *false *instead;

Best Regards,

2018-08-17 11:13 GMT+02:00 Averell <lvhuyen@gmail.com>:

> Hi,
> In Flink's documents, I couldn't find any example that uses primitive type
> when working with States. What would be the initial value of a ValueState
> of
> type Int/Boolean/...? The same question apply for MapValueState like
> [String, Int]
> Thanks and regards,
> Averell
> --
> Sent from: http://apache-flink-user-mailing-list-archive.2336050.
> n4.nabble.com/

View raw message