Package org.apache.cassandra.db.marshal
Class TupleType
- All Implemented Interfaces:
Comparator<ByteBuffer>,AssignmentTestable
- Direct Known Subclasses:
UserType
This is essentially like a CompositeType, but it's not primarily meant for comparison, just
to pack multiple values together so has a more friendly encoding.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.cassandra.db.marshal.AbstractType
AbstractType.ComparisonType, AbstractType.DefaultArgumentDeserializerNested classes/interfaces inherited from interface org.apache.cassandra.cql3.AssignmentTestable
AssignmentTestable.TestResult -
Field Summary
FieldsFields inherited from class org.apache.cassandra.db.marshal.AbstractType
comparatorSet, comparisonType, isByteOrderComparable, reverseComparator -
Constructor Summary
ConstructorsConstructorDescriptionTupleType(List<AbstractType<?>> types) TupleType(List<AbstractType<?>> types, boolean freezeInner) -
Method Summary
Modifier and TypeMethodDescriptionbooleanDefines if the type allows an empty set of bytes (new byte[0]) as valid input.List<AbstractType<?>>allTypes()<V> ByteSourceasComparableBytes(ValueAccessor<V> accessor, V data, ByteComparable.Version version) Produce a byte-comparable representation of the given value, i.e.static ByteBufferbuildValue(ByteBuffer... components) static <V> VbuildValue(ValueAccessor<V> accessor, V... components) <VL,VR> int compareCustom(VL left, ValueAccessor<VL> accessorL, VR right, ValueAccessor<VR> accessorR) Implement IFF ComparisonType is CUSTOM Compares the byte representation of two instances of this class, for types where this cannot be done by simple in-order comparison of the unsigned bytes Standard Java compare semanticsbooleanAbstractType<?>Replace any instances of UserType with equivalent TupleType-s.<V> VfromComparableBytes(ValueAccessor<V> accessor, ByteSource.Peekable comparableBytes, ByteComparable.Version version) Translates the given byte-ordered representation to the common, non-byte-ordered binary representation of a payload for this abstract type (the latter, common binary representation is what we mostly work with in the storage engine internals).fromJSONObject(Object parsed) Given a parsed JSON string, return a byte representation of the object.fromString(String source) get a byte representation of the given string.static TupleTypegetInstance(TypeParser parser) <V> StringgetString(V input, ValueAccessor<V> accessor) get a string representation of the bytes used for various identifier (NOT just for log messages)inthashCode()booleanisCompatibleWith(AbstractType<?> previous) Returns true if this comparator is compatible with the provided previous comparator, that is if previous can safely be replaced by this.booleanisTuple()booleanisValueCompatibleWithInternal(AbstractType<?> otherType) Needed to handle ReversedType in value-compatibility checks.boolean<V> booleanreferencesUserType(V name, ValueAccessor<V> accessor) intsize()<V> V[]split(ValueAccessor<V> accessor, V value) Split a tuple value into its component values.static <V> V[]split(ValueAccessor<V> accessor, V value, int numberOfElements, TupleType type) Split a tuple value into its component values.List<AbstractType<?>>subTypes()toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion) Converts the specified value into its JSON representation.toString()This must be overriden by subclasses if necessary so that for any AbstractType, this == TypeParser.parse(toString()).AbstractType<?>type(int i) Returns an instance of this type with all references to the provided user type recursively replaced with its new definition.Methods inherited from class org.apache.cassandra.db.marshal.AbstractType
asComparableBytes, asCQLTypeStringList, checkComparable, compare, compare, compareCollectionMembers, compareForCQL, compose, compose, decompose, decomposeUntyped, freeze, freezeNestedMulticellTypes, fromComparableBytes, getArgumentDeserializer, getCompatibleTypeIfKnown, getComponents, getString, getString, isCollection, isCounter, isEmptyValueMeaningless, isFreezable, isFrozenCollection, isMultiCell, isNull, isNull, isReversed, isSerializationCompatibleWith, isUDT, isValueCompatibleWith, isValueLengthFixed, isVector, parseDefaultParameters, read, readArray, readBuffer, readBuffer, referencesUserType, skipValue, testAssignment, testAssignment, toCQLString, toJSONString, toString, udfType, unfreeze, unwrap, validate, validate, validateCellValue, validateCollectionMember, valueLengthIfFixed, writeValue, writeValue, writtenLength, writtenLengthMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
types
-
-
Constructor Details
-
TupleType
-
TupleType
-
-
Method Details
-
allowsEmpty
public boolean allowsEmpty()Description copied from class:AbstractTypeDefines if the type allows an empty set of bytes (new byte[0]) as valid input. TheAbstractType.validate(Object, ValueAccessor)andAbstractType.compose(Object, ValueAccessor)methods must allow empty bytes when this returns true, and must reject empty bytes when this is false. As of this writing, the main user of this API is for testing to know what types allow empty values and what types don't, so that the data that gets generated understands whenByteBufferUtil.EMPTY_BYTE_BUFFERis allowed as valid data.- Overrides:
allowsEmptyin classAbstractType<ByteBuffer>
-
getInstance
public static TupleType getInstance(TypeParser parser) throws ConfigurationException, SyntaxException -
referencesUserType
- Overrides:
referencesUserTypein classAbstractType<ByteBuffer>
-
withUpdatedUserType
Description copied from class:AbstractTypeReturns an instance of this type with all references to the provided user type recursively replaced with its new definition.- Overrides:
withUpdatedUserTypein classAbstractType<ByteBuffer>
-
expandUserTypes
Description copied from class:AbstractTypeReplace any instances of UserType with equivalent TupleType-s. We need it for dropped_columns, to allow safely dropping unused user types later without retaining any references to them in system_schema.dropped_columns.- Overrides:
expandUserTypesin classAbstractType<ByteBuffer>
-
referencesDuration
public boolean referencesDuration()- Overrides:
referencesDurationin classAbstractType<ByteBuffer>
-
type
-
size
public int size() -
subTypes
- Overrides:
subTypesin classAbstractType<ByteBuffer>
-
allTypes
-
isTuple
public boolean isTuple()- Overrides:
isTuplein classAbstractType<ByteBuffer>
-
compareCustom
public <VL,VR> int compareCustom(VL left, ValueAccessor<VL> accessorL, VR right, ValueAccessor<VR> accessorR) Description copied from class:AbstractTypeImplement IFF ComparisonType is CUSTOM Compares the byte representation of two instances of this class, for types where this cannot be done by simple in-order comparison of the unsigned bytes Standard Java compare semantics- Overrides:
compareCustomin classAbstractType<ByteBuffer>
-
asComparableBytes
public <V> ByteSource asComparableBytes(ValueAccessor<V> accessor, V data, ByteComparable.Version version) Description copied from class:AbstractTypeProduce a byte-comparable representation of the given value, i.e. a sequence of bytes that compares the same way using lexicographical unsigned byte comparison as the original value using the type's comparator. We use a slightly stronger requirement to be able to use the types in tuples. Precisely, for any pair x, y of non-equal valid values of this type and any bytes b1, b2 between 0x10 and 0xEF, (+ stands for concatenation) compare(x, y) == compareLexicographicallyUnsigned(asByteComparable(x)+b1, asByteComparable(y)+b2) (i.e. the values compare like the original type, and an added 0x10-0xEF byte at the end does not change that) and: asByteComparable(x)+b1 is not a prefix of asByteComparable(y) (weakly prefix free) (i.e. a valid representation of a value may be a prefix of another valid representation of a value only if the following byte in the latter is smaller than 0x10 or larger than 0xEF). These properties are trivially true if the encoding compares correctly and is prefix free, but also permits a little more freedom that enables somewhat more efficient encoding of arbitrary-length byte-comparable blobs. Depending on the type, this method can be called for null or empty input, in which case the output is allowed to be null (the clustering/tuple encoding will accept and handle it).- Overrides:
asComparableBytesin classAbstractType<ByteBuffer>
-
fromComparableBytes
public <V> V fromComparableBytes(ValueAccessor<V> accessor, ByteSource.Peekable comparableBytes, ByteComparable.Version version) Description copied from class:AbstractTypeTranslates the given byte-ordered representation to the common, non-byte-ordered binary representation of a payload for this abstract type (the latter, common binary representation is what we mostly work with in the storage engine internals). If the given bytes don't correspond to the encoding of some payload value for this abstract type, anIllegalArgumentExceptionmay be thrown.- Overrides:
fromComparableBytesin classAbstractType<ByteBuffer>- Parameters:
accessor- value accessor used to construct the value.comparableBytes- A byte-ordered representation (presumably of a payload for this abstract type).version- The byte-comparable version used to construct the representation.- Returns:
- A of a payload for this abstract type, corresponding to the given byte-ordered representation, constructed using the supplied value accessor.
- See Also:
-
split
Split a tuple value into its component values. -
split
public static <V> V[] split(ValueAccessor<V> accessor, V value, int numberOfElements, TupleType type) Split a tuple value into its component values. -
buildValue
-
buildValue
-
getString
Description copied from class:AbstractTypeget a string representation of the bytes used for various identifier (NOT just for log messages)- Overrides:
getStringin classAbstractType<ByteBuffer>
-
fromString
Description copied from class:AbstractTypeget a byte representation of the given string.- Specified by:
fromStringin classAbstractType<ByteBuffer>
-
fromJSONObject
Description copied from class:AbstractTypeGiven a parsed JSON string, return a byte representation of the object.- Specified by:
fromJSONObjectin classAbstractType<ByteBuffer>- Parameters:
parsed- the result of parsing a json string- Throws:
MarshalException
-
toJSONString
Description copied from class:AbstractTypeConverts the specified value into its JSON representation.The buffer position will stay the same.
- Overrides:
toJSONStringin classAbstractType<ByteBuffer>- Parameters:
buffer- the value to convertprotocolVersion- the protocol version to use for the conversion- Returns:
- a JSON string representing the specified value
-
getSerializer
- Specified by:
getSerializerin classAbstractType<ByteBuffer>
-
isCompatibleWith
Description copied from class:AbstractTypeReturns true if this comparator is compatible with the provided previous comparator, that is if previous can safely be replaced by this. A comparator cn should be compatible with a previous one cp if forall columns c1 and c2, if cn.validate(c1) and cn.validate(c2) and cn.compare(c1, c2) == v, then cp.validate(c1) and cp.validate(c2) and cp.compare(c1, c2) == v. Note that a type should be compatible with at least itself and when in doubt, keep the default behavior of not being compatible with any other comparator!- Overrides:
isCompatibleWithin classAbstractType<ByteBuffer>
-
isValueCompatibleWithInternal
Description copied from class:AbstractTypeNeeded to handle ReversedType in value-compatibility checks. Subclasses should implement this instead of isValueCompatibleWith().- Overrides:
isValueCompatibleWithInternalin classAbstractType<ByteBuffer>
-
hashCode
public int hashCode() -
equals
- Specified by:
equalsin interfaceComparator<ByteBuffer>- Overrides:
equalsin classObject
-
asCQL3Type
- Overrides:
asCQL3Typein classAbstractType<ByteBuffer>
-
toString
Description copied from class:AbstractTypeThis must be overriden by subclasses if necessary so that for any AbstractType, this == TypeParser.parse(toString()). Note that for backwards compatibility this includes the full classname. For CQL purposes the short name is fine.- Overrides:
toStringin classAbstractType<ByteBuffer>
-
getMaskedValue
- Overrides:
getMaskedValuein classAbstractType<ByteBuffer>- Returns:
- A fixed, serialized value to be used when the column is masked, to be returned instead of the real value.
-