本文整理匯總了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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}
示例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;
}
}
};
}
示例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;
}
}
示例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);
}