当前位置: 首页>>代码示例>>Java>>正文


Java FlatMapFunction.flatMap方法代码示例

本文整理汇总了Java中org.apache.flink.api.common.functions.FlatMapFunction.flatMap方法的典型用法代码示例。如果您正苦于以下问题:Java FlatMapFunction.flatMap方法的具体用法?Java FlatMapFunction.flatMap怎么用?Java FlatMapFunction.flatMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.flink.api.common.functions.FlatMapFunction的用法示例。


在下文中一共展示了FlatMapFunction.flatMap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeOnCollections

import org.apache.flink.api.common.functions.FlatMapFunction; //导入方法依赖的package包/类
@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;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:19,代码来源:FilterOperatorBase.java

示例2: executeOnCollections

import org.apache.flink.api.common.functions.FlatMapFunction; //导入方法依赖的package包/类
@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;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:24,代码来源:FlatMapOperatorBase.java

示例3: executeOnCollections

import org.apache.flink.api.common.functions.FlatMapFunction; //导入方法依赖的package包/类
@Override
protected List<T> executeOnCollections(List<T> inputData, RuntimeContext ctx, boolean mutableObjectSafeMode) 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;
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:19,代码来源:FilterOperatorBase.java

示例4: testCounts

import org.apache.flink.api.common.functions.FlatMapFunction; //导入方法依赖的package包/类
@Test
public void testCounts() throws Exception {
    FlatMapFunction f = new ExactTriangleCount.SumAndEmitCounters();
    Tuple2<Integer, Integer> expected = new Tuple2<>();

    f.flatMap(new Tuple2<>(-1, 1), out3);
    expected.setField(-1, 0);
    expected.setField(1, 1);
    Assert.assertEquals(expected, resultTuple3);

    f.flatMap(new Tuple2<>(-1, 5), out3);
    expected.setField(-1, 0);
    expected.setField(6, 1);
    Assert.assertEquals(expected, resultTuple3);

    f.flatMap(new Tuple2<>(2, 2), out3);
    expected.setField(2, 0);
    expected.setField(2, 1);
    Assert.assertEquals(expected, resultTuple3);

    f.flatMap(new Tuple2<>(-1, 4), out3);
    expected.setField(-1, 0);
    expected.setField(10, 1);
    Assert.assertEquals(expected, resultTuple3);

    f.flatMap(new Tuple2<>(2, 4), out3);
    expected.setField(2, 0);
    expected.setField(6, 1);
    Assert.assertEquals(expected, resultTuple3);
}
 
开发者ID:vasia,项目名称:gelly-streaming,代码行数:31,代码来源:TriangleCountTest.java

示例5: run

import org.apache.flink.api.common.functions.FlatMapFunction; //导入方法依赖的package包/类
@Override
public void run() throws Exception {
	// cache references on the stack
	final MutableObjectIterator<IT> input = this.taskContext.getInput(0);
	final FlatMapFunction<IT, OT> function = this.taskContext.getStub();
	final Collector<OT> output = this.taskContext.getOutputCollector();

	IT record = this.taskContext.<IT>getInputSerializer(0).getSerializer().createInstance();

	while (this.running && ((record = input.next(record)) != null)) {
		function.flatMap(record, output);
	}
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:14,代码来源:FlatMapDriver.java

示例6: testIntersection

import org.apache.flink.api.common.functions.FlatMapFunction; //导入方法依赖的package包/类
@Test
public void testIntersection() throws Exception {
    FlatMapFunction f = new ExactTriangleCount.IntersectNeighborhoods();

    TreeSet<Integer> t1 = new TreeSet<>();
    t1.add(2);
    t1.add(3);
    t1.add(5);
    t1.add(7);
    t1.add(9);
    Tuple3<Integer, Integer, TreeSet<Integer>> input1 = new Tuple3<>(1, 2, t1);

    Tuple3<Integer, Integer, TreeSet<Integer>> input2 = new Tuple3<>(1, 3, t1);
    TreeSet<Integer> t2 = new TreeSet<>();
    t2.add(1);
    t2.add(3);
    t2.add(4);
    t2.add(5);
    t2.add(15);
    t2.add(18);

    Tuple3<Integer, Integer, TreeSet<Integer>> input3 = new Tuple3<>(1, 2, t2);

    f.flatMap(input1, out2);
    Assert.assertEquals(0, resultList2.size());

    f.flatMap(input2, out2);
    Assert.assertEquals(0, resultList2.size());

    f.flatMap(input3, out2);
    Assert.assertEquals(5, resultList2.size());
    Assert.assertEquals(true, resultList2.contains(new Tuple2<>(3, 1)));
    Assert.assertEquals(true, resultList2.contains(new Tuple2<>(5, 1)));
    Assert.assertEquals(true, resultList2.contains(new Tuple2<>(1, 2)));
    Assert.assertEquals(true, resultList2.contains(new Tuple2<>(2, 2)));
    Assert.assertEquals(true, resultList2.contains(new Tuple2<>(-1, 2)));

    TreeSet<Integer> t3 = new TreeSet<>();
    t3.add(1);
    t3.add(2);
    t3.add(7);
    t3.add(8);
    Tuple3<Integer, Integer, TreeSet<Integer>> input4 = new Tuple3<>(1, 3, t3);

    resultList2.clear();
    f.flatMap(input4, out2);
    Assert.assertEquals(5, resultList2.size());
    Assert.assertEquals(true, resultList2.contains(new Tuple2<>(2, 1)));
    Assert.assertEquals(true, resultList2.contains(new Tuple2<>(7, 1)));
    Assert.assertEquals(true, resultList2.contains(new Tuple2<>(1, 2)));
    Assert.assertEquals(true, resultList2.contains(new Tuple2<>(3, 2)));
    Assert.assertEquals(true, resultList2.contains(new Tuple2<>(-1, 2)));
}
 
开发者ID:vasia,项目名称:gelly-streaming,代码行数:54,代码来源:TriangleCountTest.java


注:本文中的org.apache.flink.api.common.functions.FlatMapFunction.flatMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。