use of org.apache.phoenix.schema.tuple.Tuple in project phoenix by apache.
the class OrderedResultIterator method getResultIterator.
private PeekingResultIterator getResultIterator() throws SQLException {
if (resultIterator != null) {
return resultIterator;
}
final int numSortKeys = orderByExpressions.size();
List<Expression> expressions = Lists.newArrayList(Collections2.transform(orderByExpressions, TO_EXPRESSION));
final Comparator<ResultEntry> comparator = buildComparator(orderByExpressions);
try {
final MappedByteBufferSortedQueue queueEntries = new MappedByteBufferSortedQueue(comparator, limit, thresholdBytes);
resultIterator = new PeekingResultIterator() {
int count = 0;
@Override
public Tuple next() throws SQLException {
ResultEntry entry = queueEntries.poll();
while (entry != null && offset != null && count < offset) {
count++;
if (entry.getResult() == null) {
return null;
}
entry = queueEntries.poll();
}
if (entry == null || (limit != null && count++ > limit)) {
resultIterator.close();
resultIterator = PeekingResultIterator.EMPTY_ITERATOR;
return null;
}
return entry.getResult();
}
@Override
public Tuple peek() throws SQLException {
ResultEntry entry = queueEntries.peek();
while (entry != null && offset != null && count < offset) {
entry = queueEntries.poll();
count++;
if (entry == null) {
return null;
}
}
if (limit != null && count > limit) {
return null;
}
entry = queueEntries.peek();
if (entry == null) {
return null;
}
return entry.getResult();
}
@Override
public void explain(List<String> planSteps) {
}
@Override
public void close() throws SQLException {
queueEntries.close();
}
};
for (Tuple result = delegate.next(); result != null; result = delegate.next()) {
int pos = 0;
ImmutableBytesWritable[] sortKeys = new ImmutableBytesWritable[numSortKeys];
for (Expression expression : expressions) {
final ImmutableBytesWritable sortKey = new ImmutableBytesWritable();
boolean evaluated = expression.evaluate(result, sortKey);
// set the sort key that failed to get evaluated with null
sortKeys[pos++] = evaluated && sortKey.getLength() > 0 ? sortKey : null;
}
queueEntries.add(new ResultEntry(sortKeys, result));
}
this.byteSize = queueEntries.getByteSize();
} catch (IOException e) {
ServerUtil.createIOException(e.getMessage(), e);
} finally {
delegate.close();
}
return resultIterator;
}
use of org.apache.phoenix.schema.tuple.Tuple in project phoenix by apache.
the class ConcatResultIterator method currentIterator.
private PeekingResultIterator currentIterator() throws SQLException {
List<PeekingResultIterator> iterators = getIterators();
while (index < iterators.size()) {
PeekingResultIterator iterator = iterators.get(index);
Tuple r = iterator.peek();
if (r != null) {
return iterator;
}
iterator.close();
index++;
}
return EMPTY_ITERATOR;
}
use of org.apache.phoenix.schema.tuple.Tuple in project phoenix by apache.
the class DistinctAggregatingResultIterator method getResultIterator.
private Iterator<ResultEntry> getResultIterator() throws SQLException {
if (resultIterator != null) {
return resultIterator;
}
// TODO: size?
Set<ResultEntry> entries = Sets.<ResultEntry>newHashSet();
try {
for (Tuple result = delegate.next(); result != null; result = delegate.next()) {
ResultEntry entry = new ResultEntry(result);
entries.add(entry);
}
} finally {
delegate.close();
}
resultIterator = entries.iterator();
return resultIterator;
}
use of org.apache.phoenix.schema.tuple.Tuple in project phoenix by apache.
the class LookAheadResultIterator method next.
@Override
public Tuple next() throws SQLException {
init();
Tuple next = this.next;
this.next = advance();
return next;
}
use of org.apache.phoenix.schema.tuple.Tuple in project phoenix by apache.
the class MaterializedComparableResultIterator method next.
@Override
public Tuple next() throws SQLException {
Tuple next = delegate.next();
this.current = delegate.peek();
return next;
}
Aggregations