use of org.apache.beam.runners.dataflow.worker.util.ValueInEmptyWindows in project beam by apache.
the class WindowingWindmillReader method iterator.
@Override
public NativeReaderIterator<WindowedValue<KeyedWorkItem<K, T>>> iterator() throws IOException {
final K key = keyCoder.decode(context.getSerializedKey().newInput(), Coder.Context.OUTER);
final WorkItem workItem = context.getWork();
KeyedWorkItem<K, T> keyedWorkItem = new WindmillKeyedWorkItem<>(key, workItem, windowCoder, windowsCoder, valueCoder);
final boolean isEmptyWorkItem = (Iterables.isEmpty(keyedWorkItem.timersIterable()) && Iterables.isEmpty(keyedWorkItem.elementsIterable()));
final WindowedValue<KeyedWorkItem<K, T>> value = new ValueInEmptyWindows<>(keyedWorkItem);
// Return a noop iterator when current workitem is an empty workitem.
if (isEmptyWorkItem) {
return new NativeReaderIterator<WindowedValue<KeyedWorkItem<K, T>>>() {
@Override
public boolean start() throws IOException {
return false;
}
@Override
public boolean advance() throws IOException {
return false;
}
@Override
public WindowedValue<KeyedWorkItem<K, T>> getCurrent() {
throw new NoSuchElementException();
}
};
} else {
return new NativeReaderIterator<WindowedValue<KeyedWorkItem<K, T>>>() {
private WindowedValue<KeyedWorkItem<K, T>> current;
@Override
public boolean start() throws IOException {
current = value;
return true;
}
@Override
public boolean advance() throws IOException {
current = null;
return false;
}
@Override
public WindowedValue<KeyedWorkItem<K, T>> getCurrent() {
if (current == null) {
throw new NoSuchElementException();
}
return value;
}
};
}
}
Aggregations