Search in sources :

Example 1 with Cell

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);
}
Also used : ByteBuffer(java.nio.ByteBuffer) Cell(org.apache.cassandra.db.rows.Cell)

Example 2 with Cell

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;
}
Also used : ByteBuffer(java.nio.ByteBuffer) Cell(org.apache.cassandra.db.rows.Cell)

Example 3 with Cell

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());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) CellPath(org.apache.cassandra.db.rows.CellPath) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) ByteBufferUtil.bytes(org.apache.cassandra.utils.ByteBufferUtil.bytes) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) OpOrder(org.apache.cassandra.utils.concurrent.OpOrder) ListType(org.apache.cassandra.db.marshal.ListType) BufferCell(org.apache.cassandra.db.rows.BufferCell) BiConsumer(java.util.function.BiConsumer) Parameterized(org.junit.runners.Parameterized) ArrayCell(org.apache.cassandra.db.rows.ArrayCell) NativeCell(org.apache.cassandra.db.rows.NativeCell) Collection(java.util.Collection) BytesType(org.apache.cassandra.db.marshal.BytesType) Test(org.junit.Test) NativeAllocator(org.apache.cassandra.utils.memory.NativeAllocator) Collectors(java.util.stream.Collectors) UUIDGen(org.apache.cassandra.utils.UUIDGen) CellPath(org.apache.cassandra.db.rows.CellPath) List(java.util.List) Cell(org.apache.cassandra.db.rows.Cell) ImmediateFuture(org.apache.cassandra.utils.concurrent.ImmediateFuture) TableMetadata(org.apache.cassandra.schema.TableMetadata) ObjectSizes(org.apache.cassandra.utils.ObjectSizes) NativePool(org.apache.cassandra.utils.memory.NativePool) ArrayCell(org.apache.cassandra.db.rows.ArrayCell) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) NativePool(org.apache.cassandra.utils.memory.NativePool) ArrayList(java.util.ArrayList) NativeCell(org.apache.cassandra.db.rows.NativeCell) BufferCell(org.apache.cassandra.db.rows.BufferCell) ByteBuffer(java.nio.ByteBuffer) OpOrder(org.apache.cassandra.utils.concurrent.OpOrder) NativeAllocator(org.apache.cassandra.utils.memory.NativeAllocator) BufferCell(org.apache.cassandra.db.rows.BufferCell) ArrayCell(org.apache.cassandra.db.rows.ArrayCell) NativeCell(org.apache.cassandra.db.rows.NativeCell) Cell(org.apache.cassandra.db.rows.Cell)

Example 4 with Cell

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;
}
Also used : AbstractBTreePartition(org.apache.cassandra.db.partitions.AbstractBTreePartition) Partition(org.apache.cassandra.db.partitions.Partition) ImmutableBTreePartition(org.apache.cassandra.db.partitions.ImmutableBTreePartition) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Memtable(org.apache.cassandra.db.Memtable) Row(org.apache.cassandra.db.rows.Row) Cell(org.apache.cassandra.db.rows.Cell)

Example 5 with Cell

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()));
}
Also used : Cell(org.apache.cassandra.db.rows.Cell)

Aggregations

Cell (org.apache.cassandra.db.rows.Cell)8 ByteBuffer (java.nio.ByteBuffer)4 BufferCell (org.apache.cassandra.db.rows.BufferCell)3 Row (org.apache.cassandra.db.rows.Row)3 Test (org.junit.Test)3 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2 TableMetadata (org.apache.cassandra.schema.TableMetadata)2 Files (com.google.common.io.Files)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BiConsumer (java.util.function.BiConsumer)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1