use of edu.iu.dsc.tws.tset.links.batch.GatherTLink in project twister2 by DSC-SPIDAL.
the class TSetGatherExample method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
super.execute(workerEnv);
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
// set the parallelism of source to task stage 0
int srcPara = jobParameters.getTaskStages().get(0);
int sinkPara = jobParameters.getTaskStages().get(1);
SourceTSet<int[]> source = env.createSource(new TestBaseSource(), srcPara).setName("Source");
GatherTLink<int[]> gather = source.gather();
SinkTSet<Iterator<Tuple<Integer, int[]>>> sink = gather.sink((SinkFunc<Iterator<Tuple<Integer, int[]>>>) val -> {
int[] value = null;
while (val.hasNext()) {
value = val.next().getValue();
}
experimentData.setOutput(value);
LOG.info("Results " + Arrays.toString(value));
try {
verify(OperationNames.GATHER);
} catch (VerificationException e) {
LOG.info("Exception Message : " + e.getMessage());
}
return true;
});
env.run(sink);
}
use of edu.iu.dsc.tws.tset.links.batch.GatherTLink in project twister2 by DSC-SPIDAL.
the class GatherExample method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
int start = env.getWorkerID() * 100;
SourceTSet<Integer> src = dummySource(env, start, COUNT, PARALLELISM);
GatherTLink<Integer> gather = src.gather();
LOG.info("test foreach");
gather.forEach(i -> LOG.info("foreach: " + i));
LOG.info("test map");
gather.map(i -> i.toString() + "$$").withSchema(PrimitiveSchemas.STRING).direct().forEach(s -> LOG.info("map: " + s));
LOG.info("test compute");
gather.compute((ComputeFunc<Iterator<Tuple<Integer, Integer>>, String>) input -> {
int sum = 0;
while (input.hasNext()) {
sum += input.next().getValue();
}
return "sum=" + sum;
}).withSchema(PrimitiveSchemas.STRING).direct().forEach(s -> LOG.info("compute: " + s));
LOG.info("test computec");
gather.compute((ComputeCollectorFunc<Iterator<Tuple<Integer, Integer>>, String>) (input, output) -> {
int sum = 0;
while (input.hasNext()) {
sum += input.next().getValue();
}
output.collect("sum=" + sum);
}).withSchema(PrimitiveSchemas.STRING).direct().forEach(s -> LOG.info("computec: " + s));
gather.mapToTuple(i -> new Tuple<>(i % 2, i)).keyedDirect().forEach(i -> LOG.info("mapToTuple: " + i.toString()));
}
Aggregations