Search in sources :

Example 1 with ClusteringIndexFilter

use of org.apache.cassandra.db.filter.ClusteringIndexFilter in project cassandra by apache.

the class CassandraIndexTest method assertIndexRowTtl.

// this is slightly annoying, but we cannot read rows from the methods in Util as
// ReadCommand#executeInternal uses metadata retrieved via the tableId, which the index
// CFS inherits from the base CFS. This has the 'wrong' partitioner (the index table
// uses LocalPartition, the base table a real one, so we cannot read from the index
// table with executeInternal
private void assertIndexRowTtl(ColumnFamilyStore indexCfs, int indexedValue, int ttl) throws Throwable {
    DecoratedKey indexKey = indexCfs.decorateKey(ByteBufferUtil.bytes(indexedValue));
    ClusteringIndexFilter filter = new ClusteringIndexSliceFilter(Slices.with(indexCfs.metadata().comparator, Slice.ALL), false);
    SinglePartitionReadCommand command = SinglePartitionReadCommand.create(indexCfs.metadata(), FBUtilities.nowInSeconds(), indexKey, ColumnFilter.all(indexCfs.metadata()), filter);
    try (ReadExecutionController executionController = command.executionController();
        UnfilteredRowIterator iter = command.queryMemtableAndDisk(indexCfs, executionController)) {
        while (iter.hasNext()) {
            Unfiltered unfiltered = iter.next();
            assert (unfiltered.isRow());
            Row indexRow = (Row) unfiltered;
            assertEquals(ttl, indexRow.primaryKeyLivenessInfo().ttl());
        }
    }
}
Also used : ClusteringIndexSliceFilter(org.apache.cassandra.db.filter.ClusteringIndexSliceFilter) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) Row(org.apache.cassandra.db.rows.Row) ClusteringIndexFilter(org.apache.cassandra.db.filter.ClusteringIndexFilter) Unfiltered(org.apache.cassandra.db.rows.Unfiltered)

Example 2 with ClusteringIndexFilter

use of org.apache.cassandra.db.filter.ClusteringIndexFilter 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));
    // 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).value();
        else if (iter.hasNext())
            value = iter.next().getCell(column).value();
        return value;
    }
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) CellPath(org.apache.cassandra.db.rows.CellPath) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) ClusteringIndexNamesFilter(org.apache.cassandra.db.filter.ClusteringIndexNamesFilter) ColumnFilter(org.apache.cassandra.db.filter.ColumnFilter) ByteBuffer(java.nio.ByteBuffer) RowIterator(org.apache.cassandra.db.rows.RowIterator) ClusteringIndexFilter(org.apache.cassandra.db.filter.ClusteringIndexFilter)

Aggregations

ClusteringIndexFilter (org.apache.cassandra.db.filter.ClusteringIndexFilter)2 ByteBuffer (java.nio.ByteBuffer)1 ClusteringIndexNamesFilter (org.apache.cassandra.db.filter.ClusteringIndexNamesFilter)1 ClusteringIndexSliceFilter (org.apache.cassandra.db.filter.ClusteringIndexSliceFilter)1 ColumnFilter (org.apache.cassandra.db.filter.ColumnFilter)1 CellPath (org.apache.cassandra.db.rows.CellPath)1 Row (org.apache.cassandra.db.rows.Row)1 RowIterator (org.apache.cassandra.db.rows.RowIterator)1 Unfiltered (org.apache.cassandra.db.rows.Unfiltered)1 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)1 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1