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