Search in sources :

Example 1 with SliceQueryFilter

use of org.apache.cassandra.db.filter.SliceQueryFilter in project titan by thinkaurelius.

the class CassandraEmbeddedKeyColumnValueStore method getSlice.

@Override
public EntryList getSlice(KeySliceQuery query, StoreTransaction txh) throws BackendException {
    /**
         * This timestamp mimics the timestamp used by
         * {@link org.apache.cassandra.thrift.CassandraServer#get(ByteBuffer,ColumnPath,ConsistencyLevel)}.
         *
         * That method passes the server's System.currentTimeMillis() to
         * {@link ReadCommand#create(String, ByteBuffer, String, long, IDiskAtomFilter)}.
         * {@code create(...)} in turn passes that timestamp to the SliceFromReadCommand constructor.
         */
    final long nowMillis = times.getTime().toEpochMilli();
    Composite startComposite = CellNames.simpleDense(query.getSliceStart().asByteBuffer());
    Composite endComposite = CellNames.simpleDense(query.getSliceEnd().asByteBuffer());
    SliceQueryFilter sqf = new SliceQueryFilter(startComposite, endComposite, false, query.getLimit() + (query.hasLimit() ? 1 : 0));
    ReadCommand sliceCmd = new SliceFromReadCommand(keyspace, query.getKey().asByteBuffer(), columnFamily, nowMillis, sqf);
    List<Row> slice = read(sliceCmd, getTx(txh).getReadConsistencyLevel().getDB());
    if (null == slice || 0 == slice.size())
        return EntryList.EMPTY_LIST;
    int sliceSize = slice.size();
    if (1 < sliceSize)
        throw new PermanentBackendException("Received " + sliceSize + " rows for single key");
    Row r = slice.get(0);
    if (null == r) {
        log.warn("Null Row object retrieved from Cassandra StorageProxy");
        return EntryList.EMPTY_LIST;
    }
    ColumnFamily cf = r.cf;
    if (null == cf) {
        log.debug("null ColumnFamily (\"{}\")", columnFamily);
        return EntryList.EMPTY_LIST;
    }
    if (cf.isMarkedForDelete())
        return EntryList.EMPTY_LIST;
    return CassandraHelper.makeEntryList(Iterables.filter(cf.getSortedColumns(), new FilterDeletedColumns(nowMillis)), entryGetter, query.getSliceEnd(), query.getLimit());
}
Also used : Composite(org.apache.cassandra.db.composites.Composite) SliceQueryFilter(org.apache.cassandra.db.filter.SliceQueryFilter)

Example 2 with SliceQueryFilter

use of org.apache.cassandra.db.filter.SliceQueryFilter in project stargate-core by tuplejump.

the class ResultMapper method getCellNameColumnFamilyMap.

private Map<CellName, ColumnFamily> getCellNameColumnFamilyMap(DecoratedKey dk, ColumnSlice[] columnSlices) {
    SliceQueryFilter sliceQueryFilter = new SliceQueryFilter(columnSlices, false, Integer.MAX_VALUE);
    QueryFilter queryFilter = new QueryFilter(dk, tableMapper.table.name, sliceQueryFilter, filter.timestamp);
    ColumnFamily columnFamily = tableMapper.table.getColumnFamily(queryFilter);
    return tableMapper.getRows(columnFamily);
}
Also used : SliceQueryFilter(org.apache.cassandra.db.filter.SliceQueryFilter) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) SliceQueryFilter(org.apache.cassandra.db.filter.SliceQueryFilter) ColumnFamily(org.apache.cassandra.db.ColumnFamily)

Example 3 with SliceQueryFilter

use of org.apache.cassandra.db.filter.SliceQueryFilter in project stargate-core by tuplejump.

the class RowIndexSupport method loadOldRow.

private void loadOldRow(DecoratedKey dk, ByteBuffer pkBuf, List<Field> fields) {
    CellName clusteringKey = tableMapper.makeClusteringKey(pkBuf);
    Composite start = tableMapper.start(clusteringKey);
    Composite end = tableMapper.end(start);
    ColumnSlice columnSlice = new ColumnSlice(start, end);
    SliceQueryFilter sliceQueryFilter = new SliceQueryFilter(columnSlice, false, Integer.MAX_VALUE);
    QueryFilter queryFilter = new QueryFilter(dk, tableMapper.table.name, sliceQueryFilter, new Date().getTime());
    ColumnFamily columnFamily = tableMapper.table.getColumnFamily(queryFilter);
    Map<CellName, ColumnFamily> fullSlice = tableMapper.getRows(columnFamily);
    ColumnFamily oldDocument = fullSlice.get(clusteringKey);
    for (Cell cell : oldDocument) {
        CellName cellName = cell.name();
        ColumnIdentifier cql3ColName = cellName.cql3ColumnName(tableMapper.cfMetaData);
        String actualColName = cql3ColName.toString();
        ColumnDefinition columnDefinition = tableMapper.cfMetaData.getColumnDefinition(cql3ColName);
        if (options.shouldIndex(actualColName)) {
            addFields(cell, actualColName, columnDefinition, fields);
        }
    }
}
Also used : SliceQueryFilter(org.apache.cassandra.db.filter.SliceQueryFilter) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) Composite(org.apache.cassandra.db.composites.Composite) ColumnSlice(org.apache.cassandra.db.filter.ColumnSlice) SliceQueryFilter(org.apache.cassandra.db.filter.SliceQueryFilter) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) CellName(org.apache.cassandra.db.composites.CellName) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Aggregations

SliceQueryFilter (org.apache.cassandra.db.filter.SliceQueryFilter)3 Composite (org.apache.cassandra.db.composites.Composite)2 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)2 ColumnDefinition (org.apache.cassandra.config.ColumnDefinition)1 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)1 ColumnFamily (org.apache.cassandra.db.ColumnFamily)1 CellName (org.apache.cassandra.db.composites.CellName)1 ColumnSlice (org.apache.cassandra.db.filter.ColumnSlice)1