org.apache.flink.api.common.state.FoldingState Java Examples

The following examples show how to use org.apache.flink.api.common.state.FoldingState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that an empty {@code FoldingState} yields {@code null}.
 */
@Test
public void testFoldingStateDefaultValue() throws Exception {
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

	FoldingStateDescriptor<Integer, String> kvId =
			new FoldingStateDescriptor<>("id", "Fold-Initial:", new AppendingFold(), String.class);

	FoldingState<Integer, String> state = backend.getPartitionedState(
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE, kvId);

	backend.setCurrentKey(1);
	assertNull(state.get());

	state.add(1);
	state.add(2);
	assertEquals("Fold-Initial:,1,2", state.get());

	state.clear();
	assertNull(state.get());

	backend.dispose();
}
 
Example #2
Source File: StateBackendTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that an empty {@code FoldingState} yields {@code null}.
 */
@Test
public void testFoldingStateDefaultValue() throws Exception {
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

	FoldingStateDescriptor<Integer, String> kvId =
			new FoldingStateDescriptor<>("id", "Fold-Initial:", new AppendingFold(), String.class);

	FoldingState<Integer, String> state = backend.getPartitionedState(
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE, kvId);

	backend.setCurrentKey(1);
	assertNull(state.get());

	state.add(1);
	state.add(2);
	assertEquals("Fold-Initial:,1,2", state.get());

	state.clear();
	assertNull(state.get());

	backend.dispose();
}
 
Example #3
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that an empty {@code FoldingState} yields {@code null}.
 */
@Test
public void testFoldingStateDefaultValue() throws Exception {
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

	FoldingStateDescriptor<Integer, String> kvId =
			new FoldingStateDescriptor<>("id", "Fold-Initial:", new AppendingFold(), String.class);

	FoldingState<Integer, String> state = backend.getPartitionedState(
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE, kvId);

	backend.setCurrentKey(1);
	assertNull(state.get());

	state.add(1);
	state.add(2);
	assertEquals("Fold-Initial:,1,2", state.get());

	state.clear();
	assertNull(state.get());

	backend.dispose();
}
 
Example #4
Source File: AbstractRuntimeUDFContext.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
@PublicEvolving
@Deprecated
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	throw new UnsupportedOperationException(
			"This state is only accessible by functions executed on a KeyedStream");
}
 
Example #5
Source File: DefaultKeyedStateStore.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	requireNonNull(stateProperties, "The state properties must not be null");
	try {
		stateProperties.initializeSerializerUnlessSet(executionConfig);
		return getPartitionedState(stateProperties);
	} catch (Exception e) {
		throw new RuntimeException("Error while getting state", e);
	}
}
 
Example #6
Source File: DefaultKeyedStateStore.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	requireNonNull(stateProperties, "The state properties must not be null");
	try {
		stateProperties.initializeSerializerUnlessSet(executionConfig);
		return getPartitionedState(stateProperties);
	} catch (Exception e) {
		throw new RuntimeException("Error while getting state", e);
	}
}
 
Example #7
Source File: DefaultKeyedStateStore.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	requireNonNull(stateProperties, "The state properties must not be null");
	try {
		stateProperties.initializeSerializerUnlessSet(executionConfig);
		return getPartitionedState(stateProperties);
	} catch (Exception e) {
		throw new RuntimeException("Error while getting state", e);
	}
}
 
Example #8
Source File: SavepointRuntimeContext.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
@Deprecated
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	if (!stateRegistrationAllowed) {
		throw new RuntimeException(REGISTRATION_EXCEPTION_MSG);
	}

	registeredDescriptors.add(stateProperties);
	return keyedStateStore.getFoldingState(stateProperties);
}
 
Example #9
Source File: AbstractRuntimeUDFContext.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
@PublicEvolving
@Deprecated
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	throw new UnsupportedOperationException(
			"This state is only accessible by functions executed on a KeyedStream");
}
 
Example #10
Source File: TtlFoldingStateVerifier.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
void updateInternal(@Nonnull FoldingState<Integer, Long> state, Integer update) throws Exception {
	state.add(update);
}
 
Example #11
Source File: WindowOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <T, A> FoldingState<T, A> getFoldingState(FoldingStateDescriptor<T, A> stateProperties) {
	throw new UnsupportedOperationException("Per-window state is not allowed when using merging windows.");
}
 
Example #12
Source File: StreamingRuntimeContext.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	KeyedStateStore keyedStateStore = checkPreconditionsAndGetKeyedStateStore(stateProperties);
	stateProperties.initializeSerializerUnlessSet(getExecutionConfig());
	return keyedStateStore.getFoldingState(stateProperties);
}
 
Example #13
Source File: RichAsyncFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	throw new UnsupportedOperationException("State is not supported in rich async functions.");
}
 
Example #14
Source File: WindowOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <T, A> FoldingState<T, A> getFoldingState(FoldingStateDescriptor<T, A> stateProperties) {
	throw new UnsupportedOperationException("Per-window state is not allowed when using merging windows.");
}
 
Example #15
Source File: ReductionsTest.java    From stateful-functions with Apache License 2.0 4 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(
    FoldingStateDescriptor<T, ACC> stateProperties) {
  throw new UnsupportedOperationException();
}
 
Example #16
Source File: ReductionsTest.java    From flink-statefun with Apache License 2.0 4 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(
    FoldingStateDescriptor<T, ACC> stateProperties) {
  throw new UnsupportedOperationException();
}
 
Example #17
Source File: TestSharedBuffer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	throw new UnsupportedOperationException();
}
 
Example #18
Source File: TtlFoldingStateVerifier.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
Long getInternal(@Nonnull FoldingState<Integer, Long> state) throws Exception {
	return state.get();
}
 
Example #19
Source File: TtlFoldingStateVerifier.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
void updateInternal(@Nonnull FoldingState<Integer, Long> state, Integer update) throws Exception {
	state.add(update);
}
 
Example #20
Source File: TtlFoldingStateVerifier.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
Long getInternal(@Nonnull FoldingState<Integer, Long> state) throws Exception {
	return state.get();
}
 
Example #21
Source File: TestSharedBuffer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	throw new UnsupportedOperationException();
}
 
Example #22
Source File: CepRuntimeContext.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(final FoldingStateDescriptor<T, ACC> stateProperties) {
	throw new UnsupportedOperationException("State is not supported.");
}
 
Example #23
Source File: WindowOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public <T, A> FoldingState<T, A> getFoldingState(FoldingStateDescriptor<T, A> stateProperties) {
	throw new UnsupportedOperationException("Per-window state is not allowed when using merging windows.");
}
 
Example #24
Source File: RichAsyncFunction.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	throw new UnsupportedOperationException("State is not supported in rich async functions.");
}
 
Example #25
Source File: StreamingRuntimeContext.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	KeyedStateStore keyedStateStore = checkPreconditionsAndGetKeyedStateStore(stateProperties);
	stateProperties.initializeSerializerUnlessSet(getExecutionConfig());
	return keyedStateStore.getFoldingState(stateProperties);
}
 
Example #26
Source File: TtlFoldingStateVerifier.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
void updateInternal(@Nonnull FoldingState<Integer, Long> state, Integer update) throws Exception {
	state.add(update);
}
 
Example #27
Source File: TtlFoldingStateVerifier.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
Long getInternal(@Nonnull FoldingState<Integer, Long> state) throws Exception {
	return state.get();
}
 
Example #28
Source File: TestSharedBuffer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties) {
	throw new UnsupportedOperationException();
}
 
Example #29
Source File: CepRuntimeContext.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public <T, ACC> FoldingState<T, ACC> getFoldingState(final FoldingStateDescriptor<T, ACC> stateProperties) {
	throw new UnsupportedOperationException("State is not supported.");
}
 
Example #30
Source File: RuntimeContext.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Gets a handle to the system's key/value folding state. This state is similar to the state
 * accessed via {@link #getState(ValueStateDescriptor)}, but is optimized for state that
 * aggregates values with different types.
 *
 * <p>This state is only accessible if the function is executed on a KeyedStream.
 *
 * <pre>{@code
 * DataStream<MyType> stream = ...;
 * KeyedStream<MyType> keyedStream = stream.keyBy("id");
 *
 * keyedStream.map(new RichMapFunction<MyType, List<MyType>>() {
 *
 *     private FoldingState<MyType, Long> state;
 *
 *     public void open(Configuration cfg) {
 *         state = getRuntimeContext().getFoldingState(
 *                 new FoldingStateDescriptor<>("sum", 0L, (a, b) -> a.count() + b, Long.class));
 *     }
 *
 *     public Tuple2<MyType, Long> map(MyType value) {
 *         state.add(value);
 *         return new Tuple2<>(value, state.get());
 *     }
 * });
 *
 * }</pre>
 *
 * @param stateProperties The descriptor defining the properties of the stats.
 *
 * @param <T> Type of the values folded in the other state
 * @param <ACC> Type of the value in the state
 *
 * @return The partitioned state object.
 *
 * @throws UnsupportedOperationException Thrown, if no partitioned state is available for the
 *                                       function (function is not part of a KeyedStream).
 *
 * @deprecated will be removed in a future version in favor of {@link AggregatingState}
 */
@PublicEvolving
@Deprecated
<T, ACC> FoldingState<T, ACC> getFoldingState(FoldingStateDescriptor<T, ACC> stateProperties);