use of edu.iu.dsc.tws.api.tset.fn.FlatMapFunc in project twister2 by DSC-SPIDAL.
the class FullGraphRunExample method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
SourceTSet<Integer> src = dummySource(env, COUNT, PARALLELISM);
src.direct().flatmap((FlatMapFunc<Integer, Object>) (integer, collector) -> LOG.info("dir= " + integer));
src.reduce(Integer::sum).flatmap((FlatMapFunc<Integer, Object>) (integer, collector) -> LOG.info("red= " + integer));
// env.run();
}
use of edu.iu.dsc.tws.api.tset.fn.FlatMapFunc in project twister2 by DSC-SPIDAL.
the class FileBasedWordCount method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
int sourcePar = (int) env.getConfig().get("PAR");
// read the file line by line by using a single worker
SourceTSet<String> lines = env.createSource(new WordCountFileSource(), 1);
// distribute the lines among the workers and performs a flatmap operation to extract words
ComputeTSet<String> words = lines.partition(new HashingPartitioner<>(), sourcePar).flatmap((FlatMapFunc<String, String>) (l, collector) -> {
StringTokenizer itr = new StringTokenizer(l);
while (itr.hasMoreTokens()) {
collector.collect(itr.nextToken());
}
});
// attach count as 1 for each word
KeyedTSet<String, Integer> groupedWords = words.mapToTuple(w -> new Tuple<>(w, 1));
// performs reduce by key at each worker
KeyedReduceTLink<String, Integer> keyedReduce = groupedWords.keyedReduce(Integer::sum);
// gather the results to worker0 (there is a dummy map op here to pass the values to edges)
// and write to a file
keyedReduce.map(i -> i).gather().forEach(new WordcountFileWriter());
}
Aggregations