Java Code Examples for org.apache.flink.api.java.typeutils.TypeExtractor#getUnaryOperatorReturnType()

The following examples show how to use org.apache.flink.api.java.typeutils.TypeExtractor#getUnaryOperatorReturnType() . These examples are extracted from open source projects. 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 Project: flink   File: KeyedStream.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Applies the given {@link KeyedProcessFunction} on the input stream, thereby creating a transformed output stream.
 *
 * <p>The function will be called for every element in the input streams and can produce zero
 * or more output elements. Contrary to the {@link DataStream#flatMap(FlatMapFunction)}
 * function, this function can also query the time and set timers. When reacting to the firing
 * of set timers the function can directly emit elements and/or register yet more timers.
 *
 * @param keyedProcessFunction The {@link KeyedProcessFunction} that is called for each element in the stream.
 *
 * @param <R> The type of elements emitted by the {@code KeyedProcessFunction}.
 *
 * @return The transformed {@link DataStream}.
 */
@PublicEvolving
public <R> SingleOutputStreamOperator<R> process(KeyedProcessFunction<KEY, T, R> keyedProcessFunction) {

	TypeInformation<R> outType = TypeExtractor.getUnaryOperatorReturnType(
			keyedProcessFunction,
			KeyedProcessFunction.class,
			1,
			2,
			TypeExtractor.NO_INDEX,
			getType(),
			Utils.getCallLocationName(),
			true);

	return process(keyedProcessFunction, outType);
}
 
Example 2
Source Project: Flink-CEPplus   File: PatternStream.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Applies a select function to the detected pattern sequence. For each pattern sequence the
 * provided {@link PatternSelectFunction} is called. The pattern select function can produce
 * exactly one resulting element.
 *
 * @param patternSelectFunction The pattern select function which is called for each detected
 *                              pattern sequence.
 * @param <R> Type of the resulting elements
 * @return {@link DataStream} which contains the resulting elements from the pattern select
 *         function.
 */
public <R> SingleOutputStreamOperator<R> select(final PatternSelectFunction<T, R> patternSelectFunction) {
	// we have to extract the output type from the provided pattern selection function manually
	// because the TypeExtractor cannot do that if the method is wrapped in a MapFunction

	final TypeInformation<R> returnType = TypeExtractor.getUnaryOperatorReturnType(
		patternSelectFunction,
		PatternSelectFunction.class,
		0,
		1,
		TypeExtractor.NO_INDEX,
		builder.getInputType(),
		null,
		false);

	return select(patternSelectFunction, returnType);
}
 
Example 3
Source Project: Flink-CEPplus   File: PatternStream.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Applies a flat select function to the detected pattern sequence. For each pattern sequence
 * the provided {@link PatternFlatSelectFunction} is called. The pattern flat select function
 * can produce an arbitrary number of resulting elements.
 *
 * @param patternFlatSelectFunction The pattern flat select function which is called for each
 *                                  detected pattern sequence.
 * @param <R> Type of the resulting elements
 * @return {@link DataStream} which contains the resulting elements from the pattern flat select
 *         function.
 */
public <R> SingleOutputStreamOperator<R> flatSelect(final PatternFlatSelectFunction<T, R> patternFlatSelectFunction) {
	// we have to extract the output type from the provided pattern selection function manually
	// because the TypeExtractor cannot do that if the method is wrapped in a MapFunction

	final TypeInformation<R> outTypeInfo = TypeExtractor.getUnaryOperatorReturnType(
		patternFlatSelectFunction,
		PatternFlatSelectFunction.class,
		0,
		1,
		new int[]{1, 0},
		builder.getInputType(),
		null,
		false);

	return flatSelect(patternFlatSelectFunction, outTypeInfo);
}
 
Example 4
Source Project: flink   File: PatternStream.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Applies a select function to the detected pattern sequence. For each pattern sequence the
 * provided {@link PatternSelectFunction} is called. The pattern select function can produce
 * exactly one resulting element.
 *
 * @param patternSelectFunction The pattern select function which is called for each detected
 *                              pattern sequence.
 * @param <R> Type of the resulting elements
 * @return {@link DataStream} which contains the resulting elements from the pattern select
 *         function.
 */
public <R> SingleOutputStreamOperator<R> select(final PatternSelectFunction<T, R> patternSelectFunction) {
	// we have to extract the output type from the provided pattern selection function manually
	// because the TypeExtractor cannot do that if the method is wrapped in a MapFunction

	final TypeInformation<R> returnType = TypeExtractor.getUnaryOperatorReturnType(
		patternSelectFunction,
		PatternSelectFunction.class,
		0,
		1,
		TypeExtractor.NO_INDEX,
		builder.getInputType(),
		null,
		false);

	return select(patternSelectFunction, returnType);
}
 
Example 5
Source Project: flink   File: KeyedStream.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Applies the given {@link ProcessFunction} on the input stream, thereby creating a transformed output stream.
 *
 * <p>The function will be called for every element in the input streams and can produce zero
 * or more output elements. Contrary to the {@link DataStream#flatMap(FlatMapFunction)}
 * function, this function can also query the time and set timers. When reacting to the firing
 * of set timers the function can directly emit elements and/or register yet more timers.
 *
 * @param processFunction The {@link ProcessFunction} that is called for each element
 *                      in the stream.
 *
 * @param <R> The type of elements emitted by the {@code ProcessFunction}.
 *
 * @return The transformed {@link DataStream}.
 *
 * @deprecated Use {@link KeyedStream#process(KeyedProcessFunction)}
 */
@Deprecated
@Override
@PublicEvolving
public <R> SingleOutputStreamOperator<R> process(ProcessFunction<T, R> processFunction) {

	TypeInformation<R> outType = TypeExtractor.getUnaryOperatorReturnType(
		processFunction,
		ProcessFunction.class,
		0,
		1,
		TypeExtractor.NO_INDEX,
		getType(),
		Utils.getCallLocationName(),
		true);

	return process(processFunction, outType);
}
 
Example 6
Source Project: Flink-CEPplus   File: DataStream.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Applies the given {@link ProcessFunction} on the input stream, thereby
 * creating a transformed output stream.
 *
 * <p>The function will be called for every element in the input streams and can produce zero
 * or more output elements.
 *
 * @param processFunction The {@link ProcessFunction} that is called for each element
 *                      in the stream.
 *
 * @param <R> The type of elements emitted by the {@code ProcessFunction}.
 *
 * @return The transformed {@link DataStream}.
 */
@PublicEvolving
public <R> SingleOutputStreamOperator<R> process(ProcessFunction<T, R> processFunction) {

	TypeInformation<R> outType = TypeExtractor.getUnaryOperatorReturnType(
		processFunction,
		ProcessFunction.class,
		0,
		1,
		TypeExtractor.NO_INDEX,
		getType(),
		Utils.getCallLocationName(),
		true);

	return process(processFunction, outType);
}
 
Example 7
Source Project: flink   File: PatternStream.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Applies a flat select function to the detected pattern sequence. For each pattern sequence
 * the provided {@link PatternFlatSelectFunction} is called. The pattern flat select function
 * can produce an arbitrary number of resulting elements.
 *
 * @param patternFlatSelectFunction The pattern flat select function which is called for each
 *                                  detected pattern sequence.
 * @param <R> Type of the resulting elements
 * @return {@link DataStream} which contains the resulting elements from the pattern flat select
 *         function.
 */
public <R> SingleOutputStreamOperator<R> flatSelect(final PatternFlatSelectFunction<T, R> patternFlatSelectFunction) {
	// we have to extract the output type from the provided pattern selection function manually
	// because the TypeExtractor cannot do that if the method is wrapped in a MapFunction

	final TypeInformation<R> outTypeInfo = TypeExtractor.getUnaryOperatorReturnType(
		patternFlatSelectFunction,
		PatternFlatSelectFunction.class,
		0,
		1,
		new int[]{1, 0},
		builder.getInputType(),
		null,
		false);

	return flatSelect(patternFlatSelectFunction, outTypeInfo);
}
 
Example 8
Source Project: flink   File: AllWindowedStream.java    License: Apache License 2.0 5 votes vote down vote up
private static <IN, OUT> TypeInformation<OUT> getAllWindowFunctionReturnType(
		AllWindowFunction<IN, OUT, ?> function,
		TypeInformation<IN> inType) {
	return TypeExtractor.getUnaryOperatorReturnType(
		function,
		AllWindowFunction.class,
		0,
		1,
		new int[]{2, 0},
		inType,
		null,
		false);
}
 
Example 9
Source Project: flink   File: Translate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Translate {@link Edge} values using the given {@link TranslateFunction}.
 *
 * @param edges input edges
 * @param translator implements conversion from {@code OLD} to {@code NEW}
 * @param parallelism operator parallelism
 * @param <K> vertex ID type
 * @param <OLD> old edge value type
 * @param <NEW> new edge value type
 * @return translated edges
 */
@SuppressWarnings("unchecked")
public static <K, OLD, NEW> DataSet<Edge<K, NEW>> translateEdgeValues(DataSet<Edge<K, OLD>> edges, TranslateFunction<OLD, NEW> translator, int parallelism) {
	Preconditions.checkNotNull(edges);
	Preconditions.checkNotNull(translator);

	Class<Edge<K, NEW>> edgeClass = (Class<Edge<K, NEW>>) (Class<? extends Edge>) Edge.class;
	TypeInformation<K> idType = ((TupleTypeInfo<Edge<K, OLD>>) edges.getType()).getTypeAt(0);
	TypeInformation<OLD> oldType = ((TupleTypeInfo<Edge<K, OLD>>) edges.getType()).getTypeAt(2);
	TypeInformation<NEW> newType = TypeExtractor.getUnaryOperatorReturnType(
		translator,
		TranslateFunction.class,
		0,
		1,
		new int[]{1},
		oldType,
		null,
		false);

	TupleTypeInfo<Edge<K, NEW>> returnType = new TupleTypeInfo<>(edgeClass, idType, idType, newType);

	return edges
		.map(new TranslateEdgeValue<>(translator))
		.returns(returnType)
			.setParallelism(parallelism)
			.name("Translate edge values");
}
 
Example 10
Source Project: flink   File: WindowedStream.java    License: Apache License 2.0 5 votes vote down vote up
private static <IN, OUT, KEY> TypeInformation<OUT> getWindowFunctionReturnType(
	WindowFunction<IN, OUT, KEY, ?> function,
	TypeInformation<IN> inType) {
	return TypeExtractor.getUnaryOperatorReturnType(
		function,
		WindowFunction.class,
		0,
		1,
		new int[]{3, 0},
		inType,
		null,
		false);
}
 
Example 11
Source Project: Flink-CEPplus   File: Translate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Translate {@link Vertex} values using the given {@link TranslateFunction}.
 *
 * @param vertices input vertices
 * @param translator implements conversion from {@code OLD} to {@code NEW}
 * @param parallelism operator parallelism
 * @param <K> vertex ID type
 * @param <OLD> old vertex value type
 * @param <NEW> new vertex value type
 * @return translated vertices
 */
@SuppressWarnings("unchecked")
public static <K, OLD, NEW> DataSet<Vertex<K, NEW>> translateVertexValues(DataSet<Vertex<K, OLD>> vertices, TranslateFunction<OLD, NEW> translator, int parallelism) {
	Preconditions.checkNotNull(vertices);
	Preconditions.checkNotNull(translator);

	Class<Vertex<K, NEW>> vertexClass = (Class<Vertex<K, NEW>>) (Class<? extends Vertex>) Vertex.class;
	TypeInformation<K> idType = ((TupleTypeInfo<Vertex<K, OLD>>) vertices.getType()).getTypeAt(0);
	TypeInformation<OLD> oldType = ((TupleTypeInfo<Vertex<K, OLD>>) vertices.getType()).getTypeAt(1);
	TypeInformation<NEW> newType = TypeExtractor.getUnaryOperatorReturnType(
		translator,
		TranslateFunction.class,
		0,
		1,
		new int[]{1},
		oldType,
		null,
		false);

	TupleTypeInfo<Vertex<K, NEW>> returnType = new TupleTypeInfo<>(vertexClass, idType, newType);

	return vertices
		.map(new TranslateVertexValue<>(translator))
		.returns(returnType)
			.setParallelism(parallelism)
			.name("Translate vertex values");
}
 
Example 12
Source Project: Flink-CEPplus   File: Translate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Translate {@link Edge} values using the given {@link TranslateFunction}.
 *
 * @param edges input edges
 * @param translator implements conversion from {@code OLD} to {@code NEW}
 * @param parallelism operator parallelism
 * @param <K> vertex ID type
 * @param <OLD> old edge value type
 * @param <NEW> new edge value type
 * @return translated edges
 */
@SuppressWarnings("unchecked")
public static <K, OLD, NEW> DataSet<Edge<K, NEW>> translateEdgeValues(DataSet<Edge<K, OLD>> edges, TranslateFunction<OLD, NEW> translator, int parallelism) {
	Preconditions.checkNotNull(edges);
	Preconditions.checkNotNull(translator);

	Class<Edge<K, NEW>> edgeClass = (Class<Edge<K, NEW>>) (Class<? extends Edge>) Edge.class;
	TypeInformation<K> idType = ((TupleTypeInfo<Edge<K, OLD>>) edges.getType()).getTypeAt(0);
	TypeInformation<OLD> oldType = ((TupleTypeInfo<Edge<K, OLD>>) edges.getType()).getTypeAt(2);
	TypeInformation<NEW> newType = TypeExtractor.getUnaryOperatorReturnType(
		translator,
		TranslateFunction.class,
		0,
		1,
		new int[]{1},
		oldType,
		null,
		false);

	TupleTypeInfo<Edge<K, NEW>> returnType = new TupleTypeInfo<>(edgeClass, idType, idType, newType);

	return edges
		.map(new TranslateEdgeValue<>(translator))
		.returns(returnType)
			.setParallelism(parallelism)
			.name("Translate edge values");
}
 
Example 13
Source Project: flink   File: Translate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Translate {@link Edge} IDs using the given {@link TranslateFunction}.
 *
 * @param edges input edges
 * @param translator implements conversion from {@code OLD} to {@code NEW}
 * @param parallelism operator parallelism
 * @param <OLD> old edge ID type
 * @param <NEW> new edge ID type
 * @param <EV> edge value type
 * @return translated edges
 */
@SuppressWarnings("unchecked")
public static <OLD, NEW, EV> DataSet<Edge<NEW, EV>> translateEdgeIds(DataSet<Edge<OLD, EV>> edges, TranslateFunction<OLD, NEW> translator, int parallelism) {
	Preconditions.checkNotNull(edges);
	Preconditions.checkNotNull(translator);

	Class<Edge<NEW, EV>> edgeClass = (Class<Edge<NEW, EV>>) (Class<? extends Edge>) Edge.class;
	TypeInformation<OLD> oldType = ((TupleTypeInfo<Edge<OLD, EV>>) edges.getType()).getTypeAt(0);
	TypeInformation<NEW> newType = TypeExtractor.getUnaryOperatorReturnType(
		translator,
		TranslateFunction.class,
		0,
		1,
		new int[] {1},
		oldType,
		null,
		false);
	TypeInformation<EV> edgeValueType = ((TupleTypeInfo<Edge<OLD, EV>>) edges.getType()).getTypeAt(2);

	TupleTypeInfo<Edge<NEW, EV>> returnType = new TupleTypeInfo<>(edgeClass, newType, newType, edgeValueType);

	return edges
		.map(new TranslateEdgeId<>(translator))
		.returns(returnType)
			.setParallelism(parallelism)
			.name("Translate edge IDs");
}
 
Example 14
Source Project: flink   File: WindowedStream.java    License: Apache License 2.0 5 votes vote down vote up
private static <IN, OUT, KEY> TypeInformation<OUT> getProcessWindowFunctionReturnType(
		ProcessWindowFunction<IN, OUT, KEY, ?> function,
		TypeInformation<IN> inType,
		String functionName) {
	return TypeExtractor.getUnaryOperatorReturnType(
		function,
		ProcessWindowFunction.class,
		0,
		1,
		TypeExtractor.NO_INDEX,
		inType,
		functionName,
		false);
}
 
Example 15
Source Project: Flink-CEPplus   File: AsyncDataStream.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Add an AsyncWaitOperator.
 *
 * @param in The {@link DataStream} where the {@link AsyncWaitOperator} will be added.
 * @param func {@link AsyncFunction} wrapped inside {@link AsyncWaitOperator}.
 * @param timeout for the asynchronous operation to complete
 * @param bufSize The max number of inputs the {@link AsyncWaitOperator} can hold inside.
 * @param mode Processing mode for {@link AsyncWaitOperator}.
 * @param <IN> Input type.
 * @param <OUT> Output type.
 * @return A new {@link SingleOutputStreamOperator}
 */
private static <IN, OUT> SingleOutputStreamOperator<OUT> addOperator(
		DataStream<IN> in,
		AsyncFunction<IN, OUT> func,
		long timeout,
		int bufSize,
		OutputMode mode) {

	TypeInformation<OUT> outTypeInfo = TypeExtractor.getUnaryOperatorReturnType(
		func,
		AsyncFunction.class,
		0,
		1,
		new int[]{1, 0},
		in.getType(),
		Utils.getCallLocationName(),
		true);

	// create transform
	AsyncWaitOperator<IN, OUT> operator = new AsyncWaitOperator<>(
		in.getExecutionEnvironment().clean(func),
		timeout,
		bufSize,
		mode);

	return in.transform("async wait operator", outTypeInfo, operator);
}
 
Example 16
Source Project: flink   File: PatternStream.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Applies a process function to the detected pattern sequence. For each pattern sequence the
 * provided {@link PatternProcessFunction} is called. In order to process timed out partial matches as well one can
 * use {@link TimedOutPartialMatchHandler} as additional interface.
 *
 * @param patternProcessFunction The pattern process function which is called for each detected
 *                               pattern sequence.
 * @param <R> Type of the resulting elements
 * @return {@link DataStream} which contains the resulting elements from the pattern process
 *         function.
 */
public <R> SingleOutputStreamOperator<R> process(final PatternProcessFunction<T, R> patternProcessFunction) {
	final TypeInformation<R> returnType = TypeExtractor.getUnaryOperatorReturnType(
		patternProcessFunction,
		PatternProcessFunction.class,
		0,
		1,
		TypeExtractor.NO_INDEX,
		builder.getInputType(),
		null,
		false);

	return process(patternProcessFunction, returnType);
}
 
Example 17
Source Project: flink   File: Translate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Translate {@link Edge} values using the given {@link TranslateFunction}.
 *
 * @param edges input edges
 * @param translator implements conversion from {@code OLD} to {@code NEW}
 * @param parallelism operator parallelism
 * @param <K> vertex ID type
 * @param <OLD> old edge value type
 * @param <NEW> new edge value type
 * @return translated edges
 */
@SuppressWarnings("unchecked")
public static <K, OLD, NEW> DataSet<Edge<K, NEW>> translateEdgeValues(DataSet<Edge<K, OLD>> edges, TranslateFunction<OLD, NEW> translator, int parallelism) {
	Preconditions.checkNotNull(edges);
	Preconditions.checkNotNull(translator);

	Class<Edge<K, NEW>> edgeClass = (Class<Edge<K, NEW>>) (Class<? extends Edge>) Edge.class;
	TypeInformation<K> idType = ((TupleTypeInfo<Edge<K, OLD>>) edges.getType()).getTypeAt(0);
	TypeInformation<OLD> oldType = ((TupleTypeInfo<Edge<K, OLD>>) edges.getType()).getTypeAt(2);
	TypeInformation<NEW> newType = TypeExtractor.getUnaryOperatorReturnType(
		translator,
		TranslateFunction.class,
		0,
		1,
		new int[]{1},
		oldType,
		null,
		false);

	TupleTypeInfo<Edge<K, NEW>> returnType = new TupleTypeInfo<>(edgeClass, idType, idType, newType);

	return edges
		.map(new TranslateEdgeValue<>(translator))
		.returns(returnType)
			.setParallelism(parallelism)
			.name("Translate edge values");
}
 
Example 18
Source Project: Flink-CEPplus   File: PatternStream.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Applies a select function to the detected pattern sequence. For each pattern sequence the
 * provided {@link PatternSelectFunction} is called. The pattern select function can produce
 * exactly one resulting element.
 *
 * <p>Applies a timeout function to a partial pattern sequence which has timed out. For each
 * partial pattern sequence the provided {@link PatternTimeoutFunction} is called. The pattern
 * timeout function can produce exactly one resulting element.
 *
 * <p>You can get the stream of timed-out data resulting from the
 * {@link SingleOutputStreamOperator#getSideOutput(OutputTag)} on the
 * {@link SingleOutputStreamOperator} resulting from the select operation
 * with the same {@link OutputTag}.
 *
 * @param timedOutPartialMatchesTag {@link OutputTag} that identifies side output with timed out patterns
 * @param patternTimeoutFunction The pattern timeout function which is called for each partial
 *                               pattern sequence which has timed out.
 * @param patternSelectFunction The pattern select function which is called for each detected
 *                              pattern sequence.
 * @param <L> Type of the resulting timeout elements
 * @param <R> Type of the resulting elements
 * @return {@link DataStream} which contains the resulting elements with the resulting timeout
 * elements in a side output.
 */
public <L, R> SingleOutputStreamOperator<R> select(
		final OutputTag<L> timedOutPartialMatchesTag,
		final PatternTimeoutFunction<T, L> patternTimeoutFunction,
		final PatternSelectFunction<T, R> patternSelectFunction) {

	final TypeInformation<R> rightTypeInfo = TypeExtractor.getUnaryOperatorReturnType(
		patternSelectFunction,
		PatternSelectFunction.class,
		0,
		1,
		TypeExtractor.NO_INDEX,
		builder.getInputType(),
		null,
		false);

	return select(
		timedOutPartialMatchesTag,
		patternTimeoutFunction,
		rightTypeInfo,
		patternSelectFunction);
}
 
Example 19
Source Project: flink   File: PatternStream.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Applies a select function to the detected pattern sequence. For each pattern sequence the
 * provided {@link PatternSelectFunction} is called. The pattern select function can produce
 * exactly one resulting element.
 *
 * <p>Applies a timeout function to a partial pattern sequence which has timed out. For each
 * partial pattern sequence the provided {@link PatternTimeoutFunction} is called. The pattern
 * timeout function can produce exactly one resulting element.
 *
 * @param patternTimeoutFunction The pattern timeout function which is called for each partial
 *                               pattern sequence which has timed out.
 * @param patternSelectFunction The pattern select function which is called for each detected
 *                              pattern sequence.
 * @param <L> Type of the resulting timeout elements
 * @param <R> Type of the resulting elements
 *
 * @deprecated Use {@link PatternStream#select(OutputTag, PatternTimeoutFunction, PatternSelectFunction)}
 * that returns timed out events as a side-output
 *
 * @return {@link DataStream} which contains the resulting elements or the resulting timeout
 * elements wrapped in an {@link Either} type.
 */
@Deprecated
public <L, R> SingleOutputStreamOperator<Either<L, R>> select(
		final PatternTimeoutFunction<T, L> patternTimeoutFunction,
		final PatternSelectFunction<T, R> patternSelectFunction) {

	final TypeInformation<R> mainTypeInfo = TypeExtractor.getUnaryOperatorReturnType(
		patternSelectFunction,
		PatternSelectFunction.class,
		0,
		1,
		TypeExtractor.NO_INDEX,
		builder.getInputType(),
		null,
		false);

	final TypeInformation<L> timeoutTypeInfo = TypeExtractor.getUnaryOperatorReturnType(
		patternTimeoutFunction,
		PatternTimeoutFunction.class,
		0,
		1,
		TypeExtractor.NO_INDEX,
		builder.getInputType(),
		null,
		false);

	final TypeInformation<Either<L, R>> outTypeInfo = new EitherTypeInfo<>(timeoutTypeInfo, mainTypeInfo);

	final OutputTag<L> outputTag = new OutputTag<>(UUID.randomUUID().toString(), timeoutTypeInfo);

	final PatternProcessFunction<T, R> processFunction =
		fromSelect(builder.clean(patternSelectFunction))
			.withTimeoutHandler(outputTag, builder.clean(patternTimeoutFunction))
			.build();

	final SingleOutputStreamOperator<R> mainStream = process(processFunction, mainTypeInfo);
	final DataStream<L> timedOutStream = mainStream.getSideOutput(outputTag);

	return mainStream
		.connect(timedOutStream)
		.map(new CoMapTimeout<>())
		.returns(outTypeInfo);
}
 
Example 20
Source Project: flink   File: PatternStream.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Applies a flat select function to the detected pattern sequence. For each pattern sequence
 * the provided {@link PatternFlatSelectFunction} is called. The pattern flat select function
 * can produce an arbitrary number of resulting elements.
 *
 * <p>Applies a timeout function to a partial pattern sequence which has timed out. For each
 * partial pattern sequence the provided {@link PatternFlatTimeoutFunction} is called. The
 * pattern timeout function can produce an arbitrary number of resulting elements.
 *
 * @param patternFlatTimeoutFunction The pattern flat timeout function which is called for each
 *                                   partial pattern sequence which has timed out.
 * @param patternFlatSelectFunction The pattern flat select function which is called for each
 *                                  detected pattern sequence.
 * @param <L> Type of the resulting timeout events
 * @param <R> Type of the resulting events
 *
 * @deprecated Use {@link PatternStream#flatSelect(OutputTag, PatternFlatTimeoutFunction, PatternFlatSelectFunction)}
 * that returns timed out events as a side-output
 *
 * @return {@link DataStream} which contains the resulting events from the pattern flat select
 * function or the resulting timeout events from the pattern flat timeout function wrapped in an
 * {@link Either} type.
 */
@Deprecated
public <L, R> SingleOutputStreamOperator<Either<L, R>> flatSelect(
		final PatternFlatTimeoutFunction<T, L> patternFlatTimeoutFunction,
		final PatternFlatSelectFunction<T, R> patternFlatSelectFunction) {

	final TypeInformation<L> timedOutTypeInfo = TypeExtractor.getUnaryOperatorReturnType(
		patternFlatTimeoutFunction,
		PatternFlatTimeoutFunction.class,
		0,
		1,
		new int[]{2, 0},
		builder.getInputType(),
		null,
		false);

	final TypeInformation<R> mainTypeInfo = TypeExtractor.getUnaryOperatorReturnType(
		patternFlatSelectFunction,
		PatternFlatSelectFunction.class,
		0,
		1,
		new int[]{1, 0},
		builder.getInputType(),
		null,
		false);

	final OutputTag<L> outputTag = new OutputTag<>(UUID.randomUUID().toString(), timedOutTypeInfo);

	final PatternProcessFunction<T, R> processFunction =
		fromFlatSelect(builder.clean(patternFlatSelectFunction))
			.withTimeoutHandler(outputTag, builder.clean(patternFlatTimeoutFunction))
			.build();

	final SingleOutputStreamOperator<R> mainStream = process(processFunction, mainTypeInfo);
	final DataStream<L> timedOutStream = mainStream.getSideOutput(outputTag);
	final TypeInformation<Either<L, R>> outTypeInfo = new EitherTypeInfo<>(timedOutTypeInfo, mainTypeInfo);

	return mainStream
			.connect(timedOutStream)
			.map(new CoMapTimeout<>())
			.returns(outTypeInfo);
}