Search in sources :

Example 26 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class CommitLogReaderTest method confirmReadOrder.

/**
     * Since we have both table and non mixed into the CL, we ignore updates that aren't for the table the test handler
     * is configured to check.
     * @param handler
     * @param offset integer offset of count we expect to see in record
     */
private void confirmReadOrder(TestCLRHandler handler, int offset) {
    ColumnMetadata cd = currentTableMetadata().getColumn(new ColumnIdentifier("data", false));
    int i = 0;
    int j = 0;
    while (i + j < handler.seenMutationCount()) {
        PartitionUpdate pu = handler.seenMutations.get(i + j).get(currentTableMetadata());
        if (pu == null) {
            j++;
            continue;
        }
        for (Row r : pu) {
            String expected = Integer.toString(i + offset);
            String seen = new String(r.getCell(cd).value().array());
            if (!expected.equals(seen))
                Assert.fail("Mismatch at index: " + i + ". Offset: " + offset + " Expected: " + expected + " Seen: " + seen);
        }
        i++;
    }
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) Row(org.apache.cassandra.db.rows.Row) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Example 27 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class RowTest method testHashCode.

@Test
public void testHashCode() {
    ColumnMetadata defA = metadata.getColumn(new ColumnIdentifier("a", true));
    ColumnMetadata defB = metadata.getColumn(new ColumnIdentifier("b", true));
    Row.Builder builder = BTreeRow.unsortedBuilder(nowInSeconds);
    builder.newRow(metadata.comparator.make("c1"));
    writeSimpleCellValue(builder, defA, "a1", 0);
    writeSimpleCellValue(builder, defA, "a2", 1);
    writeSimpleCellValue(builder, defB, "b1", 1);
    Row row = builder.build();
    Map<Row, Integer> map = new HashMap<>();
    map.put(row, 1);
    assertEquals(Integer.valueOf(1), map.get(row));
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) HashMap(java.util.HashMap) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) Test(org.junit.Test)

Example 28 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class RowTest method testResolve.

@Test
public void testResolve() {
    ColumnMetadata defA = metadata.getColumn(new ColumnIdentifier("a", true));
    ColumnMetadata defB = metadata.getColumn(new ColumnIdentifier("b", true));
    Row.Builder builder = BTreeRow.unsortedBuilder(nowInSeconds);
    builder.newRow(metadata.comparator.make("c1"));
    writeSimpleCellValue(builder, defA, "a1", 0);
    writeSimpleCellValue(builder, defA, "a2", 1);
    writeSimpleCellValue(builder, defB, "b1", 1);
    Row row = builder.build();
    PartitionUpdate update = PartitionUpdate.singleRowUpdate(metadata, dk, row);
    Unfiltered unfiltered = update.unfilteredIterator().next();
    assertTrue(unfiltered.kind() == Unfiltered.Kind.ROW);
    row = (Row) unfiltered;
    assertEquals("a2", defA.cellValueType().getString(row.getCell(defA).value()));
    assertEquals("b1", defB.cellValueType().getString(row.getCell(defB).value()));
    assertEquals(2, row.columns().size());
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Example 29 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class DynamicCompositeTypeTest method testFullRoundReversed.

@Test
public void testFullRoundReversed() throws Exception {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARDDYNCOMPOSITE);
    ByteBuffer cname1 = createDynamicCompositeKey("test1", null, -1, false, true);
    ByteBuffer cname2 = createDynamicCompositeKey("test1", uuids[0], 24, false, true);
    ByteBuffer cname3 = createDynamicCompositeKey("test1", uuids[0], 42, false, true);
    ByteBuffer cname4 = createDynamicCompositeKey("test2", uuids[0], -1, false, true);
    ByteBuffer cname5 = createDynamicCompositeKey("test2", uuids[1], 42, false, true);
    ByteBuffer key = ByteBufferUtil.bytes("kr");
    long ts = FBUtilities.timestampMicros();
    new RowUpdateBuilder(cfs.metadata(), ts, key).clustering(cname5).add("val", "cname5").build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata(), ts, key).clustering(cname1).add("val", "cname1").build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata(), ts, key).clustering(cname4).add("val", "cname4").build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata(), ts, key).clustering(cname2).add("val", "cname2").build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata(), ts, key).clustering(cname3).add("val", "cname3").build().applyUnsafe();
    ColumnMetadata cdef = cfs.metadata().getColumn(ByteBufferUtil.bytes("val"));
    ImmutableBTreePartition readPartition = Util.getOnlyPartitionUnfiltered(Util.cmd(cfs, key).build());
    Iterator<Row> iter = readPartition.iterator();
    compareValues(iter.next().getCell(cdef), "cname5");
    compareValues(iter.next().getCell(cdef), "cname4");
    // null UUID < reversed value
    compareValues(iter.next().getCell(cdef), "cname1");
    compareValues(iter.next().getCell(cdef), "cname3");
    compareValues(iter.next().getCell(cdef), "cname2");
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) Row(org.apache.cassandra.db.rows.Row) ImmutableBTreePartition(org.apache.cassandra.db.partitions.ImmutableBTreePartition) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 30 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class DynamicCompositeTypeTest method testFullRound.

@Test
public void testFullRound() throws Exception {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARDDYNCOMPOSITE);
    ByteBuffer cname1 = createDynamicCompositeKey("test1", null, -1, false);
    ByteBuffer cname2 = createDynamicCompositeKey("test1", uuids[0], 24, false);
    ByteBuffer cname3 = createDynamicCompositeKey("test1", uuids[0], 42, false);
    ByteBuffer cname4 = createDynamicCompositeKey("test2", uuids[0], -1, false);
    ByteBuffer cname5 = createDynamicCompositeKey("test2", uuids[1], 42, false);
    ByteBuffer key = ByteBufferUtil.bytes("k");
    long ts = FBUtilities.timestampMicros();
    new RowUpdateBuilder(cfs.metadata(), ts, key).clustering(cname5).add("val", "cname5").build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata(), ts, key).clustering(cname1).add("val", "cname1").build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata(), ts, key).clustering(cname4).add("val", "cname4").build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata(), ts, key).clustering(cname2).add("val", "cname2").build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata(), ts, key).clustering(cname3).add("val", "cname3").build().applyUnsafe();
    ColumnMetadata cdef = cfs.metadata().getColumn(ByteBufferUtil.bytes("val"));
    ImmutableBTreePartition readPartition = Util.getOnlyPartitionUnfiltered(Util.cmd(cfs, key).build());
    Iterator<Row> iter = readPartition.iterator();
    compareValues(iter.next().getCell(cdef), "cname1");
    compareValues(iter.next().getCell(cdef), "cname2");
    compareValues(iter.next().getCell(cdef), "cname3");
    compareValues(iter.next().getCell(cdef), "cname4");
    compareValues(iter.next().getCell(cdef), "cname5");
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) Row(org.apache.cassandra.db.rows.Row) ImmutableBTreePartition(org.apache.cassandra.db.partitions.ImmutableBTreePartition) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)123 Test (org.junit.Test)35 ByteBuffer (java.nio.ByteBuffer)23 Row (org.apache.cassandra.db.rows.Row)17 TableMetadata (org.apache.cassandra.schema.TableMetadata)16 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)15 AbstractType (org.apache.cassandra.db.marshal.AbstractType)8 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)5 java.util (java.util)4 IndexTarget (org.apache.cassandra.cql3.statements.IndexTarget)4 CollectionType (org.apache.cassandra.db.marshal.CollectionType)4 IndexMetadata (org.apache.cassandra.schema.IndexMetadata)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)3 ColumnFilter (org.apache.cassandra.db.filter.ColumnFilter)3 ImmutableBTreePartition (org.apache.cassandra.db.partitions.ImmutableBTreePartition)3 Cell (org.apache.cassandra.db.rows.Cell)3 RowIterator (org.apache.cassandra.db.rows.RowIterator)3 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)3