本文整理汇总了Java中org.apache.cassandra.db.marshal.AbstractType类的典型用法代码示例。如果您正苦于以下问题:Java AbstractType类的具体用法?Java AbstractType怎么用?Java AbstractType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractType类属于org.apache.cassandra.db.marshal包,在下文中一共展示了AbstractType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSerializedValue
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
/**
* Given a serialized map, gets the value associated with a given key.
* @param serializedMap a serialized map
* @param serializedKey a serialized key
* @param keyType the key type for the map
* @return the value associated with the key if one exists, null otherwise
*/
public ByteBuffer getSerializedValue(ByteBuffer serializedMap, ByteBuffer serializedKey, AbstractType keyType)
{
try
{
ByteBuffer input = serializedMap.duplicate();
int n = readCollectionSize(input, ProtocolVersion.V3);
for (int i = 0; i < n; i++)
{
ByteBuffer kbb = readValue(input, ProtocolVersion.V3);
ByteBuffer vbb = readValue(input, ProtocolVersion.V3);
int comparison = keyType.compare(kbb, serializedKey);
if (comparison == 0)
return vbb;
else if (comparison > 0)
// since the map is in sorted order, we know we've gone too far and the element doesn't exist
return null;
}
return null;
}
catch (BufferUnderflowException e)
{
throw new MarshalException("Not enough bytes to read a map");
}
}
示例2: testAssignment
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
public final AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver)
{
// We should ignore the fact that the receiver type is frozen in our comparison as functions do not support
// frozen types for return type
AbstractType<?> returnType = returnType();
if (receiver.type.isFreezable() && !receiver.type.isMultiCell())
returnType = returnType.freeze();
if (receiver.type.equals(returnType))
return AssignmentTestable.TestResult.EXACT_MATCH;
if (receiver.type.isValueCompatibleWith(returnType))
return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE;
return AssignmentTestable.TestResult.NOT_ASSIGNABLE;
}
示例3: testParsingCompositeKey
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的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));
}
示例4: ColumnDefinition
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
@VisibleForTesting
public ColumnDefinition(String ksName,
String cfName,
ColumnIdentifier name,
AbstractType<?> type,
int position,
Kind kind)
{
super(ksName, cfName, name, type);
assert name != null && type != null && kind != null;
assert name.isInterned();
assert (position == NO_POSITION) == !kind.isPrimaryKeyKind(); // The position really only make sense for partition and clustering columns (and those must have one),
// so make sure we don't sneak it for something else since it'd breaks equals()
this.kind = kind;
this.position = position;
this.cellPathComparator = makeCellPathComparator(kind, type);
this.cellComparator = cellPathComparator == null ? ColumnData.comparator : (a, b) -> cellPathComparator.compare(a.path(), b.path());
this.asymmetricCellPathComparator = cellPathComparator == null ? null : (a, b) -> cellPathComparator.compare(((Cell)a).path(), (CellPath) b);
this.comparisonOrder = comparisonOrder(kind, isComplex(), Math.max(0, position), name);
}
示例5: serializedSize
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
public long serializedSize(Slices slices, int version)
{
long size = TypeSizes.sizeofUnsignedVInt(slices.size());
if (slices.size() == 0)
return size;
List<AbstractType<?>> types = slices instanceof SelectAllSlices
? Collections.<AbstractType<?>>emptyList()
: ((ArrayBackedSlices)slices).comparator.subtypes();
for (Slice slice : slices)
size += Slice.serializer.serializedSize(slice, version, types);
return size;
}
示例6: valuesWithoutSizeSerializedSize
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
long valuesWithoutSizeSerializedSize(ClusteringPrefix clustering, int version, List<AbstractType<?>> types)
{
long result = 0;
int offset = 0;
int clusteringSize = clustering.size();
while (offset < clusteringSize)
{
int limit = Math.min(clusteringSize, offset + 32);
result += TypeSizes.sizeofUnsignedVInt(makeHeader(clustering, offset, limit));
offset = limit;
}
for (int i = 0; i < clusteringSize; i++)
{
ByteBuffer v = clustering.get(i);
if (v == null || !v.hasRemaining())
continue; // handled in the header
result += types.get(i).writtenLength(v);
}
return result;
}
示例7: deserializeValuesWithoutSize
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
ByteBuffer[] deserializeValuesWithoutSize(DataInputPlus in, int size, int version, List<AbstractType<?>> types) throws IOException
{
// Callers of this method should handle the case where size = 0 (in all case we want to return a special value anyway).
assert size > 0;
ByteBuffer[] values = new ByteBuffer[size];
int offset = 0;
while (offset < size)
{
long header = in.readUnsignedVInt();
int limit = Math.min(size, offset + 32);
while (offset < limit)
{
values[offset] = isNull(header, offset)
? null
: (isEmpty(header, offset) ? ByteBufferUtil.EMPTY_BYTE_BUFFER : types.get(offset).readValue(in, DatabaseDescriptor.getMaxValueSize()));
offset++;
}
}
return values;
}
示例8: skipValuesWithoutSize
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
void skipValuesWithoutSize(DataInputPlus in, int size, int version, List<AbstractType<?>> types) throws IOException
{
// Callers of this method should handle the case where size = 0 (in all case we want to return a special value anyway).
assert size > 0;
int offset = 0;
while (offset < size)
{
long header = in.readUnsignedVInt();
int limit = Math.min(size, offset + 32);
while (offset < limit)
{
if (!isNull(header, offset) && !isEmpty(header, offset))
types.get(offset).skipValue(in);
offset++;
}
}
}
示例9: deserialize
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
public Component deserialize(Version version, DataInputPlus in) throws IOException
{
EncodingStats stats = EncodingStats.serializer.deserialize(in);
AbstractType<?> keyType = readType(in);
int size = (int)in.readUnsignedVInt();
List<AbstractType<?>> clusteringTypes = new ArrayList<>(size);
for (int i = 0; i < size; i++)
clusteringTypes.add(readType(in));
Map<ByteBuffer, AbstractType<?>> staticColumns = new LinkedHashMap<>();
Map<ByteBuffer, AbstractType<?>> regularColumns = new LinkedHashMap<>();
readColumnsWithType(in, staticColumns);
readColumnsWithType(in, regularColumns);
return new Component(keyType, clusteringTypes, staticColumns, regularColumns, stats);
}
示例10: prepare
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
public ColumnDefinition prepare(CFMetaData cfm)
{
if (!cfm.isStaticCompactTable())
return find(cfm);
AbstractType<?> thriftColumnNameType = cfm.thriftColumnNameType();
if (thriftColumnNameType instanceof UTF8Type)
return find(cfm);
// We have a Thrift-created table with a non-text comparator. Check if we have a match column, otherwise assume we should use
// thriftColumnNameType
ByteBuffer bufferName = ByteBufferUtil.bytes(text);
for (ColumnDefinition def : cfm.allColumns())
{
if (def.name.bytes.equals(bufferName))
return def;
}
return find(thriftColumnNameType.fromString(text), cfm);
}
示例11: ColumnSpecification
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
public ColumnSpecification(String ksName, String cfName, ColumnIdentifier name, AbstractType<?> type)
{
this.ksName = ksName;
this.cfName = cfName;
this.name = name;
this.type = type;
}
示例12: getExactTypeIfKnown
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
@Override
public AbstractType<?> getExactTypeIfKnown(String keyspace)
{
for (Term.Raw term : elements)
{
AbstractType<?> type = term.getExactTypeIfKnown(keyspace);
if (type != null)
return ListType.getInstance(type, false);
}
return null;
}
示例13: metadataBuilder
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
public CFMetaData.Builder metadataBuilder()
{
CFMetaData.Builder builder = CFMetaData.Builder.create(keyspace(), columnFamily(), isDense, isCompound, hasCounters);
builder.withId(id);
for (int i = 0; i < keyAliases.size(); i++)
builder.addPartitionKey(keyAliases.get(i), keyTypes.get(i));
for (int i = 0; i < columnAliases.size(); i++)
builder.addClusteringColumn(columnAliases.get(i), clusteringTypes.get(i));
boolean isStaticCompact = !isDense && !isCompound;
for (Map.Entry<ColumnIdentifier, AbstractType> entry : columns.entrySet())
{
ColumnIdentifier name = entry.getKey();
// Note that for "static" no-clustering compact storage we use static for the defined columns
if (staticColumns.contains(name) || isStaticCompact)
builder.addStaticColumn(name, entry.getValue());
else
builder.addRegularColumn(name, entry.getValue());
}
boolean isCompactTable = isDense || !isCompound;
if (isCompactTable)
{
CompactTables.DefaultNames names = CompactTables.defaultNameGenerator(builder.usedColumnNames());
// Compact tables always have a clustering and a single regular value.
if (isStaticCompact)
{
builder.addClusteringColumn(names.defaultClusteringName(), UTF8Type.instance);
builder.addRegularColumn(names.defaultCompactValueName(), hasCounters ? CounterColumnType.instance : BytesType.instance);
}
else if (isDense && !builder.hasRegulars())
{
// Even for dense, we might not have our regular column if it wasn't part of the declaration. If
// that's the case, add it but with a specific EmptyType so we can recognize that case later
builder.addRegularColumn(names.defaultCompactValueName(), EmptyType.instance);
}
}
return builder;
}
示例14: getDroppedColumnDefinition
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
/**
* Returns a "fake" ColumnDefinition corresponding to the dropped column {@code name}
* of {@code null} if there is no such dropped column.
*
* @param name - the column name
* @param isStatic - whether the column was a static column, if known
*/
public ColumnDefinition getDroppedColumnDefinition(ByteBuffer name, boolean isStatic)
{
DroppedColumn dropped = droppedColumns.get(name);
if (dropped == null)
return null;
// We need the type for deserialization purpose. If we don't have the type however,
// it means that it's a dropped column from before 3.0, and in that case using
// BytesType is fine for what we'll be using it for, even if that's a hack.
AbstractType<?> type = dropped.type == null ? BytesType.instance : dropped.type;
return isStatic
? ColumnDefinition.staticDef(this, name, type)
: ColumnDefinition.regularDef(this, name, type);
}
示例15: cellValueType
import org.apache.cassandra.db.marshal.AbstractType; //导入依赖的package包/类
/**
* The type of the cell values for cell belonging to this column.
*
* This is the same than the column type, except for collections where it's the 'valueComparator'
* of the collection.
*/
public AbstractType<?> cellValueType()
{
return type instanceof CollectionType
? ((CollectionType)type).valueComparator()
: type;
}