Search in sources :

Example 1 with ValueInEmptyWindows

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;
            }
        };
    }
}
Also used : ValueInEmptyWindows(org.apache.beam.runners.dataflow.worker.util.ValueInEmptyWindows) WindowedValue(org.apache.beam.sdk.util.WindowedValue) WorkItem(org.apache.beam.runners.dataflow.worker.windmill.Windmill.WorkItem) KeyedWorkItem(org.apache.beam.runners.core.KeyedWorkItem) KeyedWorkItem(org.apache.beam.runners.core.KeyedWorkItem) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

NoSuchElementException (java.util.NoSuchElementException)1 KeyedWorkItem (org.apache.beam.runners.core.KeyedWorkItem)1 ValueInEmptyWindows (org.apache.beam.runners.dataflow.worker.util.ValueInEmptyWindows)1 WorkItem (org.apache.beam.runners.dataflow.worker.windmill.Windmill.WorkItem)1 WindowedValue (org.apache.beam.sdk.util.WindowedValue)1