Search in sources :

Example 6 with Tuple

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);
        }
    }
}
Also used : EncodedColumnQualiferCellsList(org.apache.phoenix.schema.tuple.EncodedColumnQualiferCellsList) PositionBasedMultiKeyValueTuple(org.apache.phoenix.schema.tuple.PositionBasedMultiKeyValueTuple) PositionBasedMultiKeyValueTuple(org.apache.phoenix.schema.tuple.PositionBasedMultiKeyValueTuple) MultiKeyValueTuple(org.apache.phoenix.schema.tuple.MultiKeyValueTuple) IOException(java.io.IOException) Cell(org.apache.hadoop.hbase.Cell) PositionBasedMultiKeyValueTuple(org.apache.phoenix.schema.tuple.PositionBasedMultiKeyValueTuple) MultiKeyValueTuple(org.apache.phoenix.schema.tuple.MultiKeyValueTuple) Tuple(org.apache.phoenix.schema.tuple.Tuple)

Example 7 with Tuple

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;
}
Also used : Tuple(org.apache.phoenix.schema.tuple.Tuple)

Example 8 with Tuple

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) StatementContext(org.apache.phoenix.compile.StatementContext) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ConnectionQueryServices(org.apache.phoenix.query.ConnectionQueryServices) Tuple(org.apache.phoenix.schema.tuple.Tuple)

Example 9 with Tuple

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;
}
Also used : Tuple(org.apache.phoenix.schema.tuple.Tuple) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple)

Example 10 with Tuple

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;
}
Also used : Tuple(org.apache.phoenix.schema.tuple.Tuple) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple)

Aggregations

Tuple (org.apache.phoenix.schema.tuple.Tuple)48 SingleKeyValueTuple (org.apache.phoenix.schema.tuple.SingleKeyValueTuple)22 KeyValue (org.apache.hadoop.hbase.KeyValue)16 List (java.util.List)10 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 Expression (org.apache.phoenix.expression.Expression)8 SQLException (java.sql.SQLException)7 Cell (org.apache.hadoop.hbase.Cell)6 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)6 IOException (java.io.IOException)5 Region (org.apache.hadoop.hbase.regionserver.Region)5 ProjectedColumnExpression (org.apache.phoenix.expression.ProjectedColumnExpression)5 Aggregator (org.apache.phoenix.expression.aggregator.Aggregator)5 ResultIterator (org.apache.phoenix.iterate.ResultIterator)5 PColumn (org.apache.phoenix.schema.PColumn)5 ResultTuple (org.apache.phoenix.schema.tuple.ResultTuple)5 ClientAggregators (org.apache.phoenix.expression.aggregator.ClientAggregators)4 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)4