Apache Cassandra Query Language (CQL)
Apache Cassandra Query Language (CQL)
SPECIFICATION 3.1.0
ALTER KEYSPACE
CREATE KEYSPACE
column_definition is:
column_name cql_type PRIMARY KEY
| ( PRIMARY KEY ( partition_key ) )
Restrictions:
There should always be exactly one primary key denition.
cql_type of the primary key must be a custom type or a CQL type (see last page),
other than a collection type.
cql_type of a collection uses this syntax:
LIST<cql_type>
| SET<cql_type>
| MAP<cql_type, cql_type>
BATCH
dml_statement is:
INSERT
UPDATE
DELETE
CREATE INDEX
CREATE TRIGGER
Restrictions:
USING class_name is only allowed if CUSTOM is used and
class_name is a string literal containing a java class name.
CREATE USER
* Uppercase means literal * Lowercase means not literal * Italics mean optional * The pipe (|) symbol means OR or AND/OR * Ellipsis (...) means repeatable * orange ( ) indicate scope, not literal
SPECIFICATION 3.1.0
DELETE
INSERT (continued)
LIST PERMISSIONS
DROP INDEX
DROP KEYSPACE
DROP TABLE
DROP TRIGGER
DROP USER
LIST USERS
LIST USERS
REVOKE
GRANT
SELECT
select_expression is:
selection_list | ( COUNT ( * | 1 ) )
selection_list is:
selector AS alias, selector AS alias, ... | *
INSERT
(continued)
(continued)
LEGEND:
SELECT select_expression
FROM keyspace_name.table_name
WHERE relation AND relation ...
ORDER BY (clustering_key ( ASC | DESC ), ... )
LIMIT n
ALLOW FILTERING
* Uppercase means literal * Lowercase means not literal * Italics mean optional * The pipe (|) symbol means OR or AND/OR * Ellipsis (...) means repeatable * orange ( ) indicate scope, not literal
SPECIFICATION 3.1.0
SELECT (continued)
relation is:
column_name ( = | < | > | <= | >= ) key_value
| column_name IN ( ( key_value, ... ) )
| TOKEN ( column_name, ... ) ( = | < | > | <= | >= )
( term | TOKEN ( term, ... ) )
bloom_filter_fp_chance
Desired false-positive probability for SSTable Bloom lters.
caching
Cache memory settings. Values: all, keys_only, rows_only, none.
comment
A human readable comment describing the table.
TRUNCATE keyspace_name.table_name
UPDATE
UPDATE keyspace_name.table_name
USING option AND option
SET assignment, assignment ...
WHERE row_specification
IF column_name = literal
AND column_name = literal ...
compaction
Options for SSTable compaction:
bucket_high
bucket_low
max_threshold
min_threshold
min_sstable_size
sstable_size_in_mb
tombstone_compaction_interval
tombstone_threshold
compression
The compression algorithm and subproperties for the table:
sstable_compression
chunk_length_kb
crc_check_chance
default_time_to_live
The default expiration time in seconds for a table. Used in MapReduce/Hive
scenarios in which you have no control of TTL.
dclocal_read_repair_chance
The probability of read repairs being invoked over all replicas in the current data
center.
gc_grace_seconds
The time to wait before garbage collecting tombstones (deletion markers).
term is:
[ list_position ] | key_value
index_interval
The number of keys that are sampled to create the partition summary, a subset
of the partition index.
memtable_flush_period_in_ms
Forces flushing of the memtable after the number of specied milliseconds
elapses.
USE keyspace_name
populate_io_cache_on_flush
Populates the page cache on memtable flush and compaction. Enable only
when all data on the node ts in memory. Defaults is false. Used to t only one
of several tables inside single keyspace.
LEGEND:
* Uppercase means literal * Lowercase means not literal * Italics mean optional * The pipe (|) symbol means OR or AND/OR * Ellipsis (...) means repeatable * orange ( ) indicate scope, not literal
SPECIFICATION 3.1.0
Syntax elements
TM
read_repair_chance
Species the probability for invoking read repairs on non-quorum reads.
Generally, the elements used in the command syntax have the following
denitions. A few elements have a slightly different meaning when used with a
particular command and are redened in the synopsis of the command.
replicate_on_write
Writes counter table data to all affected replicas regardless of the consistency
level specied by the client for a write request.
clustering_key
Columns in addition to the partitioning key component of a primary key that
determine clustering.
speculative_retry
Overrides normal read timeout when read_repair is not 1.0, sending another
request to read. Options:
ALL Retry reads of all replicas.
Xpercentile Retry reads based on the effect on throughput and latency.
Yms Retry reads after specified milliseconds
NONE Do not retry reads.
column_name
Alphanumeric column name, case-insensitive unless enclosed in double
quotation marks. No reserved keywords. Unreserved keywords enclosed in
quotation marks are ok. Enclose names having unparseable characters in
double quotation marks.
constant
A string, integer, float, boolean, UUID, or blob.
counter_column_name
A column_name of a column of type counter.
Functions
keyspace_name
A keyspace name, starting with an alpha character, consisting of 32 or fewer
alpha-numeric characters and underscores. Case-insensitive unless enclosed
in double quotation marks.
Blob conversion
Converts native types into binary data (blob).
typeAsBlob() takes a native type and returns it as a blob
bigintAsBlob(3) returns 0x0000000000000003
blobAsType takes a 64-bit blob argument and converts it to a bigint value
blobAsBigint(0x0000000000000003) returns 3
key_value
The value of a primary key.
literal
Data that is of a supported data type
Float constant in E notation
Numeric constant
A letter, followed by any sequence of letters, digits, or the underscore
A string, characters enclosed in single quotation marks
Whitespace that separates of terms, otherwise ignored
dateOf()
Used in a SELECT clause to extract the timestamp of a timeuuid column in a
resultset. Returns the extracted timestamp as a date.
minTimeuuid() and maxTimeuuid()
Returns a UUID-like result given a conditional time component as an argument.
Example:
SELECT * FROM myTable
WHERE t > maxTimeuuid('2013-01-01 00:05+0000')
AND t < minTimeuuid('2013-02-02 10:00+0000')
partitioning_key
The primary key column that determines on which node data is stored.
property
A CQL storage property, such as caching = "all".
now()
Generates a new unique timeuuid, useful for inserting values. Returns a unique
value.
table_name
Valid table names are strings of alphanumeric characters and underscores,
which begin with a letter.
unixTimestampOf()
Used in a SELECT clause to extract the timestamp of a timeuuid column in a
resultset. Returns a raw, 64-bit integer timestamp.
timestamp
Microseconds representing the standard base time since epoch: January 1
1970 at 00:00:00 GMT.
variable
A bind variable, such as ?, used with a prepared statement.
LEGEND:
* Uppercase means literal * Lowercase means not literal * Italics mean optional * The pipe (|) symbol means OR or AND/OR * Ellipsis (...) means repeatable * orange ( ) indicate scope, not literal
SPECIFICATION 3.1.0
Description
ASCII
BIGINT
BLOB
BOOLEAN
true or false
COUNTER
DECIMAL
Variable-precision decimal
DOUBLE
FLOAT
INET
INT
LIST
MAP
SET
TEXT
TIMESTAMP
UUID
TIMEUUID
VARCHAR
VARINT
Arbitrary-precision integer
Office Locations
DATASTAX HQ - SF BAY AREA
777 Mariners Island Blvd #510
San Mateo, CA 94404
650-389-6000
LEGEND:
DATASTAX TX
902 East 5th St. #202
Austin, TX 78702
512-537-7809
* Uppercase means literal * Lowercase means not literal * Italics mean optional * The pipe (|) symbol means OR or AND/OR * Ellipsis (...) means repeatable * orange ( ) indicate scope, not literal