Package org.apache.cassandra.db.marshal
Class UserType
- java.lang.Object
-
- org.apache.cassandra.db.marshal.AbstractType<java.nio.ByteBuffer>
-
- org.apache.cassandra.db.marshal.TupleType
-
- org.apache.cassandra.db.marshal.UserType
-
- All Implemented Interfaces:
java.util.Comparator<java.nio.ByteBuffer>,AssignmentTestable,SchemaElement
public class UserType extends TupleType implements SchemaElement
A user defined type. A user type is really just a tuple type on steroids.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.cassandra.db.marshal.AbstractType
AbstractType.ComparisonType
-
Nested classes/interfaces inherited from interface org.apache.cassandra.cql3.AssignmentTestable
AssignmentTestable.TestResult
-
Nested classes/interfaces inherited from interface org.apache.cassandra.cql3.SchemaElement
SchemaElement.SchemaElementType
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.Stringkeyspacejava.nio.ByteBuffername-
Fields inherited from class org.apache.cassandra.db.marshal.AbstractType
comparatorSet, comparisonType, isByteOrderComparable, reverseComparator
-
Fields inherited from interface org.apache.cassandra.cql3.SchemaElement
NAME_COMPARATOR
-
-
Constructor Summary
Constructors Constructor Description UserType(java.lang.String keyspace, java.nio.ByteBuffer name, java.util.List<FieldIdentifier> fieldNames, java.util.List<AbstractType<?>> fieldTypes, boolean isMultiCell)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CQL3TypeasCQL3Type()CellPathcellPathForField(FieldIdentifier fieldName)java.util.Optional<Difference>compare(UserType other)java.lang.StringelementKeyspace()Returns the CQL name of the keyspace to which this schema element belong.java.lang.StringelementName()Returns the CQL name of this schema element.SchemaElement.SchemaElementTypeelementType()Return the schema element typebooleanequals(java.lang.Object o)FieldIdentifierfieldName(int i)java.lang.StringfieldNameAsString(int i)java.util.List<FieldIdentifier>fieldNames()intfieldPosition(FieldIdentifier fieldName)AbstractType<?>fieldType(int i)java.util.List<AbstractType<?>>fieldTypes()UserTypefreeze()AbstractType<?>freezeNestedMulticellTypes()Returns an AbstractType instance that is equivalent to this one, but with all nested UDTs and collections explicitly frozen.TermfromJSONObject(java.lang.Object parsed)Given a parsed JSON string, return a byte representation of the object.java.lang.StringgetCqlTypeName()static UserTypegetInstance(TypeParser parser)java.lang.StringgetNameAsString()TypeSerializer<java.nio.ByteBuffer>getSerializer()inthashCode()booleanisFreezable()booleanisMultiCell()booleanisTuple()booleanisUDT()booleanisValueCompatibleWith(AbstractType<?> previous)Returns true if values of the other AbstractType can be read and "reasonably" interpreted by the this AbstractType.ShortTypenameComparator()booleanreferencesDuration()<V> booleanreferencesUserType(V name, ValueAccessor<V> accessor)java.nio.ByteBufferserializeForNativeProtocol(java.util.Iterator<Cell<?>> cells, ProtocolVersion protocolVersion)java.lang.StringtoCqlString(boolean withInternals, boolean ifNotExists)Returns a CQL representation of this elementjava.lang.StringtoJSONString(java.nio.ByteBuffer buffer, ProtocolVersion protocolVersion)Converts the specified value into its JSON representation.java.lang.StringtoString()This must be overriden by subclasses if necessary so that for any AbstractType, this == TypeParser.parse(toString()).java.lang.StringtoString(boolean ignoreFreezing)<V> voidvalidateCell(Cell<V> cell)UserTypewithUpdatedUserType(UserType udt)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.TupleType
allTypes, buildValue, buildValue, compareCustom, expandUserTypes, fromString, getString, isCompatibleWith, isValueCompatibleWithInternal, size, split, split, subTypes, type
-
Methods inherited from class org.apache.cassandra.db.marshal.AbstractType
asCQLTypeStringList, checkComparable, compare, compare, compareCollectionMembers, compareForCQL, compose, compose, decompose, decomposeUntyped, getComponents, getString, getString, isCollection, isCounter, isEmptyValueMeaningless, isFrozenCollection, isReversed, isSerializationCompatibleWith, parseDefaultParameters, read, readArray, readBuffer, readBuffer, referencesUserType, skipValue, testAssignment, testAssignment, toCQLString, toJSONString, udfType, unwrap, validate, validate, validateCellValue, validateCollectionMember, valueLengthIfFixed, writeValue, writeValue, writtenLength, writtenLength
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Methods inherited from interface org.apache.cassandra.cql3.SchemaElement
elementKeyspaceQuotedIfNeeded, elementNameQuotedIfNeeded
-
-
-
-
Constructor Detail
-
UserType
public UserType(java.lang.String keyspace, java.nio.ByteBuffer name, java.util.List<FieldIdentifier> fieldNames, java.util.List<AbstractType<?>> fieldTypes, boolean isMultiCell)
-
-
Method Detail
-
getInstance
public static UserType getInstance(TypeParser parser)
-
isUDT
public boolean isUDT()
- Overrides:
isUDTin classAbstractType<java.nio.ByteBuffer>
-
isMultiCell
public boolean isMultiCell()
- Overrides:
isMultiCellin classAbstractType<java.nio.ByteBuffer>
-
isFreezable
public boolean isFreezable()
- Overrides:
isFreezablein classAbstractType<java.nio.ByteBuffer>
-
fieldType
public AbstractType<?> fieldType(int i)
-
fieldTypes
public java.util.List<AbstractType<?>> fieldTypes()
-
fieldName
public FieldIdentifier fieldName(int i)
-
fieldNameAsString
public java.lang.String fieldNameAsString(int i)
-
fieldNames
public java.util.List<FieldIdentifier> fieldNames()
-
getNameAsString
public java.lang.String getNameAsString()
-
fieldPosition
public int fieldPosition(FieldIdentifier fieldName)
-
cellPathForField
public CellPath cellPathForField(FieldIdentifier fieldName)
-
nameComparator
public ShortType nameComparator()
-
serializeForNativeProtocol
public java.nio.ByteBuffer serializeForNativeProtocol(java.util.Iterator<Cell<?>> cells, ProtocolVersion protocolVersion)
-
validateCell
public <V> void validateCell(Cell<V> cell) throws MarshalException
- Throws:
MarshalException
-
fromJSONObject
public Term fromJSONObject(java.lang.Object parsed) throws MarshalException
Description copied from class:AbstractTypeGiven a parsed JSON string, return a byte representation of the object.- Overrides:
fromJSONObjectin classTupleType- Parameters:
parsed- the result of parsing a json string- Throws:
MarshalException
-
toJSONString
public java.lang.String toJSONString(java.nio.ByteBuffer buffer, ProtocolVersion protocolVersion)Description copied from class:AbstractTypeConverts the specified value into its JSON representation.The buffer position will stay the same.
- Overrides:
toJSONStringin classTupleType- Parameters:
buffer- the value to convertprotocolVersion- the protocol version to use for the conversion- Returns:
- a JSON string representing the specified value
-
freeze
public UserType freeze()
- Overrides:
freezein classAbstractType<java.nio.ByteBuffer>
-
freezeNestedMulticellTypes
public AbstractType<?> freezeNestedMulticellTypes()
Description copied from class:AbstractTypeReturns an AbstractType instance that is equivalent to this one, but with all nested UDTs and collections explicitly frozen. This is only necessary for2.x -> 3.xschema migrations, and can be removed in Cassandra 4.0. See CASSANDRA-11609 and CASSANDRA-11613.- Overrides:
freezeNestedMulticellTypesin classAbstractType<java.nio.ByteBuffer>
-
isValueCompatibleWith
public boolean isValueCompatibleWith(AbstractType<?> previous)
Description copied from class:AbstractTypeReturns true if values of the other AbstractType can be read and "reasonably" interpreted by the this AbstractType. Note that this is a weaker version of isCompatibleWith, as it does not require that both type compare values the same way. The restriction on the other type being "reasonably" interpreted is to prevent, for example, IntegerType from being compatible with all other types. Even though any byte string is a valid IntegerType value, it doesn't necessarily make sense to interpret a UUID or a UTF8 string as an integer. Note that a type should be compatible with at least itself.- Overrides:
isValueCompatibleWithin classAbstractType<java.nio.ByteBuffer>
-
equals
public boolean equals(java.lang.Object o)
-
compare
public java.util.Optional<Difference> compare(UserType other)
-
asCQL3Type
public CQL3Type asCQL3Type()
- Overrides:
asCQL3Typein classTupleType
-
referencesUserType
public <V> boolean referencesUserType(V name, ValueAccessor<V> accessor)- Overrides:
referencesUserTypein classTupleType
-
withUpdatedUserType
public UserType withUpdatedUserType(UserType udt)
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 classTupleType
-
referencesDuration
public boolean referencesDuration()
- Overrides:
referencesDurationin classTupleType
-
toString
public java.lang.String 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.
-
toString
public java.lang.String toString(boolean ignoreFreezing)
- Overrides:
toStringin classAbstractType<java.nio.ByteBuffer>- Parameters:
ignoreFreezing- if true, the type string will not be wrapped with FrozenType(...), even if this type is frozen.
-
getCqlTypeName
public java.lang.String getCqlTypeName()
-
getSerializer
public TypeSerializer<java.nio.ByteBuffer> getSerializer()
- Overrides:
getSerializerin classTupleType
-
elementType
public SchemaElement.SchemaElementType elementType()
Description copied from interface:SchemaElementReturn the schema element type- Specified by:
elementTypein interfaceSchemaElement- Returns:
- the schema element type
-
elementKeyspace
public java.lang.String elementKeyspace()
Description copied from interface:SchemaElementReturns the CQL name of the keyspace to which this schema element belong.- Specified by:
elementKeyspacein interfaceSchemaElement- Returns:
- the keyspace name.
-
elementName
public java.lang.String elementName()
Description copied from interface:SchemaElementReturns the CQL name of this schema element.- Specified by:
elementNamein interfaceSchemaElement- Returns:
- the name of this schema element.
-
toCqlString
public java.lang.String toCqlString(boolean withInternals, boolean ifNotExists)Description copied from interface:SchemaElementReturns a CQL representation of this element- Specified by:
toCqlStringin interfaceSchemaElement- Parameters:
withInternals- if the internals part of the CQL should be exposed.ifNotExists- if "IF NOT EXISTS" should be included.- Returns:
- a CQL representation of this element
-
-