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++;
}
}
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()));
}
}
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;
}
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();
}
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());
}
Aggregations