List of usage examples for org.apache.cassandra.db DecoratedKey getKey
public abstract ByteBuffer getKey();
From source file:com.mirantis.magnetodb.cassandra.db.index.MagnetoDBLocalSecondaryIndex.java
License:Apache License
public void insert(ByteBuffer rowKey, Cell cell, OpOrder.Group opGroup) { if (isQueryPropertiesField) return;/*from w ww . j av a 2 s. c o m*/ DecoratedKey valueKey = new BufferDecoratedKey(indexCfs.partitioner.getToken(rowKey), rowKey); ColumnFamily cfi = ArrayBackedSortedColumns.factory.create(indexCfs.metadata, false, 1); CellName name = makeIndexColumnName(rowKey, cell); if (cell instanceof ExpiringCell) { ExpiringCell ec = (ExpiringCell) cell; cfi.addColumn(new BufferExpiringCell(name, ByteBufferUtil.EMPTY_BYTE_BUFFER, ec.timestamp(), ec.getTimeToLive(), ec.getLocalDeletionTime())); } else { cfi.addColumn(new BufferCell(name, ByteBufferUtil.EMPTY_BYTE_BUFFER, cell.timestamp())); } if (logger.isDebugEnabled()) logger.debug("applying index row {} in {}", indexCfs.metadata.getKeyValidator().getString(valueKey.getKey()), cfi); indexCfs.apply(valueKey, cfi, SecondaryIndexManager.nullUpdater, opGroup, null); }
From source file:com.protectwise.cassandra.db.compaction.AbstractSimpleDeletingConvictor.java
License:Apache License
protected Map<ByteBuffer, ByteBuffer> getNamedPkColumns(DecoratedKey key) { return getNamedPkColumns(key.getKey()); }
From source file:com.stratio.cassandra.index.FullKeyMapper.java
License:Apache License
/** * Returns the {@link ByteBuffer} representation of the full row key formed by the specified partition key and the * clustering key./*from ww w . j av a 2 s . co m*/ * * @param partitionKey A partition key. * @param cellName A clustering key. * @return The {@link ByteBuffer} representation of the full row key formed by the specified key pair. */ public ByteBuffer byteBuffer(DecoratedKey partitionKey, CellName cellName) { return type.builder().add(partitionKey.getKey()).add(cellName.toByteBuffer()).build(); }
From source file:com.stratio.cassandra.index.PartitionKeyMapper.java
License:Apache License
/** * Adds to the specified {@link Document} the {@link Field}s associated to the specified raw partition key. * * @param document The document in which the fields are going to be added. * @param partitionKey The raw partition key to be converted. *//*from w w w . j a va2 s.c o m*/ public void addFields(Document document, DecoratedKey partitionKey) { String serializedKey = ByteBufferUtils.toString(partitionKey.getKey()); Field field = new StringField(FIELD_NAME, serializedKey, Store.YES); document.add(field); }
From source file:com.stratio.cassandra.index.PartitionKeyMapper.java
License:Apache License
/** * Returns the specified raw partition key as a Lucene {@link Term}. * * @param partitionKey The raw partition key to be converted. * @return The specified raw partition key as a Lucene {@link Term}. */// w w w . ja va 2 s . c om public Term term(DecoratedKey partitionKey) { String serializedKey = ByteBufferUtils.toString(partitionKey.getKey()); return new Term(FIELD_NAME, serializedKey); }
From source file:com.stratio.cassandra.index.PartitionKeyMapper.java
License:Apache License
public Columns columns(Row row) { DecoratedKey partitionKey = row.key; Columns columns = new Columns(); AbstractType<?> rawKeyType = metadata.getKeyValidator(); List<ColumnDefinition> columnDefinitions = metadata.partitionKeyColumns(); for (ColumnDefinition columnDefinition : columnDefinitions) { String name = columnDefinition.name.toString(); ByteBuffer[] components = ByteBufferUtils.split(partitionKey.getKey(), rawKeyType); int position = columnDefinition.position(); ByteBuffer value = components[position]; AbstractType<?> valueType = rawKeyType.getComponents().get(position); columns.add(new Column(name, value, valueType)); }//from ww w . j a v a2 s. c o m return columns; }
From source file:com.stratio.cassandra.index.PartitionKeyMapper.java
License:Apache License
public String toString(DecoratedKey decoratedKey) { return decoratedKey.getToken() + " - " + ByteBufferUtils.toString(decoratedKey.getKey(), type); }
From source file:com.stratio.cassandra.lucene.IndexPagingState.java
License:Apache License
/** * Returns a byte buffer representation of this. Thew returned result can be read with {@link #build(ByteBuffer)}. * * @return a byte buffer representing this *//*from w ww.j ava 2 s . co m*/ public ByteBuffer toByteBuffer() { ByteBuffer[] entryValues = new ByteBuffer[entries.size()]; entries.entrySet().stream().map(entry -> { DecoratedKey key = entry.getKey(); Clustering clustering = entry.getValue(); ByteBuffer[] clusteringValues = clustering.getRawValues(); ByteBuffer[] values = new ByteBuffer[1 + clusteringValues.length]; values[0] = key.getKey(); System.arraycopy(clusteringValues, 0, values, 1, clusteringValues.length); return compose(values); }).collect(toList()).toArray(entryValues); ByteBuffer values = compose(entryValues); ByteBuffer out = ByteBuffer.allocate(2 + values.remaining()); writeShortLength(out, remaining); out.put(values); out.flip(); return out; }
From source file:com.stratio.cassandra.lucene.IndexReaderWide.java
License:Apache License
private NavigableSet<Clustering> clusterings(DecoratedKey key) { NavigableSet<Clustering> clusterings = service.clusterings(); Clustering clustering = service.clustering(nextDoc.left); Clustering lastClustering = null;//from w ww. j a v a 2 s . c o m while (nextDoc != null && key.getKey().equals(service.decoratedKey(nextDoc.left).getKey()) && (lastClustering == null || comparator.compare(lastClustering, clustering) < 0)) { if (command.selectsKey(key) && command.selectsClustering(key, clustering)) { lastClustering = clustering; clusterings.add(clustering); cacheUpdater.put(key, clustering, nextDoc.right); } if (documents.hasNext()) { nextDoc = documents.next(); clustering = service.clustering(nextDoc.left); } else { nextDoc = null; } if (documents.needsFetch()) { break; } } return clusterings; }
From source file:com.stratio.cassandra.lucene.key.KeyMapper.java
License:Apache License
/** * Returns the {@link ByteBuffer} representation of the primary key formed by the specified partition key and the * clustering key./* w ww .j a v a2 s . com*/ * * @param key the partition key * @param clustering the clustering key * @return the {@link ByteBuffer} representation of the primary key */ public ByteBuffer byteBuffer(DecoratedKey key, Clustering clustering) { return type.builder().add(TokenMapper.byteBuffer(key.getToken())).add(key.getKey()) .add(byteBuffer(clustering)).build(); }