use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class GeneralReduceByKeyAndWindowOperator method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(TupleWindow inputWindow) {
Map<K, VR> reduceMap = new HashMap<>();
Map<K, Integer> windowCountMap = new HashMap<>();
for (Tuple tuple : inputWindow.get()) {
V tup = (V) tuple.getValue(0);
addMap(reduceMap, windowCountMap, tup);
}
long startWindow;
long endWindow;
if (inputWindow.getStartTimestamp() == null) {
startWindow = 0;
} else {
startWindow = inputWindow.getStartTimestamp();
}
if (inputWindow.getEndTimestamp() == null) {
endWindow = 0;
} else {
endWindow = inputWindow.getEndTimestamp();
}
for (K key : reduceMap.keySet()) {
Window window = new Window(startWindow, endWindow, windowCountMap.get(key));
KeyedWindow<K> keyedWindow = new KeyedWindow<>(key, window);
collector.emit(new Values(new KeyValue<>(keyedWindow, reduceMap.get(key))));
}
}
use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class HdfsStringSpout method nextTuple.
@Override
public void nextTuple() {
if (br == null) {
return;
}
try {
String line = "";
if ((line = br.readLine()) != null) {
collector.emit(new Values(line));
} else {
br.close();
br = null;
}
} catch (IOException e) {
// Clean stuff if any exceptions
try {
// Close the outmost is enough
br.close();
} catch (IOException e1) {
throw new RuntimeException("Unable to close stream reader", e1);
}
throw new RuntimeException("Unable to emit tuples normally", e);
}
}
use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class ABSpout method nextTuple.
@Override
public void nextTuple() {
String word = TO_SEND[emitted % TO_SEND.length];
if (appendSequenceId) {
word = word + "_" + emitted;
}
collector.emit(new Values(word));
emitted++;
}
use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class LocalFileSpout method nextTuple.
// We do not explicitly close the buffered reader, even on EoF. This is in case more content is
// added to file, we will read that content as well
@Override
public void nextTuple() {
if (br == null) {
return;
}
try {
String currentLine;
if ((currentLine = br.readLine()) != null) {
collector.emit(new Values(currentLine));
} else {
br.close();
br = null;
}
} catch (IOException e) {
// Clean stuff if any exceptions
try {
// Close the outmost is enough
if (br != null) {
br.close();
}
} catch (IOException e1) {
throw new RuntimeException("Unable to close stream reader", e1);
}
throw new RuntimeException("Unable to emit tuples normally", e);
}
}
Aggregations