use of org.apache.phoenix.schema.tuple.Tuple in project phoenix by apache.
the class RegionScannerResultIterator method next.
@Override
public Tuple next() throws SQLException {
// stopRegionOperation
synchronized (scanner) {
try {
// TODO: size
List<Cell> results = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond(), encodingScheme) : new ArrayList<Cell>();
// Results are potentially returned even when the return value of s.next is false
// since this is an indication of whether or not there are more values after the
// ones returned
boolean hasMore = scanner.nextRaw(results);
if (!hasMore && results.isEmpty()) {
return null;
}
// We instantiate a new tuple because in all cases currently we hang on to it
// (i.e. to compute and hold onto the TopN).
Tuple tuple = useQualifierAsIndex ? new PositionBasedMultiKeyValueTuple() : new MultiKeyValueTuple();
tuple.setKeyValues(results);
return tuple;
} catch (IOException e) {
throw ServerUtil.parseServerException(e);
}
}
}
use of org.apache.phoenix.schema.tuple.Tuple in project phoenix by apache.
the class RoundRobinResultIterator method next.
@Override
public Tuple next() throws SQLException {
List<RoundRobinIterator> iterators;
int size;
while ((size = (iterators = getIterators()).size()) > 0) {
index = index % size;
RoundRobinIterator itr = iterators.get(index);
if (itr.getNumRecordsRead() < threshold) {
Tuple tuple;
if ((tuple = itr.peek()) != null) {
tuple = itr.next();
if (itr.getNumRecordsRead() == threshold) {
numScannersCacheExhausted++;
}
index = (index + 1) % size;
return tuple;
} else {
// The underlying scanner is exhausted. Close the iterator and un-track it.
itr.close();
iterators.remove(index);
if (iterators.size() == 0) {
close();
}
}
} else {
index = (index + 1) % size;
}
}
return null;
}
use of org.apache.phoenix.schema.tuple.Tuple in project phoenix by apache.
the class RoundRobinResultIterator method fetchNextBatch.
private List<RoundRobinIterator> fetchNextBatch() throws SQLException {
int numExpectedIterators = openIterators.size();
List<Future<Tuple>> futures = new ArrayList<>(numExpectedIterators);
List<RoundRobinIterator> results = new ArrayList<>();
// Randomize the order in which we will be hitting region servers to try not overload particular region servers.
Collections.shuffle(openIterators);
boolean success = false;
SQLException toThrow = null;
try {
StatementContext context = plan.getContext();
final ConnectionQueryServices services = context.getConnection().getQueryServices();
ExecutorService executor = services.getExecutor();
numParallelFetches++;
if (logger.isDebugEnabled()) {
logger.debug("Performing parallel fetch for " + openIterators.size() + " iterators. ");
}
for (final RoundRobinIterator itr : openIterators) {
Future<Tuple> future = executor.submit(new Callable<Tuple>() {
@Override
public Tuple call() throws Exception {
// Read the next record to refill the scanner's cache.
return itr.next();
}
});
futures.add(future);
}
int i = 0;
for (Future<Tuple> future : futures) {
Tuple tuple = future.get();
if (tuple != null) {
results.add(new RoundRobinIterator(openIterators.get(i).delegate, tuple));
} else {
// Underlying scanner is exhausted. So close it.
openIterators.get(i).close();
}
i++;
}
success = true;
return results;
} catch (SQLException e) {
toThrow = e;
} catch (Exception e) {
toThrow = ServerUtil.parseServerException(e);
} finally {
try {
if (!success) {
try {
close();
} catch (Exception e) {
if (toThrow == null) {
toThrow = ServerUtil.parseServerException(e);
} else {
toThrow.setNextException(ServerUtil.parseServerException(e));
}
}
}
} finally {
if (toThrow != null) {
GLOBAL_FAILED_QUERY_COUNTER.increment();
throw toThrow;
}
}
}
// Not reachable
return null;
}
use of org.apache.phoenix.schema.tuple.Tuple in project phoenix by apache.
the class RowKeyOrderedAggregateResultIterator method nextTuple.
private Tuple nextTuple() throws SQLException {
List<PeekingResultIterator> iterators = getIterators();
while (index < iterators.size()) {
PeekingResultIterator iterator = iterators.get(index);
Tuple r = iterator.peek();
if (r != null) {
return iterator.next();
}
traversedIterator = true;
iterator.close();
index++;
}
return null;
}
use of org.apache.phoenix.schema.tuple.Tuple in project phoenix by apache.
the class RowKeyOrderedAggregateResultIterator method next.
@Override
public Tuple next() throws SQLException {
Tuple t = super.next();
if (t == null) {
return null;
}
aggregate(t);
return t;
}
Aggregations