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


Java Tuple2.setField方法代码示例

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


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

示例1: combine

import org.apache.flink.api.java.tuple.Tuple2; //导入方法依赖的package包/类
@Override
public void combine(Iterable<Tuple2<Integer, Integer>> values, Collector<Tuple2<Integer, Integer>> out) {
	ArrayList<Tuple2<Integer, Integer>> valueList = new ArrayList<>();
	for (Tuple2<Integer, Integer> next : values) {
		valueList.add(next);
	}

	int count = 0;
	Tuple2<Integer, Integer> rec = new Tuple2<>();
	for (Tuple2<Integer, Integer> tuple : valueList) {
		rec.setField(tuple.f0, 0);
		count += tuple.f1;
	}
	rec.setField(count, 1);
	out.collect(rec);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:17,代码来源:CombiningUnilateralSortMergerITCase.java

示例2: join

import org.apache.flink.api.java.tuple.Tuple2; //导入方法依赖的package包/类
@Override
public Tuple2<Long, Long> join(Tuple2<Long, Long> edge,
		Tuple2<Long, Long> vertexWithCompId) throws Exception {

	vertexWithCompId.setField(edge.f1, 0);
	return vertexWithCompId;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:8,代码来源:DependencyConnectedComponentsITCase.java

示例3: map

import org.apache.flink.api.java.tuple.Tuple2; //导入方法依赖的package包/类
@Override
public Tuple2<Integer, Integer> map(Tuple2<Integer, Integer> value) throws Exception {
	Integer i = value.f0;
	value.setField(value.f1, 0);
	value.setField(i, 1);
	return value;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:8,代码来源:UdfAnalyzerTest.java

示例4: testCombine

import org.apache.flink.api.java.tuple.Tuple2; //导入方法依赖的package包/类
@Test
public void testCombine() throws Exception
{
	int noKeys = 100;
	int noKeyCnt = 10000;

	TestData.MockTuple2Reader<Tuple2<Integer, Integer>> reader = TestData.getIntIntTupleReader();

	LOG.debug("initializing sortmerger");
	
	TestCountCombiner comb = new TestCountCombiner();
	
	Sorter<Tuple2<Integer, Integer>> merger = new CombiningUnilateralSortMerger<>(comb,
			this.memoryManager, this.ioManager, reader, this.parentTask, this.serializerFactory2, this.comparator2,
			0.25, 64, 0.7f, true /* use large record handler */, false);

	final Tuple2<Integer, Integer> rec = new Tuple2<>();
	rec.setField(1, 1);
	
	for (int i = 0; i < noKeyCnt; i++) {
		for (int j = 0; j < noKeys; j++) {
			rec.setField(j, 0);
			reader.emit(rec);
		}
	}
	reader.close();
	
	MutableObjectIterator<Tuple2<Integer, Integer>> iterator = merger.getIterator();

	Iterator<Integer> result = getReducingIterator(iterator, serializerFactory2.getSerializer(), comparator2.duplicate());
	while (result.hasNext()) {
		Assert.assertEquals(noKeyCnt, result.next().intValue());
	}
	
	merger.close();
	
	// if the combiner was opened, it must have been closed
	Assert.assertTrue(comb.opened == comb.closed);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:40,代码来源:CombiningUnilateralSortMergerITCase.java

示例5: testCombineSpilling

import org.apache.flink.api.java.tuple.Tuple2; //导入方法依赖的package包/类
@Test
public void testCombineSpilling() throws Exception {
	int noKeys = 100;
	int noKeyCnt = 10000;

	TestData.MockTuple2Reader<Tuple2<Integer, Integer>> reader = TestData.getIntIntTupleReader();

	LOG.debug("initializing sortmerger");
	
	TestCountCombiner comb = new TestCountCombiner();
	
	Sorter<Tuple2<Integer, Integer>> merger = new CombiningUnilateralSortMerger<>(comb,
			this.memoryManager, this.ioManager, reader, this.parentTask, this.serializerFactory2, this.comparator2,
			0.01, 64, 0.005f, true /* use large record handler */, true);

	final Tuple2<Integer, Integer> rec = new Tuple2<>();
	rec.setField(1, 1);
	
	for (int i = 0; i < noKeyCnt; i++) {
		for (int j = 0; j < noKeys; j++) {
			rec.setField(j, 0);
			reader.emit(rec);
		}
	}
	reader.close();
	
	MutableObjectIterator<Tuple2<Integer, Integer>> iterator = merger.getIterator();

	Iterator<Integer> result = getReducingIterator(iterator, serializerFactory2.getSerializer(), comparator2.duplicate());
	while (result.hasNext()) {
		Assert.assertEquals(noKeyCnt, result.next().intValue());
	}
	
	merger.close();
	
	// if the combiner was opened, it must have been closed
	Assert.assertTrue(comb.opened == comb.closed);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:39,代码来源:CombiningUnilateralSortMergerITCase.java

示例6: testCombineSpillingDisableObjectReuse

import org.apache.flink.api.java.tuple.Tuple2; //导入方法依赖的package包/类
@Test
public void testCombineSpillingDisableObjectReuse() throws Exception {
	int noKeys = 100;
	int noKeyCnt = 10000;

	TestData.MockTuple2Reader<Tuple2<Integer, Integer>> reader = TestData.getIntIntTupleReader();

	LOG.debug("initializing sortmerger");

	MaterializedCountCombiner comb = new MaterializedCountCombiner();

	// set maxNumFileHandles = 2 to trigger multiple channel merging
	Sorter<Tuple2<Integer, Integer>> merger = new CombiningUnilateralSortMerger<>(comb,
			this.memoryManager, this.ioManager, reader, this.parentTask, this.serializerFactory2, this.comparator2,
			0.01, 2, 0.005f, true /* use large record handler */, false);

	final Tuple2<Integer, Integer> rec = new Tuple2<>();

	for (int i = 0; i < noKeyCnt; i++) {
		rec.setField(i, 0);
		for (int j = 0; j < noKeys; j++) {
			rec.setField(j, 1);
			reader.emit(rec);
		}
	}
	reader.close();

	MutableObjectIterator<Tuple2<Integer, Integer>> iterator = merger.getIterator();
	Iterator<Integer> result = getReducingIterator(iterator, serializerFactory2.getSerializer(), comparator2.duplicate());
	while (result.hasNext()) {
		Assert.assertEquals(4950, result.next().intValue());
	}

	merger.close();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:36,代码来源:CombiningUnilateralSortMergerITCase.java

示例7: newIterator

import org.apache.flink.api.java.tuple.Tuple2; //导入方法依赖的package包/类
private MutableObjectIterator<Tuple2<Integer, String>> newIterator(final int[] keys, final String[] values) {
	
	return new MutableObjectIterator<Tuple2<Integer, String>>() {
		
		private int key = 0;
		private String value = new String();
		
		private int current = 0;

		@Override
		public Tuple2<Integer, String> next(Tuple2<Integer, String> reuse) {
			if (current < keys.length) {
				key = keys[current];
				value = values[current];
				current++;
				reuse.setField(key, 0);
				reuse.setField(value, 1);
				return reuse;
			}
			else {
				return null;
			}
		}

		@Override
		public Tuple2<Integer, String> next() {
			if (current < keys.length) {
				Tuple2<Integer, String> result = new Tuple2<>(keys[current], values[current]);
				current++;
				return result;
			}
			else {
				return null;
			}
		}
	};
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:38,代码来源:MergeIteratorTest.java

示例8: next

import org.apache.flink.api.java.tuple.Tuple2; //导入方法依赖的package包/类
@Override
public Tuple2<Integer, Integer> next(Tuple2<Integer, Integer> reuse) {
	if (this.numLeft > 0) {
		this.numLeft--;
		reuse.setField(this.key, 0);
		reuse.setField(this.value, 1);
		return reuse;
	} else {
		return null;
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:12,代码来源:TestData.java

示例9: testSortAndValidate

import org.apache.flink.api.java.tuple.Tuple2; //导入方法依赖的package包/类
@Test
public void testSortAndValidate() throws Exception
{
	final Hashtable<Integer, Integer> countTable = new Hashtable<>(KEY_MAX);
	for (int i = 1; i <= KEY_MAX; i++) {
		countTable.put(i, 0);
	}

	// comparator
	final TypeComparator<Integer> keyComparator = new IntComparator(true);

	// reader
	TestData.MockTuple2Reader<Tuple2<Integer, String>> reader = TestData.getIntStringTupleReader();

	// merge iterator
	LOG.debug("initializing sortmerger");
	
	TestCountCombiner2 comb = new TestCountCombiner2();
	
	Sorter<Tuple2<Integer, String>> merger = new CombiningUnilateralSortMerger<>(comb,
			this.memoryManager, this.ioManager, reader, this.parentTask, this.serializerFactory1, this.comparator1,
			0.25, 2, 0.7f, true /* use large record handler */, false);

	// emit data
	LOG.debug("emitting data");
	TestData.TupleGenerator generator = new TestData.TupleGenerator(SEED, KEY_MAX, VALUE_LENGTH, KeyMode.RANDOM, ValueMode.FIX_LENGTH);
	Tuple2<Integer, String> rec = new Tuple2<>();
	
	for (int i = 0; i < NUM_PAIRS; i++) {
		Assert.assertTrue((rec = generator.next(rec)) != null);
		final Integer key = rec.f0;
		rec.setField("1", 1);
		reader.emit(rec);
		
		countTable.put(key, countTable.get(key) + 1);
	}
	reader.close();

	// check order
	MutableObjectIterator<Tuple2<Integer, String>> iterator = merger.getIterator();
	
	LOG.debug("checking results");
	
	Tuple2<Integer, String> rec1 = new Tuple2<>();
	Tuple2<Integer, String> rec2 = new Tuple2<>();
	
	Assert.assertTrue((rec1 = iterator.next(rec1)) != null);
	countTable.put(rec1.f0, countTable.get(rec1.f0) - (Integer.parseInt(rec1.f1)));

	while ((rec2 = iterator.next(rec2)) != null) {
		int k1 = rec1.f0;
		int k2 = rec2.f0;
		
		Assert.assertTrue(keyComparator.compare(k1, k2) <= 0); 
		countTable.put(k2, countTable.get(k2) - (Integer.parseInt(rec2.f1)));
		
		rec1 = rec2;
	}

	for (Integer cnt : countTable.values()) {
		Assert.assertTrue(cnt == 0);
	}
	
	merger.close();
	
	// if the combiner was opened, it must have been closed
	Assert.assertTrue(comb.opened == comb.closed);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:69,代码来源:CombiningUnilateralSortMergerITCase.java


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