Search in sources :

Example 11 with Tuple

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

the class SequenceResultIterator method next.

@Override
public Tuple next() throws SQLException {
    Tuple next = super.next();
    if (next == null) {
        return null;
    }
    next = sequenceManager.newSequenceTuple(next);
    return next;
}
Also used : Tuple(org.apache.phoenix.schema.tuple.Tuple)

Example 12 with Tuple

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

the class CursorResultIterator method next.

@Override
public Tuple next() throws SQLException {
    if (!CursorUtil.moreValues(cursorName)) {
        return null;
    } else if (fetchSize == rowsRead) {
        return null;
    }
    Tuple next = delegate.next();
    CursorUtil.updateCursor(cursorName, next, delegate.peek());
    rowsRead++;
    return next;
}
Also used : Tuple(org.apache.phoenix.schema.tuple.Tuple)

Example 13 with Tuple

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

the class DistinctAggregatingResultIterator method next.

@Override
public Tuple next() throws SQLException {
    Iterator<ResultEntry> iterator = getResultIterator();
    if (iterator.hasNext()) {
        ResultEntry entry = iterator.next();
        Tuple tuple = entry.getResult();
        aggregate(tuple);
        return tuple;
    }
    resultIterator = Collections.emptyIterator();
    return null;
}
Also used : Tuple(org.apache.phoenix.schema.tuple.Tuple)

Example 14 with Tuple

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

the class RowKeyOrderedAggregateResultIteratorTest method testSpanThree.

@Test
public void testSpanThree() throws Exception {
    Tuple[] results1 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(1L))), new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(2L))) };
    Tuple[] results2 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(3L))) };
    Tuple[] results3 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(4L))), new SingleKeyValueTuple(new KeyValue(C, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(5L))) };
    final List<PeekingResultIterator> results = Arrays.asList(new PeekingResultIterator[] { new MaterializedResultIterator(Arrays.asList(results1)), new MaterializedResultIterator(Arrays.asList(results2)), new MaterializedResultIterator(Arrays.asList(results3)) });
    ResultIterators iterators = new MaterializedResultIterators(results);
    Tuple[] expectedResults = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(1L))), new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(9L))), new SingleKeyValueTuple(new KeyValue(C, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(5L))) };
    ClientAggregators aggregators = TestUtil.getSingleSumAggregator(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    ResultIterator scanner = new RowKeyOrderedAggregateResultIterator(iterators, aggregators);
    AssertResults.assertResults(scanner, expectedResults);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ClientAggregators(org.apache.phoenix.expression.aggregator.ClientAggregators) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) Tuple(org.apache.phoenix.schema.tuple.Tuple) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 15 with Tuple

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

the class IndexUtil method wrapResultUsingOffset.

public static void wrapResultUsingOffset(final RegionCoprocessorEnvironment environment, List<Cell> result, final int offset, ColumnReference[] dataColumns, TupleProjector tupleProjector, Region dataRegion, IndexMaintainer indexMaintainer, byte[][] viewConstants, ImmutableBytesWritable ptr) throws IOException {
    if (tupleProjector != null) {
        // Join back to data table here by issuing a local get projecting
        // all of the cq:cf from the KeyValueColumnExpression into the Get.
        Cell firstCell = result.get(0);
        byte[] indexRowKey = firstCell.getRowArray();
        ptr.set(indexRowKey, firstCell.getRowOffset() + offset, firstCell.getRowLength() - offset);
        byte[] dataRowKey = indexMaintainer.buildDataRowKey(ptr, viewConstants);
        Get get = new Get(dataRowKey);
        ImmutableStorageScheme storageScheme = indexMaintainer.getIndexStorageScheme();
        for (int i = 0; i < dataColumns.length; i++) {
            if (storageScheme == ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS) {
                get.addFamily(dataColumns[i].getFamily());
            } else {
                get.addColumn(dataColumns[i].getFamily(), dataColumns[i].getQualifier());
            }
        }
        Result joinResult = null;
        if (dataRegion != null) {
            joinResult = dataRegion.get(get);
        } else {
            TableName dataTable = TableName.valueOf(MetaDataUtil.getLocalIndexUserTableName(environment.getRegion().getTableDesc().getNameAsString()));
            HTableInterface table = null;
            try {
                table = environment.getTable(dataTable);
                joinResult = table.get(get);
            } finally {
                if (table != null)
                    table.close();
            }
        }
        // at this point join result has data from the data table. We now need to take this result and
        // add it to the cells that we are returning.
        // TODO: handle null case (but shouldn't happen)
        Tuple joinTuple = new ResultTuple(joinResult);
        // This will create a byte[] that captures all of the values from the data table
        byte[] value = tupleProjector.getSchema().toBytes(joinTuple, tupleProjector.getExpressions(), tupleProjector.getValueBitSet(), ptr);
        KeyValue keyValue = KeyValueUtil.newKeyValue(firstCell.getRowArray(), firstCell.getRowOffset(), firstCell.getRowLength(), VALUE_COLUMN_FAMILY, VALUE_COLUMN_QUALIFIER, firstCell.getTimestamp(), value, 0, value.length);
        result.add(keyValue);
    }
    ListIterator<Cell> itr = result.listIterator();
    while (itr.hasNext()) {
        final Cell cell = itr.next();
        // TODO: Create DelegateCell class instead
        Cell newCell = new Cell() {

            @Override
            public byte[] getRowArray() {
                return cell.getRowArray();
            }

            @Override
            public int getRowOffset() {
                return cell.getRowOffset() + offset;
            }

            @Override
            public short getRowLength() {
                return (short) (cell.getRowLength() - offset);
            }

            @Override
            public byte[] getFamilyArray() {
                return cell.getFamilyArray();
            }

            @Override
            public int getFamilyOffset() {
                return cell.getFamilyOffset();
            }

            @Override
            public byte getFamilyLength() {
                return cell.getFamilyLength();
            }

            @Override
            public byte[] getQualifierArray() {
                return cell.getQualifierArray();
            }

            @Override
            public int getQualifierOffset() {
                return cell.getQualifierOffset();
            }

            @Override
            public int getQualifierLength() {
                return cell.getQualifierLength();
            }

            @Override
            public long getTimestamp() {
                return cell.getTimestamp();
            }

            @Override
            public byte getTypeByte() {
                return cell.getTypeByte();
            }

            @Override
            public long getMvccVersion() {
                return cell.getMvccVersion();
            }

            @Override
            public long getSequenceId() {
                return cell.getSequenceId();
            }

            @Override
            public byte[] getValueArray() {
                return cell.getValueArray();
            }

            @Override
            public int getValueOffset() {
                return cell.getValueOffset();
            }

            @Override
            public int getValueLength() {
                return cell.getValueLength();
            }

            @Override
            public byte[] getTagsArray() {
                return cell.getTagsArray();
            }

            @Override
            public int getTagsOffset() {
                return cell.getTagsOffset();
            }

            @Override
            public int getTagsLength() {
                return cell.getTagsLength();
            }

            @Override
            public byte[] getValue() {
                return cell.getValue();
            }

            @Override
            public byte[] getFamily() {
                return cell.getFamily();
            }

            @Override
            public byte[] getQualifier() {
                return cell.getQualifier();
            }

            @Override
            public byte[] getRow() {
                return cell.getRow();
            }
        };
        itr.set(newCell);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) KeyValue(org.apache.hadoop.hbase.KeyValue) Get(org.apache.hadoop.hbase.client.Get) ResultTuple(org.apache.phoenix.schema.tuple.ResultTuple) ImmutableStorageScheme(org.apache.phoenix.schema.PTable.ImmutableStorageScheme) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) Cell(org.apache.hadoop.hbase.Cell) Tuple(org.apache.phoenix.schema.tuple.Tuple) ResultTuple(org.apache.phoenix.schema.tuple.ResultTuple) MetaDataMutationResult(org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult) Result(org.apache.hadoop.hbase.client.Result)

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