Search in sources :

Example 16 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class ListsTest method testPrepender_execute.

private void testPrepender_execute(List<ByteBuffer> terms) {
    createTable("CREATE TABLE %s (k int PRIMARY KEY, l list<text>)");
    TableMetadata metaData = currentTableMetadata();
    ColumnMetadata columnMetadata = metaData.getColumn(ByteBufferUtil.bytes("l"));
    Term term = new Lists.Value(terms);
    Lists.Prepender prepender = new Lists.Prepender(columnMetadata, term);
    ByteBuffer keyBuf = ByteBufferUtil.bytes("key");
    DecoratedKey key = Murmur3Partitioner.instance.decorateKey(keyBuf);
    UpdateParameters parameters = new UpdateParameters(metaData, null, ClientState.forInternalCalls(), QueryOptions.DEFAULT, System.currentTimeMillis(), FBUtilities.nowInSeconds(), 1000, Collections.emptyMap());
    Clustering<?> clustering = Clustering.make(ByteBufferUtil.bytes(1));
    parameters.newRow(clustering);
    prepender.execute(key, parameters);
    Row row = parameters.buildRow();
    Assert.assertEquals(terms.size(), Iterators.size(row.cells().iterator()));
    int idx = 0;
    UUID last = null;
    for (Cell<?> cell : row.cells()) {
        UUID uuid = UUIDGen.getUUID(cell.path().get(0));
        if (last != null)
            Assert.assertTrue(last.compareTo(uuid) < 0);
        last = uuid;
        Assert.assertEquals(String.format("different values found: expected: '%d', found '%d'", ByteBufferUtil.toInt(terms.get(idx)), ByteBufferUtil.toInt(cell.buffer())), terms.get(idx), cell.value());
        idx++;
    }
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ByteBuffer(java.nio.ByteBuffer) Row(org.apache.cassandra.db.rows.Row) UUID(java.util.UUID)

Example 17 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class SSTableMetadataViewer method printMinMaxToken.

private void printMinMaxToken(Descriptor descriptor, IPartitioner partitioner, AbstractType<?> keyType) throws IOException {
    File summariesFile = new File(descriptor.filenameFor(Component.SUMMARY));
    if (!summariesFile.exists())
        return;
    try (DataInputStream iStream = new DataInputStream(Files.newInputStream(summariesFile.toPath()))) {
        Pair<DecoratedKey, DecoratedKey> firstLast = new IndexSummary.IndexSummarySerializer().deserializeFirstLastKey(iStream, partitioner);
        field("First token", firstLast.left.getToken(), keyType.getString(firstLast.left.getKey()));
        field("Last token", firstLast.right.getToken(), keyType.getString(firstLast.right.getKey()));
    }
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey) DataInputStream(java.io.DataInputStream) File(org.apache.cassandra.io.util.File) IndexSummary(org.apache.cassandra.io.sstable.IndexSummary)

Example 18 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class CassandraOutgoingFileTest method getKeyAtIndex.

private DecoratedKey getKeyAtIndex(int i) {
    int count = 0;
    DecoratedKey key;
    try (KeyIterator iter = new KeyIterator(sstable.descriptor, sstable.metadata())) {
        do {
            key = iter.next();
            count++;
        } while (iter.hasNext() && count < i);
    }
    return key;
}
Also used : KeyIterator(org.apache.cassandra.io.sstable.KeyIterator) DecoratedKey(org.apache.cassandra.db.DecoratedKey)

Example 19 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class CassandraStreamHeaderTest method header.

private CassandraStreamHeader header(boolean entireSSTable, boolean compressed) {
    List<Range<Token>> requestedRanges = Collections.singletonList(new Range<>(store.getPartitioner().getMinimumToken(), sstable.last.getToken()));
    requestedRanges = Range.normalize(requestedRanges);
    List<SSTableReader.PartitionPositionBounds> sections = sstable.getPositionsForRanges(requestedRanges);
    CompressionInfo compressionInfo = compressed ? CompressionInfo.newLazyInstance(sstable.getCompressionMetadata(), sections) : null;
    TableMetadata metadata = store.metadata();
    SerializationHeader.Component serializationHeader = SerializationHeader.makeWithoutStats(metadata).toComponent();
    ComponentManifest componentManifest = entireSSTable ? ComponentManifest.create(sstable.descriptor) : null;
    DecoratedKey firstKey = entireSSTable ? sstable.first : null;
    return CassandraStreamHeader.builder().withSSTableFormat(SSTableFormat.Type.BIG).withSSTableVersion(BigFormat.latestVersion).withSSTableLevel(0).withEstimatedKeys(10).withCompressionInfo(compressionInfo).withSections(sections).isEntireSSTable(entireSSTable).withComponentManifest(componentManifest).withFirstKey(firstKey).withSerializationHeader(serializationHeader).withTableId(metadata.id).build();
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) SerializationHeader(org.apache.cassandra.db.SerializationHeader) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Range(org.apache.cassandra.dht.Range)

Example 20 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class PartitionSerializationExceptionTest method testMessageWithCompositePartitionKey.

@Test
public void testMessageWithCompositePartitionKey() {
    TableMetadata metadata = TableMetadata.builder("ks", "tbl").addPartitionKeyColumn("pk1", UTF8Type.instance).addPartitionKeyColumn("pk2", UTF8Type.instance).build();
    DecoratedKey key = mock(DecoratedKey.class);
    CompositeType keyType = CompositeType.getInstance(UTF8Type.instance, UTF8Type.instance);
    when(key.getKey()).thenReturn(keyType.decompose("foo", "bar"));
    @SuppressWarnings("unchecked") BaseRowIterator<Unfiltered> partition = mock(BaseRowIterator.class);
    when(partition.metadata()).thenReturn(metadata);
    when(partition.partitionKey()).thenReturn(key);
    PartitionSerializationException pse = new PartitionSerializationException(partition, new RuntimeException());
    assertEquals("Failed to serialize partition key 'foo:bar' on table 'tbl' in keyspace 'ks'.", pse.getMessage());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) DecoratedKey(org.apache.cassandra.db.DecoratedKey) CompositeType(org.apache.cassandra.db.marshal.CompositeType) Test(org.junit.Test)

Aggregations

DecoratedKey (org.apache.cassandra.db.DecoratedKey)80 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)31 Test (org.junit.Test)28 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)22 ByteBuffer (java.nio.ByteBuffer)21 TableMetadata (org.apache.cassandra.schema.TableMetadata)20 Keyspace (org.apache.cassandra.db.Keyspace)18 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)16 ColumnFamily (org.apache.cassandra.db.ColumnFamily)8 QueryPath (org.apache.cassandra.db.filter.QueryPath)8 File (org.apache.cassandra.io.util.File)8 ArrayList (java.util.ArrayList)7 UUID (java.util.UUID)7 RowMutation (org.apache.cassandra.db.RowMutation)7 Table (org.apache.cassandra.db.Table)7 Row (org.apache.cassandra.db.rows.Row)7 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)7 Token (org.apache.cassandra.dht.Token)7 BufferDecoratedKey (org.apache.cassandra.db.BufferDecoratedKey)6 RowIndexEntry (org.apache.cassandra.db.RowIndexEntry)5