S
- The type of the State objects created from this StateDescriptor
.T
- The type of the value of the state object described by this state descriptor.@PublicEvolving public abstract class StateDescriptor<S extends State,T> extends Object implements Serializable
StateDescriptor
is used for creating partitioned
State
in stateful operations.
Subclasses must correctly implement equals(Object)
and hashCode()
.
Modifier and Type | Class and Description |
---|---|
static class |
StateDescriptor.Type
An enumeration of the types of supported states.
|
Modifier and Type | Field and Description |
---|---|
protected T |
defaultValue
Deprecated.
To make the semantics more clear, user should manually manage the default value
if the contents of the state is
null |
protected String |
name
Name that uniquely identifies state created from this StateDescriptor.
|
Modifier | Constructor and Description |
---|---|
protected |
StateDescriptor(String name,
Class<T> type,
T defaultValue)
Create a new
StateDescriptor with the given name and the given type information. |
protected |
StateDescriptor(String name,
TypeInformation<T> typeInfo,
T defaultValue)
Create a new
StateDescriptor with the given name and the given type information. |
protected |
StateDescriptor(String name,
TypeSerializer<T> serializer,
T defaultValue)
Create a new
StateDescriptor with the given name and the given type serializer. |
Modifier and Type | Method and Description |
---|---|
void |
enableTimeToLive(StateTtlConfig ttlConfig)
Configures optional activation of state time-to-live (TTL).
|
boolean |
equals(Object o) |
T |
getDefaultValue()
Returns the default value.
|
String |
getName()
Returns the name of this
StateDescriptor . |
String |
getQueryableStateName()
Deprecated.
The Queryable State feature is deprecated since Flink 1.18, and will be removed
in a future Flink major version.
|
TypeSerializer<T> |
getSerializer()
Returns the
TypeSerializer that can be used to serialize the value in the state. |
StateTtlConfig |
getTtlConfig() |
abstract StateDescriptor.Type |
getType() |
int |
hashCode() |
void |
initializeSerializerUnlessSet(ExecutionConfig executionConfig)
Initializes the serializer, unless it has been initialized before.
|
boolean |
isQueryable()
Deprecated.
The Queryable State feature is deprecated since Flink 1.18, and will be removed
in a future Flink major version.
|
boolean |
isSerializerInitialized()
Checks whether the serializer has been initialized.
|
void |
setQueryable(String queryableStateName)
Deprecated.
The Queryable State feature is deprecated since Flink 1.18, and will be removed
in a future Flink major version.
|
String |
toString() |
protected final String name
@Nullable @Deprecated protected transient T defaultValue
null
protected StateDescriptor(String name, TypeSerializer<T> serializer, @Nullable T defaultValue)
StateDescriptor
with the given name and the given type serializer.name
- The name of the StateDescriptor
.serializer
- The type serializer for the values in the state.defaultValue
- The default value that will be set when requesting state without setting
a value before.protected StateDescriptor(String name, TypeInformation<T> typeInfo, @Nullable T defaultValue)
StateDescriptor
with the given name and the given type information.name
- The name of the StateDescriptor
.typeInfo
- The type information for the values in the state.defaultValue
- The default value that will be set when requesting state without setting
a value before.protected StateDescriptor(String name, Class<T> type, @Nullable T defaultValue)
StateDescriptor
with the given name and the given type information.
If this constructor fails (because it is not possible to describe the type via a class),
consider using the StateDescriptor(String, TypeInformation, Object)
constructor.
name
- The name of the StateDescriptor
.type
- The class of the type of values in the state.defaultValue
- The default value that will be set when requesting state without setting
a value before.public String getName()
StateDescriptor
.public T getDefaultValue()
public TypeSerializer<T> getSerializer()
TypeSerializer
that can be used to serialize the value in the state. Note
that the serializer may initialized lazily and is only guaranteed to exist after calling
initializeSerializerUnlessSet(ExecutionConfig)
.@Deprecated public void setQueryable(String queryableStateName)
If a name is set, the created state will be published for queries during runtime. The name needs to be unique per job. If there is another state instance published under the same name, the job will fail during runtime.
queryableStateName
- State name for queries (unique name per job)IllegalStateException
- If queryable state name already set@Nullable @Deprecated public String getQueryableStateName()
null
if not set.@Deprecated public boolean isQueryable()
true
if state is queryable, false
otherwise.public void enableTimeToLive(StateTtlConfig ttlConfig)
State user value will expire, become unavailable and be cleaned up in storage depending on
configured StateTtlConfig
.
If enabling the TTL configuration, the field defaultValue
will be
invalid.
ttlConfig
- configuration of state TTL@Nonnull @Internal public StateTtlConfig getTtlConfig()
public boolean isSerializerInitialized()
ExecutionConfig
via initializeSerializerUnlessSet(ExecutionConfig)
.public void initializeSerializerUnlessSet(ExecutionConfig executionConfig)
executionConfig
- The execution config to use when creating the serializer.public abstract StateDescriptor.Type getType()
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.