class FetchingCursor implements Cursor {
        /** */
        private Iterator<Row> stream;

        /** */
        private List<Row> rows;

        /** */
        private int cur;

        /**
         * @param stream Stream of all the rows from remote nodes.
         */
        FetchingCursor(Iterator<Row> stream) {
            assert stream != null;

            // Initially we will use all the fetched rows, after we will switch to the last block.
            rows = fetched;

            this.stream = stream;

            cur--; // Set current position before the first row.
        }

        /**
         * Fetch rows from the stream.
         */
        private void fetchRows() {<FILL_FUNCTION_BODY>}

        /** {@inheritDoc} */
        @Override public boolean next() {
            if (cur == Integer.MAX_VALUE)
                return false;

            if (++cur == rows.size())
                fetchRows();

            return cur < Integer.MAX_VALUE;
        }

        /** {@inheritDoc} */
        @Override public Row get() {
            return rows.get(cur);
        }

        /** {@inheritDoc} */
        @Override public SearchRow getSearchRow() {
            return get();
        }

        /** {@inheritDoc} */
        @Override public boolean previous() {
            // Should never be called.
            throw DbException.getUnsupportedException("previous");
        }
    }

            // Take the current last block and set the position after last.
            rows = fetched.lastBlock();
            cur = rows.size();

            // Fetch stream.
            if (stream.hasNext()) {
                fetched.add(requireNonNull(stream.next()));

                // Evict block if we've fetched too many rows.
                if (fetched.size() == MAX_FETCH_SIZE) {
                    onBlockEvict(fetched.evictFirstBlock());

                    assert fetched.size() < MAX_FETCH_SIZE;
                }
            }

            if (cur == rows.size())
                cur = Integer.MAX_VALUE; // We were not able to fetch anything. Done.
        
<methods>public void <init>(org.apache.ignite.internal.GridKernalContext) ,public boolean fetchedAll() ,public void setSources(Map<org.apache.ignite.cluster.ClusterNode,java.util.BitSet>) <variables>protected final java.util.concurrent.atomic.AtomicInteger activeSourcesCnt,protected Iterator<Value[]> iter,protected final PollableQueue<org.apache.ignite.internal.processors.query.h2.twostep.ReduceResultPage> queue