This topic describes the functions that are supported by Lindorm Cassandra Query Language (CQL). This topic also describes how to use these functions.

Lindorm CQL supports the following categories of functions: scalar functions and native aggregate functions.

  • Scalar functions are used to obtain values and generate outputs.
  • Native aggregate functions are used to aggregate values of multiple rows that are returned by a SELECT statement.
Note Lindorm CQL provides multiple native hard-coded functions.

The following table provides common scalar functions and native aggregate functions.

Type Function
scalar function cast, now, maxTimeuuid, minTimeuuid, time conversion functions, and blob conversion functions
native aggregate function count, sum, avg, min, and max

Cast

The cast function is used to convert data from one native data type into another data type.

Data type conversion

The following table lists the source data types that can be converted by the cast function and the destination data types to which each source data type can be converted.

Source data type Destination data type
ascii text
bigint tinyint, smallint, int, float, double, decimal, varint, or text
boolean text
counter tinyint, smallint, int, bigint, float, double, decimal, varint, or text
date timestamp
decimal tinyint, smallint, int, bigint, float, double, varint, or text
double tinyint, smallint, int, bigint, float, decimal, varint, or text
float tinyint, smallint, int, bigint, double, decimal, varint, or text
inet text
int tinyint, smallint, bigint, float, double, decimal, varint, or text
time text
timestamp date or text
timeuuid timestamp, date, or text
tinyint tinyint, smallint, int, bigint, float, double, decimal, varint, or text
uuid text
varint tinyint, smallint, int, bigint, float, double, decimal, or text
Note

The conversions strictly rely on the semantics of Java.

Examples
CREATE TABLE persioninfo (c1 int PRIMARY KEY, c2 timeuuid);
SELECT avg(cast(c1 as double)) FROM persioninfo;

Now

The now function is used to return the current time.

The now function accepts no parameters. When you call this function, the system generates a new and unique value in the timeuuid format on a coordinator node. If you specify the now function in a WHERE clause, no result is returned. This way, each value returned by the now function is guaranteed to be unique. The following code provides an example.

SELECT * FROM persioninfo WHERE c2 = now()

maxTimeuuid and minTimeuuid functions

The maxTimeuuid function accepts a timestamp value that can be a timestamp or a date string and returns the largest TimeUUID for the timestamp value. The minTimeuuid function accepts a timestamp value that can be a timestamp or a date string and returns the smallest TimeUUID for the timestamp value.

Examples
SELECT * FROM persioninfo WHERE c2 > maxTimeuuid('2013-01-01 00:05+0000')    AND c2 < minTimeuuid('2013-02-02 10:00+0000') ALLOW FILTERING ;

Datetime

A date or time-related function is used to retrieve the date or time when the function is called.

Function Output type
currentTimestamp Timestamp
currentDate date
currentTime time
currentTimeUUID timeUUID

Time Conversion

A time conversion function is used to convert timeuuid data, timestamps, or dates into native data types supported by Lindorm CQL.

Function Input type Description
toDate timeuuid Converts the timeuuid type into the date type.
toDate timestamp Converts the timestamp type into the date type.
toTimestamp timeuuid Converts the timeuuid type into the timestamp type.
toTimestamp date Converts the date type into the timestamp type.
toUnixTimestamp timeuuid Converts the timeuuid type into the bigint type.
toUnixTimestamp timestamp Converts the timestamp type into the bigint (raw) type.
toUnixTimestamp date Converts the date type into the bigint (raw) type.

Blob Conversion

A blob conversion function is used to convert native data types into binary data or blobs.

For each native data type supported by Lindorm CQL, the typeAsBlob function accepts a parameter value of that data type and returns it as a blob. The blobAsType function accepts only 64-bit binary data and converts the data into a bigint value. For example, bigintAsBlob(3) returns 0x0000000000000003 and blobAsBigint(0x0000000000000003) returns 3.

CREATE TABLE persioninfo (c1 text PRIMARY KEY, c2 bigint);
INSERT INTO persioninfo (c1, c2) VALUES ( '11', blobAsBigint(0x0000000000000003));

Count

The count function is used to count the number of non-empty values in a specified column. This function can also be used to count the number of returned rows.

Examples

Calculate the number of returned rows.

SELECT COUNT (*) FROM persioninfo;
SELECT COUNT (1) FROM persioninfo;

Calculate the number of non-empty values in a specified column.

SELECT COUNT (c2) FROM persioninfo;

max and min functions

The max function is used to return the maximum value in a specified column. The min function is used to return the minimum value in a specified column.

Examples
CREATE TABLE persioninfo (c1 text PRIMARY KEY, c2 int);
INSERT INTO persioninfo (c1, c2) VALUES ('k1', 3);
INSERT INTO persioninfo (c1, c2) VALUES ('k2', 4);
SELECT min(c2), max(c2) FROM persioninfo;

Sum

The sum function is used to add all values in a specified column.

Examples
SELECT sum(c2) FROM persioninfo ;

Avg

The avg function is used to calculate the average of all the values in a specified column.

Examples
SELECT avg(c2) FROM persioninfo ;