Search in sources :

Example 6 with CellName

use of org.apache.cassandra.db.composites.CellName in project stargate-core by tuplejump.

the class RowIndexSupport method collectionFields.

protected List<Field> collectionFields(CollectionType validator, String colName, Cell column) {
    CellName cellName = column.name();
    List<Field> fields = new ArrayList<>();
    FieldType[] fieldTypesArr = options.collectionFieldTypes.get(colName);
    FieldType docValueType = options.collectionFieldDocValueTypes.get(colName);
    AbstractType keyType = validator.nameComparator();
    FieldCreator keyFieldCreator = CassandraUtils.fromAbstractType(keyType.asCQL3Type()).fieldCreator;
    AbstractType valueType = validator.valueComparator();
    FieldCreator valueFieldCreator = CassandraUtils.fromAbstractType(valueType.asCQL3Type()).fieldCreator;
    ByteBuffer collectionElement = cellName.collectionElement();
    if (validator instanceof MapType) {
        if (fieldTypesArr != null) {
            fields.add(keyFieldCreator.field(colName + "._key", keyType, collectionElement, fieldTypesArr[0]));
            fields.add(valueFieldCreator.field(colName + "._value", valueType, column.value(), fieldTypesArr[1]));
            fields.add(valueFieldCreator.field((colName + "." + keyType.getString(collectionElement)).toLowerCase(), valueType, column.value(), fieldTypesArr[1]));
        }
        if (docValueType != null)
            fields.add(Fields.docValueField((colName + "." + keyType.getString(collectionElement)).toLowerCase(), valueType, column.value(), docValueType));
    } else if (validator instanceof SetType) {
        if (fieldTypesArr != null)
            fields.add(keyFieldCreator.field(colName, keyType, collectionElement, fieldTypesArr[0]));
        if (docValueType != null)
            fields.add(Fields.docValueField(colName, keyType, collectionElement, docValueType));
    } else if (validator instanceof ListType) {
        if (fieldTypesArr != null)
            fields.add(valueFieldCreator.field(colName, valueType, column.value(), fieldTypesArr[0]));
        if (docValueType != null)
            fields.add(Fields.docValueField(colName, valueType, column.value(), docValueType));
    } else
        throw new UnsupportedOperationException("Unsupported collection type " + validator);
    return fields;
}
Also used : CellName(org.apache.cassandra.db.composites.CellName) ByteBuffer(java.nio.ByteBuffer) FieldType(org.apache.lucene.document.FieldType) Field(org.apache.lucene.document.Field)

Example 7 with CellName

use of org.apache.cassandra.db.composites.CellName in project stargate-core by tuplejump.

the class SearchSupport method deleteIfNotLatest.

public boolean deleteIfNotLatest(DecoratedKey decoratedKey, long timestamp, String pkString, ColumnFamily cf) throws IOException {
    if (deleteRowIfNotLatest(decoratedKey, cf))
        return true;
    Cell lastColumn = null;
    for (CellName colKey : cf.getColumnNames()) {
        String name = colKey.cql3ColumnName(tableMapper.cfMetaData).toString();
        com.tuplejump.stargate.lucene.Properties option = options.fields.get(name);
        //if option was not found then the column is not indexed
        if (option != null) {
            lastColumn = cf.getColumn(colKey);
        }
    }
    if (lastColumn != null && lastColumn.timestamp() > timestamp) {
        currentIndex.delete(decoratedKey, pkString, timestamp);
        return true;
    }
    return false;
}
Also used : CellName(org.apache.cassandra.db.composites.CellName)

Example 8 with CellName

use of org.apache.cassandra.db.composites.CellName 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)

Example 9 with CellName

use of org.apache.cassandra.db.composites.CellName in project stargate-core by tuplejump.

the class RowFetcher method getMetaColumn.

protected Cell getMetaColumn(Cell firstColumn, Float score) {
    CellNameType cellNameType = table.getComparator();
    ColumnDefinition columnDefinition = resultMapper.tableMapper.primaryColumnDefinition;
    CellName cellName = cellNameType.create(firstColumn.name(), columnDefinition);
    return new BufferCell(cellName, UTF8Type.instance.decompose("{\"score\":" + score.toString() + "}"));
}
Also used : CellNameType(org.apache.cassandra.db.composites.CellNameType) CellName(org.apache.cassandra.db.composites.CellName) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Example 10 with CellName

use of org.apache.cassandra.db.composites.CellName in project stargate-core by tuplejump.

the class RowFetcher method fetchIOOptimized.

private List<Row> fetchIOOptimized() throws IOException {
    List<Row> rows = new ArrayList<>();
    TreeMultimap<DecoratedKey, IndexEntryCollector.IndexEntry> docs = resultMapper.docsByRowKey();
    for (DecoratedKey dk : docs.keySet()) {
        NavigableSet<IndexEntryCollector.IndexEntry> entries = docs.get(dk);
        if (!resultMapper.filter.dataRange.contains(dk)) {
            if (logger.isTraceEnabled()) {
                logger.trace("Skipping entry {} outside of assigned scan range", dk.getToken());
            }
            continue;
        }
        final Map<CellName, ColumnFamily> fullSlice = resultMapper.fetchPagedRangeSlice(entries, dk, limit);
        for (IndexEntryCollector.IndexEntry input : entries) {
            CellName cellName = input.clusteringKey;
            if (!resultMapper.filter.columnFilter(dk.getKey()).maySelectPrefix(table.getComparator(), cellName.start())) {
                continue;
            }
            ColumnFamily data = fullSlice.get(cellName);
            if (data == null || resultMapper.searchSupport.deleteIfNotLatest(dk, data.maxTimestamp(), input.pkName, data))
                continue;
            float score = input.score;
            ColumnFamily cleanColumnFamily = resultMapper.showScore ? scored(score, data) : data;
            rows.add(new Row(dk, cleanColumnFamily));
            columnsCount++;
            if (columnsCount > limit)
                break;
        }
        if (columnsCount > limit)
            break;
    }
    return rows;
}
Also used : ArrayList(java.util.ArrayList) CellName(org.apache.cassandra.db.composites.CellName) IndexEntryCollector(com.tuplejump.stargate.lucene.IndexEntryCollector)

Aggregations

CellName (org.apache.cassandra.db.composites.CellName)11 IndexEntryCollector (com.tuplejump.stargate.lucene.IndexEntryCollector)3 ArrayList (java.util.ArrayList)3 ByteBuffer (java.nio.ByteBuffer)2 ColumnDefinition (org.apache.cassandra.config.ColumnDefinition)2 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)2 SliceByNamesReadCommand (org.apache.cassandra.db.SliceByNamesReadCommand)2 Composite (org.apache.cassandra.db.composites.Composite)2 ColumnSlice (org.apache.cassandra.db.filter.ColumnSlice)2 NamesQueryFilter (org.apache.cassandra.db.filter.NamesQueryFilter)2 IndexEntry (com.tuplejump.stargate.lucene.IndexEntryCollector.IndexEntry)1 ColumnFamily (org.apache.cassandra.db.ColumnFamily)1 DecoratedKey (org.apache.cassandra.db.DecoratedKey)1 Row (org.apache.cassandra.db.Row)1 CellNameType (org.apache.cassandra.db.composites.CellNameType)1 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)1 SliceQueryFilter (org.apache.cassandra.db.filter.SliceQueryFilter)1 Field (org.apache.lucene.document.Field)1 FieldType (org.apache.lucene.document.FieldType)1