本文整理汇总了Java中org.apache.flink.api.common.state.ValueStateDescriptor类的典型用法代码示例。如果您正苦于以下问题:Java ValueStateDescriptor类的具体用法?Java ValueStateDescriptor怎么用?Java ValueStateDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ValueStateDescriptor类属于org.apache.flink.api.common.state包,在下文中一共展示了ValueStateDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
@Override
public void open(Configuration config) {
ValueStateDescriptor<AbstractStatisticsWrapper<AisMessage>> descriptor =
new ValueStateDescriptor<AbstractStatisticsWrapper<AisMessage>>("trajectoryStatistics",
TypeInformation.of(new TypeHint<AbstractStatisticsWrapper<AisMessage>>() {}));
statisticsOfTrajectory = getRuntimeContext().getState(descriptor);
}
示例2: open
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
/**
* Override open from RichFunctions set
* This method allow the retrieval of the state and set it as queryable
*/
@Override
@SuppressWarnings("unchecked")
public void open(Configuration config) {
ValueStateDescriptor descriptor =
new ValueStateDescriptor(
"consumption",
LampConsumption.class); // default value of the state, if nothing was set
this.consumption = getRuntimeContext().getState(descriptor);
descriptor.setQueryable("consumption-list-api");
}
示例3: FlinkCombiningStateWithContext
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
FlinkCombiningStateWithContext(
KeyedStateBackend<ByteBuffer> flinkStateBackend,
StateTag<CombiningState<InputT, AccumT, OutputT>> address,
CombineWithContext.CombineFnWithContext<InputT, AccumT, OutputT> combineFn,
StateNamespace namespace,
Coder<AccumT> accumCoder,
FlinkStateInternals<K> flinkStateInternals,
CombineWithContext.Context context) {
this.namespace = namespace;
this.address = address;
this.combineFn = combineFn;
this.flinkStateBackend = flinkStateBackend;
this.flinkStateInternals = flinkStateInternals;
this.context = context;
flinkStateDescriptor = new ValueStateDescriptor<>(
address.getId(), new CoderTypeSerializer<>(accumCoder));
}
示例4: initializeState
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
@Override
public void initializeState(StateInitializationContext context) throws Exception {
super.initializeState(context);
if (nfaOperatorState == null) {
nfaOperatorState = getRuntimeContext().getState(
new ValueStateDescriptor<>(
NFA_OPERATOR_STATE_NAME,
new NFA.NFASerializer<>(inputSerializer)));
}
if (elementQueueState == null) {
elementQueueState = getRuntimeContext().getMapState(
new MapStateDescriptor<>(
EVENT_QUEUE_STATE_NAME,
LongSerializer.INSTANCE,
new ListSerializer<>(inputSerializer)
)
);
}
}
示例5: testValueStateNullAsDefaultValue
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
/**
* Verify that {@link ValueStateDescriptor} allows {@code null} as default.
*/
@Test
public void testValueStateNullAsDefaultValue() throws Exception {
AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
ValueStateDescriptor<String> kvId = new ValueStateDescriptor<>("id", String.class, null);
ValueState<String> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
backend.setCurrentKey(1);
assertNull(state.value());
state.update("Ciao");
assertEquals("Ciao", state.value());
state.clear();
assertNull(state.value());
backend.dispose();
}
示例6: testValueStateDefaultValue
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
/**
* Verify that an empty {@code ValueState} will yield the default value.
*/
@Test
public void testValueStateDefaultValue() throws Exception {
AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
ValueStateDescriptor<String> kvId = new ValueStateDescriptor<>("id", String.class, "Hello");
ValueState<String> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
backend.setCurrentKey(1);
assertEquals("Hello", state.value());
state.update("Ciao");
assertEquals("Ciao", state.value());
state.clear();
assertEquals("Hello", state.value());
backend.dispose();
}
示例7: testCopyDefaultValue
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
@Test
public void testCopyDefaultValue() throws Exception {
final AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
ValueStateDescriptor<IntValue> kvId = new ValueStateDescriptor<>("id", IntValue.class, new IntValue(-1));
ValueState<IntValue> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
backend.setCurrentKey(1);
IntValue default1 = state.value();
backend.setCurrentKey(2);
IntValue default2 = state.value();
assertNotNull(default1);
assertNotNull(default2);
assertEquals(default1, default2);
assertFalse(default1 == default2);
backend.dispose();
}
示例8: asQueryableState
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
/**
* Publishes the keyed stream as a queryable ValueState instance.
*
* @param queryableStateName Name under which to the publish the queryable state instance
* @param stateDescriptor State descriptor to create state instance from
* @return Queryable state instance
*/
@PublicEvolving
public QueryableStateStream<KEY, T> asQueryableState(
String queryableStateName,
ValueStateDescriptor<T> stateDescriptor) {
transform("Queryable state: " + queryableStateName,
getType(),
new QueryableValueStateOperator<>(queryableStateName, stateDescriptor));
stateDescriptor.initializeSerializerUnlessSet(getExecutionConfig());
return new QueryableStateStream<>(
queryableStateName,
stateDescriptor,
getKeyType().createSerializer(getExecutionConfig()));
}
示例9: open
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
@Override
public void open() throws Exception {
super.open();
if (serializedInitialValue == null) {
throw new RuntimeException("No initial value was serialized for the fold " +
"operator. Probably the setOutputType method was not called.");
}
try (ByteArrayInputStream bais = new ByteArrayInputStream(serializedInitialValue);
DataInputViewStreamWrapper in = new DataInputViewStreamWrapper(bais)) {
initialValue = outTypeSerializer.deserialize(in);
}
ValueStateDescriptor<OUT> stateId = new ValueStateDescriptor<>(STATE_NAME, outTypeSerializer);
values = getPartitionedState(stateId);
}
示例10: testValueStateInstantiation
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
@Test
public void testValueStateInstantiation() throws Exception {
final ExecutionConfig config = new ExecutionConfig();
config.registerKryoType(Path.class);
final AtomicReference<Object> descriptorCapture = new AtomicReference<>();
StreamingRuntimeContext context = new StreamingRuntimeContext(
createDescriptorCapturingMockOp(descriptorCapture, config),
createMockEnvironment(),
Collections.<String, Accumulator<?, ?>>emptyMap());
ValueStateDescriptor<TaskInfo> descr = new ValueStateDescriptor<>("name", TaskInfo.class);
context.getState(descr);
StateDescriptor<?, ?> descrIntercepted = (StateDescriptor<?, ?>) descriptorCapture.get();
TypeSerializer<?> serializer = descrIntercepted.getSerializer();
// check that the Path class is really registered, i.e., the execution config was applied
assertTrue(serializer instanceof KryoSerializer);
assertTrue(((KryoSerializer<?>) serializer).getKryo().getRegistration(Path.class).getId() > 0);
}
示例11: initializeState
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
@Override
public void initializeState(StateInitializationContext context) throws Exception {
super.initializeState(context);
if (this.engineState == null) {
this.engineState = getRuntimeContext().getState(new ValueStateDescriptor<>(ESPER_SERVICE_PROVIDER_STATE, new EsperEngineSerializer()));
}
}
示例12: open
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
@Override
public void open(Configuration config) {
ValueStateDescriptor<PriorityQueue<Tuple3<String, Long, String>>> descriptor =
new ValueStateDescriptor<>(
// state name
"sorted-raw-messages",
// type information of state
TypeInformation.of(new TypeHint<PriorityQueue<Tuple3<String, Long, String>>>() {}));
queueState = getRuntimeContext().getState(descriptor);
}
示例13: open
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
@Override
public void open(Configuration config) {
ValueStateDescriptor<Long> descriptor =
new ValueStateDescriptor<Long>("lastTimestamp", TypeInformation.of(new TypeHint<Long>() {}));
lastTimestamp = getRuntimeContext().getState(descriptor);
}
示例14: open
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
@Override
public void open(Configuration config) {
ValueStateDescriptor<PriorityQueue<AisMessage>> descriptor = new ValueStateDescriptor<>(
// state name
"sorted-ais-messages",
// type information of state
TypeInformation.of(new TypeHint<PriorityQueue<AisMessage>>() {}));
queueState = getRuntimeContext().getState(descriptor);
}
示例15: open
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入依赖的package包/类
@Override
public void open(Configuration parameters) throws Exception {
ValueStateDescriptor<EventStateMachine.State> descriptor = new ValueStateDescriptor<>(
"state", // the state name
TypeInformation.of(EventStateMachine.State.class)); // type information
state = getRuntimeContext().getState(descriptor);
}