public QueryPager getPager(PagingState pagingState, ProtocolVersion protocolVersion) { if (commands.size() == 1) return SinglePartitionReadCommand.getPager(commands.get(0), pagingState, protocolVersion); return new MultiPartitionPager(this, pagingState, protocolVersion); }
MultiPartitionPager(List<ReadCommand> commands, ConsistencyLevel consistencyLevel, ClientState cState, boolean localQuery, PagingState state, int limitForQuery) { int i = 0; // If it's not the beginning (state != null), we need to find where we were and skip previous commands // since they are done. if (state != null) for (; i < commands.size(); i++) if (commands.get(i).key.equals(state.partitionKey)) break; if (i >= commands.size()) { pagers = null; timestamp = -1; return; } pagers = new SinglePartitionPager[commands.size() - i]; // 'i' is on the first non exhausted pager for the previous page (or the first one) pagers[0] = makePager(commands.get(i), consistencyLevel, cState, localQuery, state); timestamp = commands.get(i).timestamp; // Following ones haven't been started yet for (int j = i + 1; j < commands.size(); j++) { ReadCommand command = commands.get(j); if (command.timestamp != timestamp) throw new IllegalArgumentException("All commands must have the same timestamp or weird results may happen."); pagers[j - i] = makePager(command, consistencyLevel, cState, localQuery, null); } remaining = state == null ? limitForQuery : state.remaining; }
public List<Row> fetchPage(int pageSize) throws RequestValidationException, RequestExecutionException { List<Row> result = new ArrayList<Row>(); int remainingThisQuery = Math.min(remaining, pageSize); while (remainingThisQuery > 0 && !isExhausted()) { // isExhausted has set us on the first non-exhausted pager List<Row> page = pagers[current].fetchPage(remainingThisQuery); if (page.isEmpty()) continue; Row row = page.get(0); int fetched = pagers[current].columnCounter().countAll(row.cf).live(); remaining -= fetched; remainingThisQuery -= fetched; result.add(row); } return result; }
public PagingState state() { // Sets current to the first non-exhausted pager if (isExhausted()) return null; PagingState state = pagers[current].state(); return new PagingState(pagers[current].key(), state == null ? null : state.cellName, remaining); }
public PagingState state() { // Sets current to the first non-exhausted pager if (isExhausted()) return null; PagingState state = pagers[current].state(); return new PagingState(pagers[current].key(), state == null ? null : state.rowMark, remaining, pagers[current].remainingInPartition()); }
public QueryPager getPager(PagingState pagingState, ProtocolVersion protocolVersion) { if (commands.size() == 1) return SinglePartitionReadCommand.getPager(commands.get(0), pagingState, protocolVersion); return new MultiPartitionPager(this, pagingState, protocolVersion); }
public PagingState state() { // Sets current to the first non-exhausted pager if (isExhausted()) return null; PagingState state = pagers[current].state(); return new PagingState(pagers[current].key(), state == null ? null : state.rowMark, remaining, pagers[current].remainingInPartition()); }
public QueryPager getPager(PagingState pagingState, ProtocolVersion protocolVersion) { if (commands.size() == 1) return SinglePartitionReadCommand.getPager(commands.get(0), pagingState, protocolVersion); return new MultiPartitionPager(this, pagingState, protocolVersion); }
public PagingState state() { // Sets current to the first non-exhausted pager if (isExhausted()) return null; PagingState state = pagers[current].state(); return new PagingState(pagers[current].key(), state == null ? null : state.rowMark, remaining, pagers[current].remainingInPartition()); }
public QueryPager withUpdatedLimit(DataLimits newLimits) { SinglePartitionPager[] newPagers = Arrays.copyOf(pagers, pagers.length); newPagers[current] = newPagers[current].withUpdatedLimit(newLimits); return new MultiPartitionPager(newPagers, newLimits, nowInSec, remaining, current); }
protected RowIterator computeNext() { while (result == null || !result.hasNext()) { if (result != null) { result.close(); counted += pagerMaxRemaining - pagers[current].maxRemaining(); } // We are done if we have reached the page size or in the case of GROUP BY if the current pager // is not exhausted. boolean isDone = counted >= pageSize || (result != null && limit.isGroupByLimit() && !pagers[current].isExhausted()); // isExhausted() will sets us on the first non-exhausted pager if (isDone || isExhausted()) { closed = true; return endOfData(); } pagerMaxRemaining = pagers[current].maxRemaining(); int toQuery = pageSize - counted; result = consistency == null ? pagers[current].fetchPageInternal(toQuery, executionController) : pagers[current].fetchPage(toQuery, consistency, clientState, queryStartNanoTime); } return result.next(); }
public QueryPager withUpdatedLimit(DataLimits newLimits) { SinglePartitionPager[] newPagers = Arrays.copyOf(pagers, pagers.length); newPagers[current] = newPagers[current].withUpdatedLimit(newLimits); return new MultiPartitionPager(newPagers, newLimits, nowInSec, remaining, current); }
protected RowIterator computeNext() { while (result == null || !result.hasNext()) { if (result != null) { result.close(); counted += pagerMaxRemaining - pagers[current].maxRemaining(); } // We are done if we have reached the page size or in the case of GROUP BY if the current pager // is not exhausted. boolean isDone = counted >= pageSize || (result != null && limit.isGroupByLimit() && !pagers[current].isExhausted()); // isExhausted() will sets us on the first non-exhausted pager if (isDone || isExhausted()) { closed = true; return endOfData(); } pagerMaxRemaining = pagers[current].maxRemaining(); int toQuery = pageSize - counted; result = consistency == null ? pagers[current].fetchPageInternal(toQuery, executionController) : pagers[current].fetchPage(toQuery, consistency, clientState, queryStartNanoTime); } return result.next(); }
public QueryPager withUpdatedLimit(DataLimits newLimits) { SinglePartitionPager[] newPagers = Arrays.copyOf(pagers, pagers.length); newPagers[current] = newPagers[current].withUpdatedLimit(newLimits); return new MultiPartitionPager(newPagers, newLimits, nowInSec, remaining, current); }
protected RowIterator computeNext() { while (result == null || !result.hasNext()) { if (result != null) { result.close(); counted += pagerMaxRemaining - pagers[current].maxRemaining(); } // We are done if we have reached the page size or in the case of GROUP BY if the current pager // is not exhausted. boolean isDone = counted >= pageSize || (result != null && limit.isGroupByLimit() && !pagers[current].isExhausted()); // isExhausted() will sets us on the first non-exhausted pager if (isDone || isExhausted()) { closed = true; return endOfData(); } pagerMaxRemaining = pagers[current].maxRemaining(); int toQuery = pageSize - counted; result = consistency == null ? pagers[current].fetchPageInternal(toQuery, executionController) : pagers[current].fetchPage(toQuery, consistency, clientState, queryStartNanoTime); } return result.next(); }
private static QueryPager pager(Pageable command, ConsistencyLevel consistencyLevel, ClientState cState, boolean local, PagingState state) { if (command instanceof Pageable.ReadCommands) { List<ReadCommand> commands = ((Pageable.ReadCommands)command).commands; if (commands.size() == 1) return pager(commands.get(0), consistencyLevel, cState, local, state); return new MultiPartitionPager(commands, consistencyLevel, cState, local, state, ((Pageable.ReadCommands) command).limitForQuery); } else if (command instanceof ReadCommand) { return pager((ReadCommand)command, consistencyLevel, cState, local, state); } else { assert command instanceof RangeSliceCommand; RangeSliceCommand rangeCommand = (RangeSliceCommand)command; if (rangeCommand.predicate instanceof NamesQueryFilter) return new RangeNamesQueryPager(rangeCommand, consistencyLevel, local, state); else return new RangeSliceQueryPager(rangeCommand, consistencyLevel, local, state); } }