Search in sources :

Example 11 with ResultTuple

use of org.apache.phoenix.schema.tuple.ResultTuple in project phoenix by apache.

the class NonAggregateRegionScannerFactory method getOffsetScanner.

private RegionScanner getOffsetScanner(final RegionScanner s, final OffsetResultIterator iterator, final boolean isLastScan) throws IOException {
    final Tuple firstTuple;
    final Region region = getRegion();
    region.startRegionOperation();
    try {
        Tuple tuple = iterator.next();
        if (tuple == null && !isLastScan) {
            List<KeyValue> kvList = new ArrayList<KeyValue>(1);
            KeyValue kv = new KeyValue(QueryConstants.OFFSET_ROW_KEY_BYTES, QueryConstants.OFFSET_FAMILY, QueryConstants.OFFSET_COLUMN, PInteger.INSTANCE.toBytes(iterator.getRemainingOffset()));
            kvList.add(kv);
            Result r = new Result(kvList);
            firstTuple = new ResultTuple(r);
        } else {
            firstTuple = tuple;
        }
    } catch (Throwable t) {
        ServerUtil.throwIOException(getRegion().getRegionInfo().getRegionNameAsString(), t);
        return null;
    } finally {
        region.closeRegionOperation();
    }
    return new BaseRegionScanner(s) {

        private Tuple tuple = firstTuple;

        @Override
        public boolean isFilterDone() {
            return tuple == null;
        }

        @Override
        public boolean next(List<Cell> results) throws IOException {
            try {
                if (isFilterDone()) {
                    return false;
                }
                for (int i = 0; i < tuple.size(); i++) {
                    results.add(tuple.getValue(i));
                }
                tuple = iterator.next();
                return !isFilterDone();
            } catch (Throwable t) {
                ServerUtil.throwIOException(getRegion().getRegionInfo().getRegionNameAsString(), t);
                return false;
            }
        }

        @Override
        public void close() throws IOException {
            try {
                s.close();
            } finally {
                try {
                    if (iterator != null) {
                        iterator.close();
                    }
                } catch (SQLException e) {
                    ServerUtil.throwIOException(getRegion().getRegionInfo().getRegionNameAsString(), e);
                }
            }
        }
    };
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) SQLException(java.sql.SQLException) ResultTuple(org.apache.phoenix.schema.tuple.ResultTuple) ArrayList(java.util.ArrayList) Region(org.apache.hadoop.hbase.regionserver.Region) BaseRegionScanner(org.apache.phoenix.coprocessor.BaseRegionScanner) List(java.util.List) ArrayList(java.util.ArrayList) Tuple(org.apache.phoenix.schema.tuple.Tuple) ResultTuple(org.apache.phoenix.schema.tuple.ResultTuple) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

ResultTuple (org.apache.phoenix.schema.tuple.ResultTuple)11 Result (org.apache.hadoop.hbase.client.Result)8 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)6 Scan (org.apache.hadoop.hbase.client.Scan)6 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)5 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)4 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Cell (org.apache.hadoop.hbase.Cell)3 HTable (org.apache.hadoop.hbase.client.HTable)3 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)3 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)3 SingleCellColumnExpression (org.apache.phoenix.expression.SingleCellColumnExpression)3 Tuple (org.apache.phoenix.schema.tuple.Tuple)3 SQLException (java.sql.SQLException)2 KeyValue (org.apache.hadoop.hbase.KeyValue)2 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)2 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)2 ResultIterator (org.apache.phoenix.iterate.ResultIterator)2