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.String
keyspace
java.nio.ByteBuffer
name
-
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 CQL3Type
asCQL3Type()
CellPath
cellPathForField(FieldIdentifier fieldName)
java.util.Optional<Difference>
compare(UserType other)
java.lang.String
elementKeyspace()
Returns the CQL name of the keyspace to which this schema element belong.java.lang.String
elementName()
Returns the CQL name of this schema element.SchemaElement.SchemaElementType
elementType()
Return the schema element typeboolean
equals(java.lang.Object o)
FieldIdentifier
fieldName(int i)
java.lang.String
fieldNameAsString(int i)
java.util.List<FieldIdentifier>
fieldNames()
int
fieldPosition(FieldIdentifier fieldName)
AbstractType<?>
fieldType(int i)
java.util.List<AbstractType<?>>
fieldTypes()
UserType
freeze()
AbstractType<?>
freezeNestedMulticellTypes()
Returns an AbstractType instance that is equivalent to this one, but with all nested UDTs and collections explicitly frozen.Term
fromJSONObject(java.lang.Object parsed)
Given a parsed JSON string, return a byte representation of the object.java.lang.String
getCqlTypeName()
static UserType
getInstance(TypeParser parser)
java.lang.String
getNameAsString()
TypeSerializer<java.nio.ByteBuffer>
getSerializer()
int
hashCode()
boolean
isFreezable()
boolean
isMultiCell()
boolean
isTuple()
boolean
isUDT()
boolean
isValueCompatibleWith(AbstractType<?> previous)
Returns true if values of the other AbstractType can be read and "reasonably" interpreted by the this AbstractType.ShortType
nameComparator()
boolean
referencesDuration()
<V> boolean
referencesUserType(V name, ValueAccessor<V> accessor)
java.nio.ByteBuffer
serializeForNativeProtocol(java.util.Iterator<Cell<?>> cells, ProtocolVersion protocolVersion)
java.lang.String
toCqlString(boolean withInternals, boolean ifNotExists)
Returns a CQL representation of this elementjava.lang.String
toJSONString(java.nio.ByteBuffer buffer, ProtocolVersion protocolVersion)
Converts the specified value into its JSON representation.java.lang.String
toString()
This must be overriden by subclasses if necessary so that for any AbstractType, this == TypeParser.parse(toString()).java.lang.String
toString(boolean ignoreFreezing)
<V> void
validateCell(Cell<V> cell)
UserType
withUpdatedUserType(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, subTypes, type
-
Methods inherited from class org.apache.cassandra.db.marshal.AbstractType
asCQLTypeStringList, checkComparable, compare, compare, compareCollectionMembers, compareForCQL, compose, compose, decompose, getComponents, getString, getString, isCollection, isCounter, isEmptyValueMeaningless, isFrozenCollection, isReversed, parseDefaultParameters, read, readArray, readBuffer, readBuffer, referencesUserType, skipValue, testAssignment, testAssignment, toJSONString, 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:
isUDT
in classAbstractType<java.nio.ByteBuffer>
-
isMultiCell
public boolean isMultiCell()
- Overrides:
isMultiCell
in classAbstractType<java.nio.ByteBuffer>
-
isFreezable
public boolean isFreezable()
- Overrides:
isFreezable
in 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:AbstractType
Given a parsed JSON string, return a byte representation of the object.- Overrides:
fromJSONObject
in 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:AbstractType
Converts the specified value into its JSON representation.The buffer position will stay the same.
- Overrides:
toJSONString
in 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:
freeze
in classAbstractType<java.nio.ByteBuffer>
-
freezeNestedMulticellTypes
public AbstractType<?> freezeNestedMulticellTypes()
Description copied from class:AbstractType
Returns 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.x
schema migrations, and can be removed in Cassandra 4.0. See CASSANDRA-11609 and CASSANDRA-11613.- Overrides:
freezeNestedMulticellTypes
in classAbstractType<java.nio.ByteBuffer>
-
isValueCompatibleWith
public boolean isValueCompatibleWith(AbstractType<?> previous)
Description copied from class:AbstractType
Returns 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:
isValueCompatibleWith
in 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:
asCQL3Type
in classTupleType
-
referencesUserType
public <V> boolean referencesUserType(V name, ValueAccessor<V> accessor)
- Overrides:
referencesUserType
in classTupleType
-
withUpdatedUserType
public UserType withUpdatedUserType(UserType udt)
Description copied from class:AbstractType
Returns an instance of this type with all references to the provided user type recursively replaced with its new definition.- Overrides:
withUpdatedUserType
in classTupleType
-
referencesDuration
public boolean referencesDuration()
- Overrides:
referencesDuration
in classTupleType
-
toString
public java.lang.String toString()
Description copied from class:AbstractType
This 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:
toString
in 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:
getSerializer
in classTupleType
-
elementType
public SchemaElement.SchemaElementType elementType()
Description copied from interface:SchemaElement
Return the schema element type- Specified by:
elementType
in interfaceSchemaElement
- Returns:
- the schema element type
-
elementKeyspace
public java.lang.String elementKeyspace()
Description copied from interface:SchemaElement
Returns the CQL name of the keyspace to which this schema element belong.- Specified by:
elementKeyspace
in interfaceSchemaElement
- Returns:
- the keyspace name.
-
elementName
public java.lang.String elementName()
Description copied from interface:SchemaElement
Returns the CQL name of this schema element.- Specified by:
elementName
in interfaceSchemaElement
- Returns:
- the name of this schema element.
-
toCqlString
public java.lang.String toCqlString(boolean withInternals, boolean ifNotExists)
Description copied from interface:SchemaElement
Returns a CQL representation of this element- Specified by:
toCqlString
in 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
-
-