Java Code Examples for org.apache.flink.api.common.functions.util.FunctionUtils#openFunction()

The following examples show how to use org.apache.flink.api.common.functions.util.FunctionUtils#openFunction() . 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: FoldApplyProcessAllWindowFunction.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void open(Configuration configuration) throws Exception {
	FunctionUtils.openFunction(this.windowFunction, configuration);

	if (serializedInitialValue == null) {
		throw new RuntimeException("No initial value was serialized for the fold " +
			"window function. Probably the setOutputType method was not called.");
	}

	ByteArrayInputStream bais = new ByteArrayInputStream(serializedInitialValue);
	DataInputViewStreamWrapper in = new DataInputViewStreamWrapper(bais);
	initialValue = accSerializer.deserialize(in);

	ctx = new InternalProcessApplyAllWindowContext<>(windowFunction);

}
 
Example 2
Source File: MapOperatorBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN> inputData, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	MapFunction<IN, OUT> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);
	
	ArrayList<OUT> result = new ArrayList<OUT>(inputData.size());

	TypeSerializer<IN> inSerializer = getOperatorInfo().getInputType().createSerializer(executionConfig);
	TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);

	for (IN element : inputData) {
		IN inCopy = inSerializer.copy(element);
		OUT out = function.map(inCopy);
		result.add(outSerializer.copy(out));
	}

	FunctionUtils.closeFunction(function);
	
	return result;
}
 
Example 3
Source File: FoldApplyProcessAllWindowFunction.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open(Configuration configuration) throws Exception {
	FunctionUtils.openFunction(this.windowFunction, configuration);

	if (serializedInitialValue == null) {
		throw new RuntimeException("No initial value was serialized for the fold " +
			"window function. Probably the setOutputType method was not called.");
	}

	ByteArrayInputStream bais = new ByteArrayInputStream(serializedInitialValue);
	DataInputViewStreamWrapper in = new DataInputViewStreamWrapper(bais);
	initialValue = accSerializer.deserialize(in);

	ctx = new InternalProcessApplyAllWindowContext<>(windowFunction);

}
 
Example 4
Source File: FilterOperatorBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected List<T> executeOnCollections(List<T> inputData, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	FlatMapFunction<T, T> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);
	
	ArrayList<T> result = new ArrayList<T>(inputData.size());
	ListCollector<T> collector = new ListCollector<T>(result);

	for (T element : inputData) {
		function.flatMap(element, collector);
	}
	
	FunctionUtils.closeFunction(function);
	
	return result;
}
 
Example 5
Source File: FilterOperatorBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected List<T> executeOnCollections(List<T> inputData, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	FlatMapFunction<T, T> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);
	
	ArrayList<T> result = new ArrayList<T>(inputData.size());
	ListCollector<T> collector = new ListCollector<T>(result);

	for (T element : inputData) {
		function.flatMap(element, collector);
	}
	
	FunctionUtils.closeFunction(function);
	
	return result;
}
 
Example 6
Source File: CrossOperatorBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN1> inputData1, List<IN2> inputData2, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	CrossFunction<IN1, IN2, OUT> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);

	ArrayList<OUT> result = new ArrayList<OUT>(inputData1.size() * inputData2.size());
	
	TypeSerializer<IN1> inSerializer1 = getOperatorInfo().getFirstInputType().createSerializer(executionConfig);
	TypeSerializer<IN2> inSerializer2 = getOperatorInfo().getSecondInputType().createSerializer(executionConfig);
	TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);

	for (IN1 element1 : inputData1) {
		for (IN2 element2 : inputData2) {
			IN1 copy1 = inSerializer1.copy(element1);
			IN2 copy2 = inSerializer2.copy(element2);
			OUT o = function.cross(copy1, copy2);
			result.add(outSerializer.copy(o));
		}
	}

	FunctionUtils.closeFunction(function);
	return result;
}
 
Example 7
Source File: FlatMapOperatorBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN> input, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	FlatMapFunction<IN, OUT> function = userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, parameters);

	ArrayList<OUT> result = new ArrayList<OUT>(input.size());

	TypeSerializer<IN> inSerializer = getOperatorInfo().getInputType().createSerializer(executionConfig);
	TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);

	CopyingListCollector<OUT> resultCollector = new CopyingListCollector<OUT>(result, outSerializer);

	for (IN element : input) {
		IN inCopy = inSerializer.copy(element);
		function.flatMap(inCopy, resultCollector);
	}

	FunctionUtils.closeFunction(function);

	return result;
}
 
Example 8
Source File: MapPartitionOperatorBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN> inputData, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	MapPartitionFunction<IN, OUT> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);
	
	ArrayList<OUT> result = new ArrayList<OUT>(inputData.size() / 4);

	TypeSerializer<IN> inSerializer = getOperatorInfo().getInputType().createSerializer(executionConfig);
	TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);

	CopyingIterator<IN> source = new CopyingIterator<IN>(inputData.iterator(), inSerializer);
	CopyingListCollector<OUT> resultCollector = new CopyingListCollector<OUT>(result, outSerializer);

	function.mapPartition(source, resultCollector);

	result.trimToSize();
	FunctionUtils.closeFunction(function);
	return result;
}
 
Example 9
Source File: CrossOperatorBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN1> inputData1, List<IN2> inputData2, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	CrossFunction<IN1, IN2, OUT> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);

	ArrayList<OUT> result = new ArrayList<OUT>(inputData1.size() * inputData2.size());
	
	TypeSerializer<IN1> inSerializer1 = getOperatorInfo().getFirstInputType().createSerializer(executionConfig);
	TypeSerializer<IN2> inSerializer2 = getOperatorInfo().getSecondInputType().createSerializer(executionConfig);
	TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);

	for (IN1 element1 : inputData1) {
		for (IN2 element2 : inputData2) {
			IN1 copy1 = inSerializer1.copy(element1);
			IN2 copy2 = inSerializer2.copy(element2);
			OUT o = function.cross(copy1, copy2);
			result.add(outSerializer.copy(o));
		}
	}

	FunctionUtils.closeFunction(function);
	return result;
}
 
Example 10
Source File: PatternTimeoutFlatSelectAdapter.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void open(Configuration parameters) throws Exception {
	super.open(parameters);
	FunctionUtils.setFunctionRuntimeContext(flatTimeoutFunction, getRuntimeContext());
	FunctionUtils.openFunction(flatTimeoutFunction, parameters);

	if (sideCollector == null) {
		sideCollector = new SideCollector<>(checkNotNull(timedOutPartialMatchesTag));
	}
}
 
Example 11
Source File: RichCompositeIterativeCondition.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open(Configuration parameters) throws Exception {
	super.open(parameters);
	for (IterativeCondition<T> nestedCondition : nestedConditions) {
		FunctionUtils.openFunction(nestedCondition, parameters);
	}
}
 
Example 12
Source File: AsyncLookupJoinRunner.java    From flink with Apache License 2.0 5 votes vote down vote up
public TableFunctionResultFuture<BaseRow> createFetcherResultFuture(Configuration parameters) throws Exception {
	TableFunctionResultFuture<BaseRow> resultFuture = generatedResultFuture.newInstance(
		getRuntimeContext().getUserCodeClassLoader());
	FunctionUtils.setFunctionRuntimeContext(resultFuture, getRuntimeContext());
	FunctionUtils.openFunction(resultFuture, parameters);
	return resultFuture;
}
 
Example 13
Source File: TemporalProcessTimeJoinOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	this.joinCondition = generatedJoinCondition.newInstance(getRuntimeContext().getUserCodeClassLoader());
	FunctionUtils.setFunctionRuntimeContext(joinCondition, getRuntimeContext());
	FunctionUtils.openFunction(joinCondition, new Configuration());

	ValueStateDescriptor<BaseRow> rightStateDesc = new ValueStateDescriptor<>("right", rightType);
	this.rightState = getRuntimeContext().getState(rightStateDesc);
	this.collector = new TimestampedCollector<>(output);
	this.outRow = new JoinedRow();
	// consider watermark from left stream only.
	super.processWatermark2(Watermark.MAX_WATERMARK);
}
 
Example 14
Source File: NFA.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Initialization method for the NFA. It is called before any element is passed and thus suitable for one time setup
 * work.
 * @param cepRuntimeContext runtime context of the enclosing operator
 * @param conf The configuration containing the parameters attached to the contract.
 */
public void open(RuntimeContext cepRuntimeContext, Configuration conf) throws Exception {
	for (State<T> state : getStates()) {
		for (StateTransition<T> transition : state.getStateTransitions()) {
			IterativeCondition condition = transition.getCondition();
			FunctionUtils.setFunctionRuntimeContext(condition, cepRuntimeContext);
			FunctionUtils.openFunction(condition, conf);
		}
	}
}
 
Example 15
Source File: PatternFlatSelectAdapter.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void open(final Configuration parameters) throws Exception {
	FunctionUtils.setFunctionRuntimeContext(flatSelectFunction, getRuntimeContext());
	FunctionUtils.openFunction(flatSelectFunction, parameters);
}
 
Example 16
Source File: PatternSelectAdapter.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void open(final Configuration parameters) throws Exception {
	FunctionUtils.setFunctionRuntimeContext(selectFunction, getRuntimeContext());
	FunctionUtils.openFunction(selectFunction, parameters);
}
 
Example 17
Source File: AbstractUdfStreamOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();
	FunctionUtils.openFunction(userFunction, new Configuration());
}
 
Example 18
Source File: CoGroupRawOperatorBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN1> input1, List<IN2> input2, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	// --------------------------------------------------------------------
	// Setup
	// --------------------------------------------------------------------
	TypeInformation<IN1> inputType1 = getOperatorInfo().getFirstInputType();
	TypeInformation<IN2> inputType2 = getOperatorInfo().getSecondInputType();

	int[] inputKeys1 = getKeyColumns(0);
	int[] inputKeys2 = getKeyColumns(1);

	boolean[] inputSortDirections1 = new boolean[inputKeys1.length];
	boolean[] inputSortDirections2 = new boolean[inputKeys2.length];

	Arrays.fill(inputSortDirections1, true);
	Arrays.fill(inputSortDirections2, true);

	final TypeSerializer<IN1> inputSerializer1 = inputType1.createSerializer(executionConfig);
	final TypeSerializer<IN2> inputSerializer2 = inputType2.createSerializer(executionConfig);

	final TypeComparator<IN1> inputComparator1 = getTypeComparator(executionConfig, inputType1, inputKeys1, inputSortDirections1);
	final TypeComparator<IN2> inputComparator2 = getTypeComparator(executionConfig, inputType2, inputKeys2, inputSortDirections2);

	SimpleListIterable<IN1> iterator1 = new SimpleListIterable<IN1>(input1, inputComparator1, inputSerializer1);
	SimpleListIterable<IN2> iterator2 = new SimpleListIterable<IN2>(input2, inputComparator2, inputSerializer2);

	// --------------------------------------------------------------------
	// Run UDF
	// --------------------------------------------------------------------
	CoGroupFunction<IN1, IN2, OUT> function = userFunction.getUserCodeObject();

	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, parameters);

	List<OUT> result = new ArrayList<OUT>();
	Collector<OUT> resultCollector = new CopyingListCollector<OUT>(result, getOperatorInfo().getOutputType().createSerializer(executionConfig));

	function.coGroup(iterator1, iterator2, resultCollector);

	FunctionUtils.closeFunction(function);

	return result;
}
 
Example 19
Source File: PatternSelectAdapter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void open(final Configuration parameters) throws Exception {
	FunctionUtils.setFunctionRuntimeContext(selectFunction, getRuntimeContext());
	FunctionUtils.openFunction(selectFunction, parameters);
}
 
Example 20
Source File: ReduceApplyProcessAllWindowFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void open(Configuration configuration) throws Exception {
	FunctionUtils.openFunction(this.windowFunction, configuration);
	ctx = new InternalProcessApplyAllWindowContext<>(windowFunction);
}