use of org.apache.cassandra.db.rows.CellPath 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());
}
use of org.apache.cassandra.db.rows.CellPath in project cassandra by apache.
the class CounterCacheKey method readCounterValue.
/**
* Reads the value of the counter represented by this key.
*
* @param cfs the store for the table this is a key of.
* @return the value for the counter represented by this key, or {@code null} if there
* is not such counter.
*/
public ByteBuffer readCounterValue(ColumnFamilyStore cfs) {
TableMetadata metadata = cfs.metadata();
assert metadata.id.equals(tableId) && Objects.equals(metadata.indexName().orElse(null), indexName);
DecoratedKey key = cfs.decorateKey(partitionKey());
int clusteringSize = metadata.comparator.size();
List<ByteBuffer> buffers = CompositeType.splitName(ByteBuffer.wrap(cellName), ByteBufferAccessor.instance);
// See makeCellName above
assert buffers.size() >= clusteringSize + 1;
Clustering<?> clustering = Clustering.make(buffers.subList(0, clusteringSize).toArray(new ByteBuffer[clusteringSize]));
ColumnMetadata column = metadata.getColumn(buffers.get(clusteringSize));
// try to load it. Not point if failing in any case, just skip the value.
if (column == null)
return null;
CellPath path = column.isComplex() ? CellPath.create(buffers.get(buffers.size() - 1)) : null;
int nowInSec = FBUtilities.nowInSeconds();
ColumnFilter.Builder builder = ColumnFilter.selectionBuilder();
if (path == null)
builder.add(column);
else
builder.select(column, path);
ClusteringIndexFilter filter = new ClusteringIndexNamesFilter(FBUtilities.singleton(clustering, metadata.comparator), false);
SinglePartitionReadCommand cmd = SinglePartitionReadCommand.create(metadata, nowInSec, key, builder.build(), filter);
try (ReadExecutionController controller = cmd.executionController();
RowIterator iter = UnfilteredRowIterators.filter(cmd.queryMemtableAndDisk(cfs, controller), nowInSec)) {
ByteBuffer value = null;
if (column.isStatic())
value = iter.staticRow().getCell(column).buffer();
else if (iter.hasNext())
value = iter.next().getCell(column).buffer();
return value;
}
}
Aggregations