Class DataType
- java.lang.Object
-
- org.apache.cassandra.cql3.functions.types.DataType
-
- Direct Known Subclasses:
DataType.CollectionType
,DataType.CustomType
,DataType.NativeType
,TupleType
,UserType
public abstract class DataType extends java.lang.Object
Data types supported by cassandra.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataType.CollectionType
Instances of this class represent collection types, that is, lists, sets or maps.static class
DataType.CustomType
A "custom" type is a type that cannot be expressed as a CQL type.static class
DataType.Name
The CQL type name.static class
DataType.NativeType
Instances of this class represent CQL native types, also known as CQL primitive types.
-
Field Summary
Fields Modifier and Type Field Description protected DataType.Name
name
-
Constructor Summary
Constructors Modifier Constructor Description protected
DataType(DataType.Name name)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static DataType
ascii()
Returns the ASCII type.java.lang.String
asFunctionParameterString()
Returns a String representation of this data type suitable for inclusion as a parameter type in a function or aggregate signature.static DataType
bigint()
Returns the BIGINT type.static DataType
blob()
Returns the BLOB type.static DataType
cboolean()
Returns the BOOLEAN type.static DataType
cdouble()
Returns the DOUBLE type.static DataType
cfloat()
Returns the FLOAT type.static DataType
cint()
Returns the INT type.static DataType
counter()
Returns the COUNTER type.static DataType.CustomType
custom(java.lang.String typeClassName)
Returns a Custom type.static DataType
date()
Returns the DATE type.static DataType
decimal()
Returns the DECIMAL type.static DataType
duration()
Returns the Duration type, introduced in Cassandra 3.10.DataType.Name
getName()
Returns the name of that type.java.util.List<DataType>
getTypeArguments()
Returns the type arguments of this type.static DataType
inet()
Returns the INET type.boolean
isCollection()
Returns whether this data type represent a CQLcollection type
, that is, a list, set or map.abstract boolean
isFrozen()
Returns whether this data type is frozen.static DataType.CollectionType
list(DataType elementType)
Returns the type of "not frozen" lists ofelementType
elements.static DataType.CollectionType
list(DataType elementType, boolean frozen)
Returns the type of lists ofelementType
elements.static DataType.CollectionType
map(DataType keyType, DataType valueType)
Returns the type of "not frozen" maps ofkeyType
tovalueType
elements.static DataType.CollectionType
map(DataType keyType, DataType valueType, boolean frozen)
Returns the type of maps ofkeyType
tovalueType
elements.static DataType.CollectionType
set(DataType elementType)
Returns the type of "not frozen" sets ofelementType
elements.static DataType.CollectionType
set(DataType elementType, boolean frozen)
Returns the type of sets ofelementType
elements.static DataType
smallint()
Returns the SMALLINT type.static DataType
text()
Returns the TEXT type.static DataType
time()
Returns the TIME type.static DataType
timestamp()
Returns the TIMESTAMP type.static DataType
timeuuid()
Returns the TIMEUUID type.static DataType
tinyint()
Returns the TINYINT type.static DataType
uuid()
Returns the UUID type.static DataType
varchar()
Returns the VARCHAR type.static DataType
varint()
Returns the VARINT type.
-
-
-
Field Detail
-
name
protected final DataType.Name name
-
-
Constructor Detail
-
DataType
protected DataType(DataType.Name name)
-
-
Method Detail
-
ascii
public static DataType ascii()
Returns the ASCII type.- Returns:
- The ASCII type.
-
bigint
public static DataType bigint()
Returns the BIGINT type.- Returns:
- The BIGINT type.
-
blob
public static DataType blob()
Returns the BLOB type.- Returns:
- The BLOB type.
-
cboolean
public static DataType cboolean()
Returns the BOOLEAN type.- Returns:
- The BOOLEAN type.
-
counter
public static DataType counter()
Returns the COUNTER type.- Returns:
- The COUNTER type.
-
decimal
public static DataType decimal()
Returns the DECIMAL type.- Returns:
- The DECIMAL type.
-
cdouble
public static DataType cdouble()
Returns the DOUBLE type.- Returns:
- The DOUBLE type.
-
cfloat
public static DataType cfloat()
Returns the FLOAT type.- Returns:
- The FLOAT type.
-
inet
public static DataType inet()
Returns the INET type.- Returns:
- The INET type.
-
tinyint
public static DataType tinyint()
Returns the TINYINT type.- Returns:
- The TINYINT type.
-
smallint
public static DataType smallint()
Returns the SMALLINT type.- Returns:
- The SMALLINT type.
-
cint
public static DataType cint()
Returns the INT type.- Returns:
- The INT type.
-
text
public static DataType text()
Returns the TEXT type.- Returns:
- The TEXT type.
-
timestamp
public static DataType timestamp()
Returns the TIMESTAMP type.- Returns:
- The TIMESTAMP type.
-
date
public static DataType date()
Returns the DATE type.- Returns:
- The DATE type.
-
time
public static DataType time()
Returns the TIME type.- Returns:
- The TIME type.
-
uuid
public static DataType uuid()
Returns the UUID type.- Returns:
- The UUID type.
-
varchar
public static DataType varchar()
Returns the VARCHAR type.- Returns:
- The VARCHAR type.
-
varint
public static DataType varint()
Returns the VARINT type.- Returns:
- The VARINT type.
-
timeuuid
public static DataType timeuuid()
Returns the TIMEUUID type.- Returns:
- The TIMEUUID type.
-
list
public static DataType.CollectionType list(DataType elementType, boolean frozen)
Returns the type of lists ofelementType
elements.- Parameters:
elementType
- the type of the list elements.frozen
- whether the list is frozen.- Returns:
- the type of lists of
elementType
elements.
-
list
public static DataType.CollectionType list(DataType elementType)
Returns the type of "not frozen" lists ofelementType
elements.This is a shorthand for
list(elementType, false);
.- Parameters:
elementType
- the type of the list elements.- Returns:
- the type of "not frozen" lists of
elementType
elements.
-
set
public static DataType.CollectionType set(DataType elementType, boolean frozen)
Returns the type of sets ofelementType
elements.- Parameters:
elementType
- the type of the set elements.frozen
- whether the set is frozen.- Returns:
- the type of sets of
elementType
elements.
-
set
public static DataType.CollectionType set(DataType elementType)
Returns the type of "not frozen" sets ofelementType
elements.This is a shorthand for
set(elementType, false);
.- Parameters:
elementType
- the type of the set elements.- Returns:
- the type of "not frozen" sets of
elementType
elements.
-
map
public static DataType.CollectionType map(DataType keyType, DataType valueType, boolean frozen)
Returns the type of maps ofkeyType
tovalueType
elements.- Parameters:
keyType
- the type of the map keys.valueType
- the type of the map values.frozen
- whether the map is frozen.- Returns:
- the type of maps of
keyType
tovalueType
elements.
-
map
public static DataType.CollectionType map(DataType keyType, DataType valueType)
Returns the type of "not frozen" maps ofkeyType
tovalueType
elements.This is a shorthand for
map(keyType, valueType, false);
.- Parameters:
keyType
- the type of the map keys.valueType
- the type of the map values.- Returns:
- the type of "not frozen" maps of
keyType
tovalueType
elements.
-
custom
public static DataType.CustomType custom(java.lang.String typeClassName)
Returns a Custom type.A custom type is defined by the name of the class used on the Cassandra side to implement it. Note that the support for custom types by the driver is limited.
The use of custom types is rarely useful and is thus not encouraged.
- Parameters:
typeClassName
- the server-side fully qualified class name for the type.- Returns:
- the custom type for
typeClassName
.
-
duration
public static DataType duration()
Returns the Duration type, introduced in Cassandra 3.10.Note that a Duration type does not have a native representation in CQL, and technically, is merely a special
custom type
from the driver's point of view.- Returns:
- the Duration type. The returned instance is a singleton.
-
getName
public DataType.Name getName()
Returns the name of that type.- Returns:
- the name of that type.
-
isFrozen
public abstract boolean isFrozen()
Returns whether this data type is frozen.This applies to User Defined Types, tuples and nested collections. Frozen types are serialized as a single value in Cassandra's storage engine, whereas non-frozen types are stored in a form that allows updates to individual subfields.
- Returns:
- whether this data type is frozen.
-
isCollection
public boolean isCollection()
Returns whether this data type represent a CQLcollection type
, that is, a list, set or map.- Returns:
- whether this data type name represent the name of a collection type.
-
getTypeArguments
public java.util.List<DataType> getTypeArguments()
Returns the type arguments of this type.Note that only the collection types (LIST, MAP, SET) have type arguments. For the other types, this will return an empty list.
For the collection types:
- For lists and sets, this method returns one argument, the type of the elements.
- For maps, this method returns two arguments, the first one is the type of the map keys, the second one is the type of the map values.
- Returns:
- an immutable list containing the type arguments of this type.
-
asFunctionParameterString
public java.lang.String asFunctionParameterString()
Returns a String representation of this data type suitable for inclusion as a parameter type in a function or aggregate signature.In such places, the String representation might vary from the canonical one as returned by
Object.toString()
; e.g. thefrozen
keyword is not accepted.- Returns:
- a String representation of this data type suitable for inclusion as a parameter type in a function or aggregate signature.
-
-