use of org.apache.cassandra.db.rows.Cell in project cassandra by apache.
the class UserType method serializeForNativeProtocol.
public ByteBuffer serializeForNativeProtocol(Iterator<Cell> cells, ProtocolVersion protocolVersion) {
assert isMultiCell;
ByteBuffer[] components = new ByteBuffer[size()];
short fieldPosition = 0;
while (cells.hasNext()) {
Cell cell = cells.next();
// handle null fields that aren't at the end
short fieldPositionOfCell = ByteBufferUtil.toShort(cell.path().get(0));
while (fieldPosition < fieldPositionOfCell) components[fieldPosition++] = null;
components[fieldPosition++] = cell.value();
}
// append trailing nulls for missing cells
while (fieldPosition < size()) components[fieldPosition++] = null;
return TupleType.buildValue(components);
}
use of org.apache.cassandra.db.rows.Cell in project cassandra by apache.
the class MapType method serializedValues.
public List<ByteBuffer> serializedValues(Iterator<Cell> cells) {
assert isMultiCell;
List<ByteBuffer> bbs = new ArrayList<ByteBuffer>();
while (cells.hasNext()) {
Cell c = cells.next();
bbs.add(c.path().get(0));
bbs.add(c.value());
}
return bbs;
}
use of org.apache.cassandra.db.rows.Cell in project cassandra by apache.
the class CellSpecTest method data.
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
TableMetadata table = TableMetadata.builder("testing", "testing").addPartitionKeyColumn("pk", BytesType.instance).build();
byte[] rawBytes = { 0, 1, 2, 3, 4, 5, 6 };
ByteBuffer bbBytes = ByteBuffer.wrap(rawBytes);
NativePool pool = new NativePool(1024, 1024, 1, () -> ImmediateFuture.success(true));
NativeAllocator allocator = pool.newAllocator(null);
OpOrder order = new OpOrder();
List<Cell<?>> tests = new ArrayList<>();
BiConsumer<ColumnMetadata, CellPath> fn = (column, path) -> {
tests.add(new ArrayCell(column, 1234, 1, 1, rawBytes, path));
tests.add(new BufferCell(column, 1234, 1, 1, bbBytes, path));
tests.add(new NativeCell(allocator, order.getCurrent(), column, 1234, 1, 1, bbBytes, path));
};
// simple
fn.accept(ColumnMetadata.regularColumn(table, bytes("simple"), BytesType.instance), null);
// complex
// seems NativeCell does not allow CellPath.TOP, or CellPath.BOTTOM
fn.accept(ColumnMetadata.regularColumn(table, bytes("complex"), ListType.getInstance(BytesType.instance, true)), CellPath.create(bytes(UUIDGen.getTimeUUID())));
return tests.stream().map(a -> new Object[] { a.getClass().getSimpleName() + ":" + (a.path() == null ? "simple" : "complex"), a }).collect(Collectors.toList());
}
use of org.apache.cassandra.db.rows.Cell in project cassandra by apache.
the class Ballots method latestBallotsFromPaxosMemtable.
/**
* Load the current paxos state for the table and key
*/
private static long[] latestBallotsFromPaxosMemtable(DecoratedKey key, TableMetadata metadata) {
ColumnFamilyStore paxos = Keyspace.open("system").getColumnFamilyStore("paxos");
long[] result = new long[3];
List<Memtable> memtables = ImmutableList.copyOf(paxos.getTracker().getView().getAllMemtables());
for (Memtable memtable : memtables) {
Partition partition = memtable.getPartition(key);
if (partition == null)
continue;
Row row = partition.getRow(paxos.metadata.get().comparator.make(metadata.id));
if (row == null)
continue;
Cell promise = row.getCell(PROMISE);
if (promise != null && promise.value() != null)
result[0] = promise.timestamp();
Cell proposal = row.getCell(PROPOSAL);
if (proposal != null && proposal.value() != null)
result[1] = proposal.timestamp();
Cell commit = row.getCell(COMMIT);
if (commit != null && commit.value() != null)
result[2] = commit.timestamp();
}
return result;
}
use of org.apache.cassandra.db.rows.Cell in project cassandra by apache.
the class QueryPagerTest method assertCell.
private void assertCell(Row row, ColumnMetadata column, int value) {
Cell cell = row.getCell(column);
assertNotNull(cell);
assertEquals(value, ByteBufferUtil.toInt(cell.value()));
}
Aggregations