Search in sources :

Example 1 with UnionStateInputFormat

use of org.apache.flink.state.api.input.UnionStateInputFormat in project flink by apache.

the class ExistingSavepoint method readUnionState.

/**
 * Read operator {@code UnionState} from a {@code Savepoint} when a custom serializer was used;
 * e.g., a different serializer than the one returned by {@code
 * TypeInformation#createSerializer}.
 *
 * @param uid The uid of the operator.
 * @param name The (unique) name for the state.
 * @param typeInfo The type of the elements in the state.
 * @param serializer The serializer used to write the elements into state.
 * @param <T> The type of the values that are in the union state.
 * @return A {@code DataSet} representing the elements in state.
 * @throws IOException If the savepoint path is invalid or the uid does not exist.
 */
public <T> DataSource<T> readUnionState(String uid, String name, TypeInformation<T> typeInfo, TypeSerializer<T> serializer) throws IOException {
    OperatorState operatorState = metadata.getOperatorState(uid);
    ListStateDescriptor<T> descriptor = new ListStateDescriptor<>(name, serializer);
    UnionStateInputFormat<T> inputFormat = new UnionStateInputFormat<>(operatorState, env.getConfiguration(), stateBackend, descriptor);
    return env.createInput(inputFormat, typeInfo);
}
Also used : ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) UnionStateInputFormat(org.apache.flink.state.api.input.UnionStateInputFormat)

Example 2 with UnionStateInputFormat

use of org.apache.flink.state.api.input.UnionStateInputFormat in project flink by apache.

the class SavepointReader method readUnionState.

/**
 * Read operator {@code UnionState} from a {@code Savepoint} when a custom serializer was used;
 * e.g., a different serializer than the one returned by {@code
 * TypeInformation#createSerializer}.
 *
 * @param uid The uid of the operator.
 * @param name The (unique) name for the state.
 * @param typeInfo The type of the elements in the state.
 * @param serializer The serializer used to write the elements into state.
 * @param <T> The type of the values that are in the union state.
 * @return A {@code DataStream} representing the elements in state.
 * @throws IOException If the savepoint path is invalid or the uid does not exist.
 */
public <T> DataStream<T> readUnionState(String uid, String name, TypeInformation<T> typeInfo, TypeSerializer<T> serializer) throws IOException {
    OperatorState operatorState = metadata.getOperatorState(uid);
    ListStateDescriptor<T> descriptor = new ListStateDescriptor<>(name, serializer);
    UnionStateInputFormat<T> inputFormat = new UnionStateInputFormat<>(operatorState, MutableConfig.of(env.getConfiguration()), stateBackend, descriptor);
    return SourceBuilder.fromFormat(env, inputFormat, typeInfo);
}
Also used : ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) UnionStateInputFormat(org.apache.flink.state.api.input.UnionStateInputFormat)

Example 3 with UnionStateInputFormat

use of org.apache.flink.state.api.input.UnionStateInputFormat in project flink by apache.

the class ExistingSavepoint method readUnionState.

/**
 * Read operator {@code UnionState} from a {@code Savepoint}.
 *
 * @param uid The uid of the operator.
 * @param name The (unique) name for the state.
 * @param typeInfo The type of the elements in the state.
 * @param <T> The type of the values that are in the union state.
 * @return A {@code DataSet} representing the elements in state.
 * @throws IOException If the savepoint path is invalid or the uid does not exist.
 */
public <T> DataSource<T> readUnionState(String uid, String name, TypeInformation<T> typeInfo) throws IOException {
    OperatorState operatorState = metadata.getOperatorState(uid);
    ListStateDescriptor<T> descriptor = new ListStateDescriptor<>(name, typeInfo);
    UnionStateInputFormat<T> inputFormat = new UnionStateInputFormat<>(operatorState, env.getConfiguration(), stateBackend, descriptor);
    return env.createInput(inputFormat, typeInfo);
}
Also used : ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) UnionStateInputFormat(org.apache.flink.state.api.input.UnionStateInputFormat)

Example 4 with UnionStateInputFormat

use of org.apache.flink.state.api.input.UnionStateInputFormat in project flink by apache.

the class SavepointReader method readUnionState.

/**
 * Read operator {@code UnionState} from a {@code Savepoint}.
 *
 * @param uid The uid of the operator.
 * @param name The (unique) name for the state.
 * @param typeInfo The type of the elements in the state.
 * @param <T> The type of the values that are in the union state.
 * @return A {@code DataStream} representing the elements in state.
 * @throws IOException If the savepoint path is invalid or the uid does not exist.
 */
public <T> DataStream<T> readUnionState(String uid, String name, TypeInformation<T> typeInfo) throws IOException {
    OperatorState operatorState = metadata.getOperatorState(uid);
    ListStateDescriptor<T> descriptor = new ListStateDescriptor<>(name, typeInfo);
    UnionStateInputFormat<T> inputFormat = new UnionStateInputFormat<>(operatorState, MutableConfig.of(env.getConfiguration()), stateBackend, descriptor);
    return SourceBuilder.fromFormat(env, inputFormat, typeInfo);
}
Also used : ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) UnionStateInputFormat(org.apache.flink.state.api.input.UnionStateInputFormat)

Aggregations

ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)4 OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)4 UnionStateInputFormat (org.apache.flink.state.api.input.UnionStateInputFormat)4