Search in sources :

Example 1 with BufferCell

use of org.apache.cassandra.db.rows.BufferCell 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 2 with BufferCell

use of org.apache.cassandra.db.rows.BufferCell in project cassandra by apache.

the class CounterCellTest method testDigestWithEmptyCells.

@Test
public void testDigestWithEmptyCells() throws Exception {
    // For DB-1881
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(COUNTER1);
    ColumnMetadata emptyColDef = cfs.metadata().getColumn(ByteBufferUtil.bytes("val2"));
    BufferCell emptyCell = BufferCell.live(emptyColDef, 0, ByteBuffer.allocate(0));
    Row.Builder builder = BTreeRow.unsortedBuilder();
    builder.newRow(Clustering.make(AsciiSerializer.instance.serialize("test")));
    builder.addCell(emptyCell);
    Row row = builder.build();
    Digest digest = Digest.forReadResponse();
    row.digest(digest);
    assertNotNull(digest.digest());
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) BufferCell(org.apache.cassandra.db.rows.BufferCell) BTreeRow(org.apache.cassandra.db.rows.BTreeRow) Row(org.apache.cassandra.db.rows.Row) Test(org.junit.Test)

Example 3 with BufferCell

use of org.apache.cassandra.db.rows.BufferCell in project cassandra by apache.

the class RowFilterTest method testCQLFilterClose.

@Test
public void testCQLFilterClose() {
    // CASSANDRA-15126
    TableMetadata metadata = TableMetadata.builder("testks", "testcf").addPartitionKeyColumn("pk", Int32Type.instance).addStaticColumn("s", Int32Type.instance).addRegularColumn("r", Int32Type.instance).build();
    ColumnMetadata s = metadata.getColumn(new ColumnIdentifier("s", true));
    ColumnMetadata r = metadata.getColumn(new ColumnIdentifier("r", true));
    ByteBuffer one = Int32Type.instance.decompose(1);
    RowFilter filter = RowFilter.NONE.withNewExpressions(new ArrayList<>());
    filter.add(s, Operator.NEQ, one);
    AtomicBoolean closed = new AtomicBoolean();
    UnfilteredPartitionIterator iter = filter.filter(new SingletonUnfilteredPartitionIterator(new UnfilteredRowIterator() {

        public DeletionTime partitionLevelDeletion() {
            return null;
        }

        public EncodingStats stats() {
            return null;
        }

        public TableMetadata metadata() {
            return metadata;
        }

        public boolean isReverseOrder() {
            return false;
        }

        public RegularAndStaticColumns columns() {
            return null;
        }

        public DecoratedKey partitionKey() {
            return null;
        }

        public boolean hasNext() {
            return false;
        }

        public Unfiltered next() {
            return null;
        }

        public Row staticRow() {
            return BTreeRow.create(Clustering.STATIC_CLUSTERING, LivenessInfo.EMPTY, Row.Deletion.LIVE, BTree.singleton(new BufferCell(s, 1, Cell.NO_TTL, Cell.NO_DELETION_TIME, one, null)));
        }

        public void close() {
            closed.set(true);
        }
    }), 1);
    Assert.assertFalse(iter.hasNext());
    Assert.assertTrue(closed.get());
    filter = RowFilter.NONE.withNewExpressions(new ArrayList<>());
    filter.add(r, Operator.NEQ, one);
    closed.set(false);
    iter = filter.filter(new SingletonUnfilteredPartitionIterator(new UnfilteredRowIterator() {

        boolean hasNext = true;

        public DeletionTime partitionLevelDeletion() {
            return null;
        }

        public EncodingStats stats() {
            return null;
        }

        public TableMetadata metadata() {
            return metadata;
        }

        public boolean isReverseOrder() {
            return false;
        }

        public RegularAndStaticColumns columns() {
            return null;
        }

        public DecoratedKey partitionKey() {
            return null;
        }

        public Row staticRow() {
            return Rows.EMPTY_STATIC_ROW;
        }

        public boolean hasNext() {
            boolean r = hasNext;
            hasNext = false;
            return r;
        }

        public Unfiltered next() {
            return BTreeRow.create(Clustering.EMPTY, LivenessInfo.EMPTY, Row.Deletion.LIVE, BTree.singleton(new BufferCell(r, 1, Cell.NO_TTL, Cell.NO_DELETION_TIME, one, null)));
        }

        public void close() {
            closed.set(true);
        }
    }), 1);
    Assert.assertFalse(iter.hasNext());
    Assert.assertTrue(closed.get());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) DeletionTime(org.apache.cassandra.db.DeletionTime) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ArrayList(java.util.ArrayList) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) SingletonUnfilteredPartitionIterator(org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator) BufferCell(org.apache.cassandra.db.rows.BufferCell) ByteBuffer(java.nio.ByteBuffer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EncodingStats(org.apache.cassandra.db.rows.EncodingStats) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) BTreeRow(org.apache.cassandra.db.rows.BTreeRow) Row(org.apache.cassandra.db.rows.Row) SingletonUnfilteredPartitionIterator(org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator) Unfiltered(org.apache.cassandra.db.rows.Unfiltered) RegularAndStaticColumns(org.apache.cassandra.db.RegularAndStaticColumns) Test(org.junit.Test)

Aggregations

BufferCell (org.apache.cassandra.db.rows.BufferCell)3 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)3 Test (org.junit.Test)3 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 BTreeRow (org.apache.cassandra.db.rows.BTreeRow)2 Row (org.apache.cassandra.db.rows.Row)2 TableMetadata (org.apache.cassandra.schema.TableMetadata)2 Collection (java.util.Collection)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BiConsumer (java.util.function.BiConsumer)1 Collectors (java.util.stream.Collectors)1 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)1 DecoratedKey (org.apache.cassandra.db.DecoratedKey)1 DeletionTime (org.apache.cassandra.db.DeletionTime)1 RegularAndStaticColumns (org.apache.cassandra.db.RegularAndStaticColumns)1 BytesType (org.apache.cassandra.db.marshal.BytesType)1 ListType (org.apache.cassandra.db.marshal.ListType)1 SingletonUnfilteredPartitionIterator (org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator)1