[
https://issues.apache.org/jira/browse/FLINK-26738?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17510267#comment-17510267
]
Jianhui Dong edited comment on FLINK-26738 at 3/23/22, 3:41 AM:
----------------------------------------------------------------
"it will always create another internl state descriptor and make the default
value as null ", that's the point, the default value becomes null.
For example, when I try to execute the following code :
{code:java}
ValueStateDescriptor<Tuple2<Long, Long>> descriptor =
new ValueStateDescriptor<>(
"average", // the state name
TypeInformation.of(new TypeHint<Tuple2<Long, Long>>()
{}),
Tuple2.of(0L, 0L));
descriptor.enableTimeToLive(StateTtlConfigUtil.createTtlConfig(60000));
sum = getRuntimeContext().getState(descriptor);
{code}
the sum will be null but not Tuple2.of(0L, 0L), and when I try to invoke
sum.f0, it will cause NPE.
I tried to copy the default value to the code you referred to, but I saw that
the constructor with default value was marked as deprecated. I do not know if
flink would deprecate default value field in StateDescriptor or just deprecated
the constructor in the subclass of StateDescriptor, like ValueStateDescriptor
etc.
was (Author: lam167):
"it will always create another internl state descriptor and make the default
value as null ", that's the point, the default value becomes null.
For example, when I try to execute the following code :
{code:java}
ValueStateDescriptor<Tuple2<Long, Long>> descriptor =
new ValueStateDescriptor<>(
"average", // the state name
TypeInformation.of(new TypeHint<Tuple2<Long, Long>>()
{}),
Tuple2.of(0L, 0L));
sum = getRuntimeContext().getState(descriptor);
{code}
the sum will be null but not Tuple2.of(0L, 0L), and when I try to invoke
sum.f0, it will cause NPE.
I tried to copy the default value to the code you referred to, but I saw that
the constructor with default value was marked as deprecated. I do not know if
flink would deprecate default value field in StateDescriptor or just deprecated
the constructor in the subclass of StateDescriptor, like ValueStateDescriptor
etc.
> Default value of StateDescriptor is valid when enable state ttl config
> ----------------------------------------------------------------------
>
> Key: FLINK-26738
> URL: https://issues.apache.org/jira/browse/FLINK-26738
> Project: Flink
> Issue Type: Bug
> Components: API / Core
> Affects Versions: 1.15.0
> Reporter: Jianhui Dong
> Priority: Critical
>
> Suppose we declare a ValueState like following:
> {code:java}
> ValueStateDescriptor<Tuple2<Long, Long>> descriptor =
> new ValueStateDescriptor<>(
> "average", // the state name
> TypeInformation.of(new TypeHint<Tuple2<Long, Long>>()
> {}),
> Tuple2.of(0L, 0L));
> {code}
> and then we add state ttl config to the state:
> {code:java}
> descriptor.enableTimeToLive(StateTtlConfigUtil.createTtlConfig(60000));
> {code}
> the default value Tuple2.of(0L, 0L) will be invalid and may cause NPE.
> I don't know if this is a bug cause I see @Deprecated in the comment of the
> ValueStateDescriptor constructor with argument defaultValue:
> {code:java}
> Use {@link #ValueStateDescriptor(String, TypeSerializer)} instead and manually
> * manage the default value by checking whether the contents of the
> state is {@code null}.
> {code}
> and if we decide not to use the defaultValue field in the class
> StateDescriptor, should we add @Deprecated annotation to the field
> defaultValue?
--
This message was sent by Atlassian Jira
(v8.20.1#820001)