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

The following examples show how to use org.apache.flink.api.common.functions.util.FunctionUtils#setFunctionRuntimeContext() . 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: MapPartitionOperatorBase.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 {
	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 2
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 3
Source File: ChainedReduceCombineDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(AbstractInvokable parent) {
	this.parent = parent;
	running = true;

	strategy = config.getDriverStrategy();

	reducer = BatchTask.instantiateUserCode(config, userCodeClassLoader, ReduceFunction.class);
	FunctionUtils.setFunctionRuntimeContext(reducer, getUdfRuntimeContext());
}
 
Example 4
Source File: ChainedAllReduceDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(AbstractInvokable parent) {
	@SuppressWarnings("unchecked")
	final ReduceFunction<IT> red = BatchTask.instantiateUserCode(this.config, userCodeClassLoader, ReduceFunction.class);
	this.reducer = red;
	FunctionUtils.setFunctionRuntimeContext(red, getUdfRuntimeContext());

	TypeSerializerFactory<IT> serializerFactory = this.config.getInputSerializer(0, userCodeClassLoader);
	this.serializer = serializerFactory.getSerializer();

	if (LOG.isDebugEnabled()) {
		LOG.debug("ChainedAllReduceDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
}
 
Example 5
Source File: OuterJoinOperatorBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN1> leftInput, List<IN2> rightInput, RuntimeContext runtimeContext, ExecutionConfig executionConfig) throws Exception {
	TypeInformation<IN1> leftInformation = getOperatorInfo().getFirstInputType();
	TypeInformation<IN2> rightInformation = getOperatorInfo().getSecondInputType();
	TypeInformation<OUT> outInformation = getOperatorInfo().getOutputType();

	TypeComparator<IN1> leftComparator = buildComparatorFor(0, executionConfig, leftInformation);
	TypeComparator<IN2> rightComparator = buildComparatorFor(1, executionConfig, rightInformation);

	TypeSerializer<IN1> leftSerializer = leftInformation.createSerializer(executionConfig);
	TypeSerializer<IN2> rightSerializer = rightInformation.createSerializer(executionConfig);

	OuterJoinListIterator<IN1, IN2> outerJoinIterator =
			new OuterJoinListIterator<>(leftInput, leftSerializer, leftComparator,
					rightInput, rightSerializer, rightComparator, outerJoinType);

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

	FunctionUtils.setFunctionRuntimeContext(function, runtimeContext);
	FunctionUtils.openFunction(function, this.parameters);

	List<OUT> result = new ArrayList<>();
	Collector<OUT> collector = new CopyingListCollector<>(result, outInformation.createSerializer(executionConfig));

	while (outerJoinIterator.next()) {
		IN1 left = outerJoinIterator.getLeft();
		IN2 right = outerJoinIterator.getRight();
		function.join(left == null ? null : leftSerializer.copy(left), right == null ? null : rightSerializer.copy(right), collector);
	}

	FunctionUtils.closeFunction(function);

	return result;
}
 
Example 6
Source File: LookupJoinRunner.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);
	this.fetcher = generatedFetcher.newInstance(getRuntimeContext().getUserCodeClassLoader());
	this.collector = generatedCollector.newInstance(getRuntimeContext().getUserCodeClassLoader());

	FunctionUtils.setFunctionRuntimeContext(fetcher, getRuntimeContext());
	FunctionUtils.setFunctionRuntimeContext(collector, getRuntimeContext());
	FunctionUtils.openFunction(fetcher, parameters);
	FunctionUtils.openFunction(collector, parameters);

	this.nullRow = new GenericRow(tableFieldsCount);
	this.outRow = new JoinedRow();
}
 
Example 7
Source File: RichCompositeIterativeCondition.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void setRuntimeContext(RuntimeContext t) {
	super.setRuntimeContext(t);

	for (IterativeCondition<T> nestedCondition : nestedConditions) {
		FunctionUtils.setFunctionRuntimeContext(nestedCondition, t);
	}
}
 
Example 8
Source File: AsyncLookupJoinWithCalcRunner.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TableFunctionResultFuture<BaseRow> createFetcherResultFuture(Configuration parameters) throws Exception {
	TableFunctionResultFuture<BaseRow> joinConditionCollector = super.createFetcherResultFuture(parameters);
	FlatMapFunction<BaseRow, BaseRow> calc = generatedCalc.newInstance(getRuntimeContext().getUserCodeClassLoader());
	FunctionUtils.setFunctionRuntimeContext(calc, getRuntimeContext());
	FunctionUtils.openFunction(calc, parameters);
	return new TemporalTableCalcResultFuture(calc, joinConditionCollector);
}
 
Example 9
Source File: ChainedFlatMapDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(AbstractInvokable parent) {
	@SuppressWarnings("unchecked")
	final FlatMapFunction<IT, OT> mapper =
		BatchTask.instantiateUserCode(this.config, userCodeClassLoader, FlatMapFunction.class);
	this.mapper = mapper;
	FunctionUtils.setFunctionRuntimeContext(mapper, getUdfRuntimeContext());
}
 
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: ReduceApplyProcessAllWindowFunction.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void setRuntimeContext(RuntimeContext t) {
	super.setRuntimeContext(t);

	FunctionUtils.setFunctionRuntimeContext(this.windowFunction, t);
}
 
Example 12
Source File: FoldApplyProcessWindowFunction.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void setRuntimeContext(RuntimeContext t) {
	super.setRuntimeContext(t);

	FunctionUtils.setFunctionRuntimeContext(this.windowFunction, t);
}
 
Example 13
Source File: FoldApplyProcessAllWindowFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void setRuntimeContext(RuntimeContext t) {
	super.setRuntimeContext(t);

	FunctionUtils.setFunctionRuntimeContext(this.windowFunction, t);
}
 
Example 14
Source File: ReduceApplyProcessWindowFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void setRuntimeContext(RuntimeContext t) {
	super.setRuntimeContext(t);

	FunctionUtils.setFunctionRuntimeContext(this.windowFunction, t);
}
 
Example 15
Source File: IterativeConditionRunner.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void open(Configuration parameters) throws Exception {
	this.function = generatedFunction.newInstance(getRuntimeContext().getUserCodeClassLoader());
	FunctionUtils.setFunctionRuntimeContext(function, getRuntimeContext());
	FunctionUtils.openFunction(function, parameters);
}
 
Example 16
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 17
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 18
Source File: WrappingFunction.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void setRuntimeContext(RuntimeContext t) {
	super.setRuntimeContext(t);

	FunctionUtils.setFunctionRuntimeContext(this.wrappedFunction, t);
}
 
Example 19
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 20
Source File: ReduceApplyProcessWindowFunction.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void setRuntimeContext(RuntimeContext t) {
	super.setRuntimeContext(t);

	FunctionUtils.setFunctionRuntimeContext(this.windowFunction, t);
}