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;
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations