本文整理汇总了Java中org.apache.cassandra.db.marshal.CompositeType类的典型用法代码示例。如果您正苦于以下问题:Java CompositeType类的具体用法?Java CompositeType怎么用?Java CompositeType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompositeType类属于org.apache.cassandra.db.marshal包,在下文中一共展示了CompositeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParsingCompositeKey
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
/**
* Test on parsing out a ByteBuffer to a list of strings.
* @throws IOException
*/
@Test
public void testParsingCompositeKey() throws IOException {
final String inputSSTableFullPathFileName = CASS3_DATA_DIR + "keyspace1/compressed_bills/mc-2-big-Data.db";
final SSTableSingleReader SSTableSingleReader =
new SSTableSingleReader(inputSSTableFullPathFileName,
TestBaseSSTableFunSuite.HADOOP_CONF);
final CFMetaData cfMetaData = SSTableSingleReader.getCfMetaData();
final String user = "user2";
final String email = "[email protected]";
final AbstractType<?> keyDataType = cfMetaData.getKeyValidator();
Assert.assertTrue(keyDataType instanceof CompositeType);
final ByteBuffer keyInByteBuffer = ((CompositeType) keyDataType).decompose(user, email);
final List<Object> objects = SSTableUtils.parsePrimaryKey(cfMetaData, keyInByteBuffer);
Assert.assertEquals(2, objects.size());
Assert.assertEquals(user, objects.get(0));
Assert.assertEquals(email, objects.get(1));
}
示例2: toString
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
/**
* Returns a {@code String} representation of {@code byteBuffer} validated by {@code type}.
*
* @param byteBuffer the {@link ByteBuffer} to be converted to {@code String}
* @param type {@link AbstractType} of {@code byteBuffer}
* @return a {@code String} representation of {@code byteBuffer} validated by {@code type}
*/
public static String toString(ByteBuffer byteBuffer, AbstractType<?> type) {
if (type instanceof CompositeType) {
CompositeType composite = (CompositeType) type;
List<AbstractType<?>> types = composite.types;
ByteBuffer[] components = composite.split(byteBuffer);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < components.length; i++) {
AbstractType<?> componentType = types.get(i);
ByteBuffer component = components[i];
sb.append(componentType.compose(component));
if (i < types.size() - 1) {
sb.append(':');
}
}
return sb.toString();
} else {
return type.compose(byteBuffer).toString();
}
}
示例3: newPlacement
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
@Override
public Placement newPlacement(String placement) throws ConnectionException {
String[] parsed = PlacementUtil.parsePlacement(placement);
String keyspaceName = parsed[0];
String cfPrefix = parsed[1];
CassandraKeyspace keyspace = _keyspaceMap.get(keyspaceName);
if (keyspace == null) {
throw new UnknownPlacementException(format(
"Placement string refers to unknown or non-local Cassandra keyspace: %s", keyspaceName), placement);
}
KeyspaceDefinition keyspaceDef = keyspace.getAstyanaxKeyspace().describeKeyspace();
ColumnFamily<ByteBuffer,Composite> columnFamily = getColumnFamily(keyspaceDef, cfPrefix, "blob", placement,
new SpecificCompositeSerializer(CompositeType.getInstance(Arrays.<AbstractType<?>>asList(
AsciiType.instance, IntegerType.instance))));
return new BlobPlacement(placement, keyspace, columnFamily);
}
示例4: prepare
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
public ColumnIdentifier prepare(CFMetaData cfm)
{
AbstractType<?> comparator = cfm.comparator.asAbstractType();
if (cfm.getIsDense() || comparator instanceof CompositeType || comparator instanceof UTF8Type)
return new ColumnIdentifier(text, true);
// We have a Thrift-created table with a non-text comparator. We need to parse column names with the comparator
// to get the correct ByteBuffer representation. However, this doesn't apply to key aliases, so we need to
// make a special check for those and treat them normally. See CASSANDRA-8178.
ByteBuffer bufferName = ByteBufferUtil.bytes(text);
for (ColumnDefinition def : cfm.partitionKeyColumns())
{
if (def.name.bytes.equals(bufferName))
return new ColumnIdentifier(text, true);
}
return new ColumnIdentifier(comparator.fromString(rawText), text);
}
示例5: getPartitionKey
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
private ByteBuffer getPartitionKey(Map<String, ByteBuffer> keyColumns)
{
ByteBuffer partitionKey;
if (keyValidator instanceof CompositeType)
{
ByteBuffer[] keys = new ByteBuffer[partitionKeyColumns.length];
for (int i = 0; i< keys.length; i++)
keys[i] = keyColumns.get(partitionKeyColumns[i]);
partitionKey = CompositeType.build(keys);
}
else
{
partitionKey = keyColumns.get(partitionKeyColumns[0]);
}
return partitionKey;
}
示例6: computeNext
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
protected Pair<ByteBuffer, SortedMap<ByteBuffer, Cell>> computeNext()
{
maybeInit();
if (rows == null)
return endOfData();
totalRead++;
KeySlice ks = rows.get(i++);
AbstractType<?> comp = isSuper ? CompositeType.getInstance(comparator, subComparator) : comparator;
SortedMap<ByteBuffer, Cell> map = new TreeMap<ByteBuffer, Cell>(comp);
for (ColumnOrSuperColumn cosc : ks.columns)
{
List<Cell> cells = unthriftify(cosc);
for (Cell cell : cells)
map.put(cell.name().toByteBuffer(), cell);
}
return Pair.create(ks.key, map);
}
示例7: toByteBuffer
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
public ByteBuffer toByteBuffer()
{
// This is the legacy format of composites.
// See org.apache.cassandra.db.marshal.CompositeType for details.
ByteBuffer result = ByteBuffer.allocate(dataSize() + 3 * size() + (isStatic() ? 2 : 0));
if (isStatic())
ByteBufferUtil.writeShortLength(result, CompositeType.STATIC_MARKER);
for (int i = 0; i < size(); i++)
{
ByteBuffer bb = get(i);
ByteBufferUtil.writeShortLength(result, bb.remaining());
result.put(bb.duplicate());
result.put((byte)0);
}
result.flip();
return result;
}
示例8: SliceQueryWithTombstoneTest
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
@Test
public void SliceQueryWithTombstoneTest() throws Exception
{
// Testing for the bug of #6748
String keyspace = "cql_keyspace";
String table = "table2";
ColumnFamilyStore cfs = Keyspace.open(keyspace).getColumnFamilyStore(table);
CompositeType ct = (CompositeType)cfs.metadata.comparator.asAbstractType();
// Insert rows but with a tombstone as last cell
for (int i = 0; i < 5; i++)
executeInternal(String.format("INSERT INTO %s.%s (k, c, v) VALUES ('k%d', 'c%d', null)", keyspace, table, 0, i));
SliceQueryFilter filter = new SliceQueryFilter(ColumnSlice.ALL_COLUMNS_ARRAY, false, 100);
QueryPager pager = QueryPagers.localPager(new SliceFromReadCommand(keyspace, bytes("k0"), table, 0, filter));
for (int i = 0; i < 5; i++)
{
List<Row> page = pager.fetchPage(1);
assertEquals(toString(page), 1, page.size());
// The only live cell we should have each time is the row marker
assertRow(page.get(0), "k0", ct.decompose("c" + i, ""));
}
}
示例9: readRequiredRows
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
protected Map<ByteBuffer, ColumnGroupMap> readRequiredRows(List<ByteBuffer> partitionKeys, ColumnNameBuilder clusteringPrefix, boolean local, ConsistencyLevel cl)
throws RequestExecutionException, RequestValidationException
{
// Lists SET operation incurs a read.
Set<ByteBuffer> toRead = null;
for (Operation op : columnOperations)
{
if (op.requiresRead())
{
if (toRead == null)
toRead = new TreeSet<ByteBuffer>(UTF8Type.instance);
toRead.add(op.columnName.key);
}
}
return toRead == null ? null : readRows(partitionKeys, clusteringPrefix, toRead, (CompositeType)cfm.comparator, local, cl);
}
示例10: reachEndRange
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
/** check whether current row is at the end of range */
private boolean reachEndRange()
{
// current row key
ByteBuffer rowKey;
if (keyValidator instanceof CompositeType)
{
ByteBuffer[] keys = new ByteBuffer[partitionBoundColumns.size()];
for (int i = 0; i < partitionBoundColumns.size(); i++)
keys[i] = partitionBoundColumns.get(i).value.duplicate();
rowKey = CompositeType.build(keys);
}
else
{
rowKey = partitionBoundColumns.get(0).value;
}
String endToken = split.getEndToken();
String currentToken = partitioner.getToken(rowKey).toString();
logger.debug("End token: {}, current token: {}", endToken, currentToken);
return endToken.equals(currentToken);
}
示例11: groupSuperColumns
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
private static Map<ByteBuffer, List<Column>> groupSuperColumns(ColumnFamily scf)
{
CompositeType type = (CompositeType)scf.getComparator();
// The order of insertion matters!
Map<ByteBuffer, List<Column>> scMap = new LinkedHashMap<ByteBuffer, List<Column>>();
ByteBuffer scName = null;
List<Column> subColumns = null;
for (Column column : scf)
{
ByteBuffer newScName = scName(column.name());
ByteBuffer newSubName = subName(column.name());
if (scName == null || type.types.get(0).compare(scName, newScName) != 0)
{
// new super column
scName = newScName;
subColumns = new ArrayList<Column>();
scMap.put(scName, subColumns);
}
subColumns.add(((Column)column).withUpdatedName(newSubName));
}
return scMap;
}
示例12: namesFilterToSC
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
public static SCFilter namesFilterToSC(CompositeType type, NamesQueryFilter filter)
{
ByteBuffer scName = null;
SortedSet<ByteBuffer> newColumns = new TreeSet<ByteBuffer>(filter.columns.comparator());
for (ByteBuffer name : filter.columns)
{
ByteBuffer newScName = scName(name);
if (scName == null)
{
scName = newScName;
}
else if (type.types.get(0).compare(scName, newScName) != 0)
{
// If we're selecting column across multiple SC, it's not something we can translate for an old node
throw new RuntimeException("Cannot convert filter to old super column format. Update all nodes to Cassandra 2.0 first.");
}
newColumns.add(subName(name));
}
return new SCFilter(scName, new NamesQueryFilter(newColumns));
}
示例13: fromSCNamesFilter
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
public static IDiskAtomFilter fromSCNamesFilter(CompositeType type, ByteBuffer scName, NamesQueryFilter filter)
{
if (scName == null)
{
ColumnSlice[] slices = new ColumnSlice[filter.columns.size()];
int i = 0;
for (ByteBuffer bb : filter.columns)
{
CompositeType.Builder builder = type.builder().add(bb);
slices[i++] = new ColumnSlice(builder.build(), builder.buildAsEndOfRange());
}
return new SliceQueryFilter(slices, false, slices.length, 1);
}
else
{
SortedSet<ByteBuffer> newColumns = new TreeSet<ByteBuffer>(type);
for (ByteBuffer c : filter.columns)
newColumns.add(CompositeType.build(scName, c));
return filter.withUpdatedColumns(newColumns);
}
}
示例14: Statics
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
private Statics()
{
StandardCf.addColumn(new Column(bb("aaaa")));
StandardCf.addColumn(new Column(bb("bbbb"), bb("bbbbb-value")));
StandardCf.addColumn(new Column(bb("cccc"), bb("ccccc-value"), 1000L));
StandardCf.addColumn(new DeletedColumn(bb("dddd"), 500, 1000));
StandardCf.addColumn(new DeletedColumn(bb("eeee"), bb("eeee-value"), 1001));
StandardCf.addColumn(new ExpiringColumn(bb("ffff"), bb("ffff-value"), 2000, 1000));
StandardCf.addColumn(new ExpiringColumn(bb("gggg"), bb("gggg-value"), 2001, 1000, 2002));
SuperCf.addColumn(new Column(CompositeType.build(SC, bb("aaaa"))));
SuperCf.addColumn(new Column(CompositeType.build(SC, bb("bbbb")), bb("bbbbb-value")));
SuperCf.addColumn(new Column(CompositeType.build(SC, bb("cccc")), bb("ccccc-value"), 1000L));
SuperCf.addColumn(new DeletedColumn(CompositeType.build(SC, bb("dddd")), 500, 1000));
SuperCf.addColumn(new DeletedColumn(CompositeType.build(SC, bb("eeee")), bb("eeee-value"), 1001));
SuperCf.addColumn(new ExpiringColumn(CompositeType.build(SC, bb("ffff")), bb("ffff-value"), 2000, 1000));
SuperCf.addColumn(new ExpiringColumn(CompositeType.build(SC, bb("gggg")), bb("gggg-value"), 2001, 1000, 2002));
}
示例15: testRowIteration
import org.apache.cassandra.db.marshal.CompositeType; //导入依赖的package包/类
@Test
public void testRowIteration() throws IOException, ExecutionException, InterruptedException
{
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore store = keyspace.getColumnFamilyStore("Super3");
final int ROWS_PER_SSTABLE = 10;
Set<DecoratedKey> inserted = new HashSet<DecoratedKey>();
for (int i = 0; i < ROWS_PER_SSTABLE; i++) {
DecoratedKey key = Util.dk(String.valueOf(i));
RowMutation rm = new RowMutation(KEYSPACE1, key.key);
rm.add("Super3", CompositeType.build(ByteBufferUtil.bytes("sc"), ByteBufferUtil.bytes(String.valueOf(i))), ByteBuffer.wrap(new byte[ROWS_PER_SSTABLE * 10 - i * 2]), i);
rm.apply();
inserted.add(key);
}
store.forceBlockingFlush();
assertEquals(inserted.toString(), inserted.size(), Util.getRangeSlice(store).size());
}