Executes a {@code RowQuery} with {@code autoPaginate(true)} repeatedly as necessary to fetch all pages.
351770
private <K, C> Iterator<Column<C>> executePaginated(final RowQuery<K, C> query) {
        return Iterators.concat(new AbstractIterator<Iterator<Column<C>>>() {
            @Override
            protected Iterator<Column<C>> computeNext() {
                ColumnList<C> page = execute(query);
                return !page.isEmpty() ? page.iterator() : endOfData();
            }
        });
    }
699987
public static Iterator<ColumnFamily> pageRowLocally(final ColumnFamilyStore cfs, ByteBuffer key, final int pageSize)
    {
        SliceFromReadCommand command = new SliceFromReadCommand(cfs.metadata.ksName, key, cfs.name, System.currentTimeMillis(), new IdentityQueryFilter());
        final SliceQueryPager pager = new SliceQueryPager(command, null, null, true);

        return new Iterator<ColumnFamily>()
        {
            // We don't use AbstractIterator because we don't want hasNext() to do an actual query
            public boolean hasNext()
            {
                return !pager.isExhausted();
            }

            public ColumnFamily next()
            {
                try
                {
                    List<Row> rows = pager.fetchPage(pageSize);
                    ColumnFamily cf = rows.isEmpty() ? null : rows.get(0).cf;
                    return cf == null ? ArrayBackedSortedColumns.factory.create(cfs.metadata) : cf;
                }
                catch (Exception e)
                {
                    throw new RuntimeException(e);
                }
            }

            public void remove()
            {
                throw new UnsupportedOperationException();
            }
        };
    }
1261944
static Iterator<Page> lazySearch(final Wikipedia wikipedia, final String query) {
    final Response<Page> first = wikipedia.search(query);
    if (first.nextOffset == null) {
      return first.iterator();
    }
    return new Iterator<Page>() {
      Iterator<Page> current = first.iterator();
      Long nextOffset = first.nextOffset;

      @Override
      public boolean hasNext() {
        while (!current.hasNext() && nextOffset != null) {
          System.out.println("Wow.. even more results than " + nextOffset);
          Response<Page> nextPage = wikipedia.resumeSearch(query, nextOffset);
          current = nextPage.iterator();
          nextOffset = nextPage.nextOffset;
        }
        return current.hasNext();
      }

      @Override
      public Page next() {
        return current.next();
      }

      @Override
      public void remove() {
        throw new UnsupportedOperationException();
      }
    };
  }
550496
public static ListenableFuture<ResultSet> executeAdaptiveQueryAsync(Session session, Statement statement, int fetchSize) {
        return executeAdaptiveQueryAsync(session, statement, fetchSize, MAX_ADAPTATIONS);
    }
391564
private void runQuery() {
		if(this.rowKeysList != null && this.rowKeysList.size() > 0) { // Check if there are rowkeys to query Cassandra
			if (threadCount > 1) { // When thread count greater than 1 enables parallelism, use threads to query Cassandra
				// multiple times
				
				ExecutorService executor = Executors
						.newFixedThreadPool(threadCount);
				List<Future<?>> futures = new LinkedList<Future<?>>();

				for (final List<K> param : this.rowKeysList) {
					Future<?> future = executor.submit(new Runnable() {
						public void run() {
							// Query Cassandra with the input keys provided
							runMultigetSliceQuery(param); 
							
						}
					});

					futures.add(future);
				}

				for (Future<?> f : futures) {// iterate through thread results
					try {
						f.get(); // wait for thread to complete

					} catch (InterruptedException e) {
						throw new HectorException("Failed to retrieve rows from Cassandra.",e);
					} 
					catch (ExecutionException e) {
						throw new HectorException("Failed to retrieve rows from Cassandra.",e);
					} 
				}
				// Safe to shutdown the threadpool and release the resources
				executor.shutdown(); 

				// set the rowKeysIndex to size of input keys so as no further calls
				// will be made to Cassandra.
				// This ensures iterator.hasNext() returns false when all keys are
				// queried
				rowKeysIndex = this.rowKeysList.size();

			}
			else {// When thread count less than or equal to 1 (0 or negative) disables
				// parallelism, set of(maxRowCountPerQuery) keys queries
				// Cassandra at a time
			
				runMultigetSliceQuery(this.rowKeysList.get(rowKeysIndex));
				// Increment the rowKeyIndex instead of setting it to  this.rowKeysList.size(); 
				rowKeysIndex++; 
				
			}
		}

		ArrayList<Row<K, N, V>> resultList = new ArrayList<Row<K, N, V>>(queryResult.size());

		synchronized (queryResult) {
			// Ensure that runMultigetSliceQuery() method call updates global
			// variable queryResult with query result (if exists)
			if (queryResult != null && queryResult.size() > 0)	{
				for (Rows<K, N, V> rows : queryResult) {
					if (rows != null && rows.getCount() > 0) {
						for (Row<K, N, V> row : rows) {
							// prepare List<Row<K, N, V>> to return
							// the iterator of <Row<K,N,V>> to the caller
							resultList.add(row);
						}
					}

				}
			}
		}

		// assign global iterator with the result of multigetSliceQuery
		iterator = resultList.iterator(); 
										

	}
222802
@Override
    public PaginatedList queryForPaginatedList(String statementName, Object parameterObject,
                                               int pageSize) throws DataAccessException {
        return super.queryForPaginatedList(statementName, parameterObject, pageSize);
    }
1343705
private void updatePage() {
		// retrieve page
		final int retrievalPage = page == LAST_PAGE ? pageCount : page;
		final List<Row> rows;
		try {
			rows = client.getExecutor().retrieveResultPage(resultDescriptor.getResultId(), retrievalPage);
		} catch (SqlExecutionException e) {
			close(e);
			return;
		}

		// convert page
		final List<String[]> stringRows = rows
				.stream()
				.map(CliUtils::rowToString)
				.collect(Collectors.toList());

		// update results
		if (previousResultsPage == retrievalPage) {
			// only use the previous results if the current page number has not changed
			// this allows for updated results when the key space remains constant
			previousResults = results;
		} else {
			previousResults = null;
			previousResultsPage = retrievalPage;
		}

		results = stringRows;

		// check if selected row is still valid
		if (selectedRow != NO_ROW_SELECTED) {
			if (selectedRow >= results.size()) {
				selectedRow = NO_ROW_SELECTED;
			}
		}

		// reset view
		resetAllParts();
	}
618722
public void execute(final HttpQuery query) {
    http_query = query;
    final QueryStats query_stats = 
        new QueryStats(query.getRemoteAddress(), ts_query, query.getHeaders());
    ts_query.setQueryStats(query_stats);
    
    /**
     * Sends the serialized results to the caller. This should be the very
     * last callback executed.
     */
    class CompleteCB implements Callback<Object, ChannelBuffer> {
      @Override
      public Object call(final ChannelBuffer cb) throws Exception {
        query.sendReply(cb);
        return null;
      }
    }
    
    /**
     * After all of the queries have run and we have data (or not) then we
     * need to compile the iterators.
     * This class could probably be improved:
     * First we iterate over the results AND for each result, iterate over
     * the expressions, giving a time synced iterator to each expression that 
     * needs the result set.
     * THEN we iterate over the expressions again and build a DAG to determine
     * if any of the expressions require the output of an expression. If so
     * then we add the expressions to the proper parent and compile them in
     * order.
     * After all of that we're ready to start serializing and iterating
     * over the results.
     */
    class QueriesCB implements Callback<Object, ArrayList<DataPoints[]>> {
      public Object call(final ArrayList<DataPoints[]> query_results) 
        throws Exception {
        
        for (int i = 0; i < query_results.size(); i++) {
          final TSSubQuery sub = ts_query.getQueries().get(i);
          
          Iterator<Entry<String, TSSubQuery>> it = sub_queries.entrySet().iterator();
          while (it.hasNext()) {
            final Entry<String, TSSubQuery> entry = it.next();
            if (entry.getValue().equals(sub)) {
              sub_query_results.put(entry.getKey(), query_results.get(i));
              for (final ExpressionIterator ei : expressions.values()) {
                if (ei.getVariableNames().contains(entry.getKey())) {
                  final TimeSyncedIterator tsi = new TimeSyncedIterator(
                      entry.getKey(), sub.getFilterTagKs(), 
                      query_results.get(i));
                  final NumericFillPolicy fill = fills.get(entry.getKey());
                  if (fill != null) {
                    tsi.setFillPolicy(fill);
                  }
                  ei.addResults(entry.getKey(), tsi);
                  if (LOG.isDebugEnabled()) {
                    LOG.debug("Added results for " + entry.getKey() + 
                        " to " + ei.getId());
                  }
                }
              }
            }
          }
        }

        // handle nested expressions
        final DirectedAcyclicGraph<String, DefaultEdge> graph = 
            new DirectedAcyclicGraph<String, DefaultEdge>(DefaultEdge.class);

        for (final Entry<String, ExpressionIterator> eii : expressions.entrySet()) {
          if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Expression entry key is %s, value is %s", 
                eii.getKey(), eii.getValue().toString()));
            LOG.debug(String.format("Time to loop through the variable names "
                + "for %s", eii.getKey()));
          }

          if (!graph.containsVertex(eii.getKey())) {
            if (LOG.isDebugEnabled()) {
              LOG.debug("Adding vertex " + eii.getKey());
            }
            graph.addVertex(eii.getKey());
          }

          for (final String var : eii.getValue().getVariableNames()) {
            if (LOG.isDebugEnabled()) {
              LOG.debug(String.format("var is %s", var));
            }

            final ExpressionIterator ei = expressions.get(var);

            if (ei != null) {
              if (LOG.isDebugEnabled()) {
                LOG.debug(String.format("The expression iterator for %s is %s", 
                    var, ei.toString()));
              }

              // TODO - really ought to calculate this earlier
              if (eii.getKey().equals(var)) {
                throw new IllegalArgumentException(
                    "Self referencing expression found: " + eii.getKey());
              }

              if (LOG.isDebugEnabled()) {
                LOG.debug("Nested expression detected. " + eii.getKey() + 
                    " depends on " + var);
              }

              if (!graph.containsVertex(eii.getKey())) {
                if (LOG.isDebugEnabled()) {
                  LOG.debug("Added vertex " + eii.getKey());
                }
                graph.addVertex(eii.getKey());
              } else if (LOG.isDebugEnabled()) {
                LOG.debug("Already contains vertex " + eii.getKey());
              }

              if (!graph.containsVertex(var)) {
                if (LOG.isDebugEnabled()) {
                  LOG.debug("Added vertex " + var);
                }
                graph.addVertex(var);
              } else if (LOG.isDebugEnabled()) {
                LOG.debug("Already contains vertex " + var);
              }

              try {
                if (LOG.isDebugEnabled()) {
                  LOG.debug("Added Edge " + eii.getKey() + " - " + var);
                }
                graph.addDagEdge(eii.getKey(), var);
              } catch (CycleFoundException cfe) {
                throw new IllegalArgumentException("Circular reference found: " + 
                    eii.getKey(), cfe);
              }
            } else if (LOG.isDebugEnabled()) {
              LOG.debug(String.format("The expression iterator for %s is null", var));
            }
          }
        }

        // compile all of the expressions
        final long intersect_start = DateTime.currentTimeMillis();

        final Integer expressionLength = expressions.size();
        final ExpressionIterator[] compile_stack = 
            new ExpressionIterator[expressionLength];
        final TopologicalOrderIterator<String, DefaultEdge> it = 
            new TopologicalOrderIterator<String, DefaultEdge>(graph);

        if (LOG.isDebugEnabled()) {
          LOG.debug(String.format("Expressions Size is %d", expressionLength));
          LOG.debug(String.format("Topology Iterator %s", it.toString()));
        }

        int i = 0;
        while (it.hasNext()) {
          String next = it.next();
          if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Expression: %s", next));
          }
          ExpressionIterator ei = expressions.get(next);
          if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Expression Iterator: %s", ei.toString()));
          }
          if (ei == null) {
            LOG.error(String.format("The expression iterator for %s is null", next));
          }
          compile_stack[i] = ei;
          if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Added expression %s to compile_stack[%d]", 
                next, i));
          }
          i++;
        }

        if (i != expressionLength) {
          throw new IOException(String.format(" Internal Error: Fewer "
              + "expressions where added to the compile stack than "
              + "expressions.size (%d instead of %d)", i, expressionLength));
        }

        if (LOG.isDebugEnabled()) {
          LOG.debug(String.format("compile stack length: %d", compile_stack.length));
        }

        for (int x = compile_stack.length - 1; x >= 0; x--) {
          if (compile_stack[x] == null) {
            throw new NullPointerException(String.format("Item %d in "
                + "compile_stack[] is null", x));
          }
          // look for and add expressions
          for (final String var : compile_stack[x].getVariableNames()) {
            if (LOG.isDebugEnabled()) {
              LOG.debug(String.format("Looking for variable %s for %s", var, 
                  compile_stack[x].getId()));
            }
            ExpressionIterator source = expressions.get(var);
            if (source != null) {
              compile_stack[x].addResults(var, source.getCopy());
              if (LOG.isDebugEnabled()) {
                LOG.debug(String.format("Adding expression %s to %s", 
                    source.getId(), compile_stack[x].getId()));
              }
            }
          }
          compile_stack[x].compile();
          if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Successfully compiled %s", 
                compile_stack[x].getId()));
          }
        }

        if (LOG.isDebugEnabled()) {
          LOG.debug("Finished compilations in " +
              (DateTime.currentTimeMillis() - intersect_start) + " ms");
        }
        
        return serialize()
            .addCallback(new CompleteCB())
            .addErrback(new ErrorCB());
      }
    }
    
    /**
     * Callback executed after we have resolved the metric, tag names and tag
     * values to their respective UIDs. This callback then runs the actual 
     * queries and fetches their results.
     */
    class BuildCB implements Callback<Deferred<Object>, net.opentsdb.core.Query[]> {
      @Override
      public Deferred<Object> call(final net.opentsdb.core.Query[] queries) {
        final ArrayList<Deferred<DataPoints[]>> deferreds = 
            new ArrayList<Deferred<DataPoints[]>>(queries.length);
        
        for (final net.opentsdb.core.Query query : queries) {
          deferreds.add(query.runAsync());
        }
        return Deferred.groupInOrder(deferreds).addCallback(new QueriesCB())
            .addErrback(new ErrorCB());
      }
    }
    
    // TODO - only run the ones that will be involved in an output. Folks WILL
    // ask for stuff they don't need.... *sigh*
    ts_query.buildQueriesAsync(tsdb)
      .addCallback(new BuildCB())
      .addErrback(new ErrorCB());
  }
504682
protected Collection invokePage(int pPageIndex, int pPageSize) {
        if(mDao instanceof BaseSelectPageMapper)
        {
            return ((BaseSelectPageMapper)mDao).selectPage(createModel(),pPageIndex,pPageSize);
        }
        else if( mDao instanceof MysqlSelectPageMapper)
        {
            return ((MysqlSelectPageMapper)mDao).selectPage(createModel(),pPageIndex,pPageSize);
        }
        else if(mDao instanceof  Mapper)
        {
            Mapper mapper= (Mapper)mDao;
            return mapper.selectByRowBounds(createModel(),new RowBounds(pPageIndex-1,pPageSize));
        }
        return new ArrayList();
    }
1138021
public Deferred<SearchQuery> executeSearch(final SearchQuery query) {
    if (search == null) {
      throw new IllegalStateException(
          "Searching has not been enabled on this TSD");
    }

    return search.executeQuery(query);
  }
456030
private void sequenceQuery(QueryEntry entry, CompletableFuture<QueryResponse> future) {
    // Get the client's server session. If the session doesn't exist, return an unknown session error.
    ServerSessionContext session = context.getStateMachine().executor().context().sessions().getSession(entry.getSession());
    if (session == null) {
      future.complete(logResponse(QueryResponse.builder()
        .withStatus(Response.Status.ERROR)
        .withError(CopycatError.Type.UNKNOWN_SESSION_ERROR)
        .build()));
    } else {
      sequenceQuery(entry, session, future);
    }
  }
417695
def iterativeFetch(query, batchSize=default_batch_size):
    
    while True:
        rows = query.fetchmany(batchSize)
        if not rows:
            break
        rowDicts = sqliteRowsToDicts(rows)
        for rowDict in rowDicts:
            yield rowDict
1310846
public void execute(@Param("nodeId") Long nodeId, @Param("pageIndex") int pageIndex,
                        @Param("searchKey") String searchKey, Context context, Navigator nav) throws Exception {
        Node node = nodeService.findById(nodeId);
        if (node.getStatus().isStart()) {
            nav.redirectTo(WebConstant.ERROR_FORBIDDEN_Link);
            return;
        }

        List<AutoKeeperCluster> zkClusters = autoKeeperClusterService.listAutoKeeperClusters();
        context.put("zkClusters", zkClusters);
        context.put("node", node);
        context.put("pageIndex", pageIndex);
        context.put("searchKey", searchKey);
    }
168835
public static FutureRowCount applyPageList(MultivaluedMap<String, String> queryParams, Query query) {

        FutureRowCount futureRowCount = fetchRowCount(queryParams, query);

        applyPageConfig(queryParams, query);

        return futureRowCount;
    }
564436
function RowStatementPostExec(
    statementOptions, context, services, connectionConfig)
{
  // call super
  BaseStatement.apply(this, arguments);

  // add the result request headers to the context
  context.resultRequestHeaders = buildResultRequestHeadersRow();

  /**
   * Called when the statement request is successful.
   *
   * @param {Object} body
   */
  context.onStatementRequestSucc =
      createOnStatementRequestSuccRow(this, context);

  /**
   * Fetches the rows in this statement's result and invokes the each()
   * callback on each row. If startIndex and endIndex values are specified, the
   * each() callback will only be invoked on rows in the requested range. The
   * end() callback will be invoked when either all the requested rows have been
   * successfully processed, or if an error was encountered while trying to
   * fetch the requested rows.
   *
   * @param {Object} options
   */
  this.fetchRows = createFnFetchRows(this, context);

  /**
   * Streams the rows in this statement's result. If start and end values are
   * specified, only rows in the specified range are streamed.
   *
   * @param {Object} options
   */
  this.streamRows = createFnStreamRows(this, context);

  // send a request to fetch the result
  sendRequestPostExec(context, context.onStatementRequestComp);
}
714201
public ResultSet executeQuery(ReadContext context, Options.QueryOption... options) {
    return context.executeQuery(this, options);
  }
750214
@Override
    public PaginatedList queryForPaginatedList(String statementName, int pageSize)
            throws DataAccessException {
        return super.queryForPaginatedList(statementName, pageSize);
    }