CQL native functions 

Describes scalar functions that work on values in a single row of data to create a new value.

CQL supports several functions that transform a column value into a new value.

Tip: In addition, users can define functions and aggregates.

The native database functions are:

cast 
Converts the data returned by the selector to a native CQL data type.
cast( selector AS to_type )
Cast strictly relies on the Java semantics, for more details on the underlying type see Table 1. Only use in SELECT statements.
Note: Silently ignores casting a column into its own data type.
Selector column type Output data type (to_type)
ascii text, varchar
bigint

tinyint, smallint, int, varint, float, double, decimal, text, varchar

boolean text, varchar
counter tinyint, smallint, int, bigint, float, double, decimal, varint, text, varchar
date timestamp
decimal tinyint, smallint, int, bigint, float, double, varint, text, varchar
double tinyint, smallint, int, bigint, float, decimal, varint, text, varchar
float tinyint, smallint, int, bigint, double, decimal, varint, text, varchar
inet text, varchar
int tinyint, smallint, bigint, float, double, decimal, varint, text, varchar
smallint tinyint, int, bigint, float, double, decimal, varint,text, varchar
time text, varchar
timestamp date, text, varchar
timeuuid timestamp, date, text, varchar
tinyint tinyint, smallint, int, bigint, float, double, decimal, varint, text, varchar
uuid text, varchar
varint tinyint, smallint, int, bigint, float, double, decimal, text, varchar
The Java types, from which most CQL types are derived, are obvious to Java programmers. The derivation of the following types, however, might not be obvious:
CQL types Java derivation
CQL type Java type
decimal java.math.BigDecimal
float java.lang.Float
double java.lang.Double
varint java.math.BigInteger
blobAsType 
Converts the target column or literal (enclose strings in single quotes) from a blob to the specified To_type.
blobAsTo_type(column_name | literal)
  • Display blob columns as another data type in results of SELECT statements.
  • Convert raw blob data into another type for storage INSERT and UPDATE.
typeAsBlob 
Converts the target column or literal (enclose strings in single quotes) from a blob into the specified from_type, where the from type corresponds to a valid CQL data type.
from_typeAsBlob(column_name | literal )
Use in the following types of CQL statements:
  • SELECT selectors to return a value stored in another CQL type as a blob.
  • INSERT and UPDATE convert another CQL data type into a blob for storage.
token 
Computes a token for values in the target column.
token(column_name)
The exact signature of the token function depends on the table concerned and of the partitioner used by the cluster.
  • Murmur3Partitioner type is bigint
  • RandomPartitioner type is varint
  • ByteOrderedPartitioner type is blob
Use in the following CQL requests:
  • SELECT selector clause to return values in the target column as tokens; useful for manually paging through the data or to determine the physical location of a row or set of rows.
  • SELECT where clause to return a set of records in a given token range. Allows comparison (greater than and less then) in the where clause without the use of ALLOW FILTERING. Useful when dividing query workloads between clients, such as multiple Spark clients for analytics.
Note: UPDATE does not support the token function in the where clause.
minTimeuuid 
Computes the smallest fake timeuuid from the specified date ('yyyy-mm-dd') or timestamp ('yyyy-mm-dd [hh:mm:ss[.fff][+/-NNNN]]') formatted string.
minTimeuuid( date_string | timestamp_string )

Use in a SELECT statement WHERE clause to return rows in a date range from a timeuuid column, for example WHERE id >= minTimeuuid('2017-05-01').

maxTimeuuid 
Computes the largest fake timeuuid from the specified date ('yyyy-mm-dd') or timestamp ('yyyy-mm-dd [hh:mm:ss[.fff][+/-NNNN]]') formatted string.
maxTimeuuid( date_string | timestamp_string )

Use in a SELECT statement where clause to return rows in a date range from a timeuuid column, for example WHERE id <= maxTimeuuid('2017-05-01').

now 
Takes no arguments and generates, on the coordinator node, a new unique timeuuid at the time when the statement executed.
now()

Use in INSERT or UPDATE statements to generate a new timeuuid value.

Although allowed in WHERE clauses, no values would match a given SELECT or UPDATE statement because now() is guaranteed to be unique.

Restriction: UPDATE statements SET clause cannot be used to change PRIMARY KEY fields; therefore a new timeuuid can only be set if the target field is not part of the PRIMARY KEY field.
toDate 
Converts a timestamp value from milliseconds to days (since epoch) and for timeuuid extracts the timestamp and converts it to days since epoch.
toDate(column_name)
Note: Dates and times display in string format, but are stored and compared as integers.
toTimestamp 
Converts a date value from days into milliseconds since epoch and for timeuuid extracts the timestamp.
toTimestamp(column_name)
Note: Time (hh:mm:ss.ffffff+NNNN) of a date are all set to zero in the resulting timestamp.
toUnixTimestamp 
Converts the timeuuid, timestamp, or date column into the number of seconds since epoch.
toUnixTimestamp(column_name)
uuid 
Takes no parameters and generates a random type 4 uuid.
uuid()
Use to generate a value in INSERT and UPDATE.
Restriction: UPDATE statements SET clause cannot be used to change PRIMARY KEY fields; therefore a new UUID can only be set if the target field is not part of the PRIMARY KEY field.
writetime 
Shows the unix timestamp (number of seconds since epoch) that the data was written.
writetime(column_name)
Use only in selectors clause of SELECT statements on non-partition key columns.
ttl 
Count down in seconds until the value in the field expires and the data is automatically removed; null indicates that TTL for the column is not set (or the count down has ended).
ttl(column_name)
Use only in selectors clause of SELECT statements on non-partition key columns.

Deprecated functions 

The following functions are supported for backward compatibility only.

dateOf  
Similar to toTimestamp(timeuuid).
unixTimestampOf 
Similar to toUnixTimestamp(timeuuid).