cassandra/doc/cql/CQL.textile

131 lines
5.2 KiB
Plaintext

h1. Cassandra Query Language (CQL) v0.99.1
h2. Table of Contents
{toc}
h2. USE
__Synopsis:__
bc.
USE <KEYSPACE>;
A @USE@ statement consists of the @USE@ keyword, followed by a valid keyspace name. Its purpose is to assign the per-connection, current working keyspace. All subsequent keyspace-specific actions will be performed in the context of the supplied value.
h2. SELECT
__Synopsis:__
bc.
SELECT [FIRST N] [REVERSED] <SELECT EXPR> FROM <COLUMN FAMILY> [USING <CONSISTENCY>]
[WHERE <CLAUSE>] [LIMIT N];
A @SELECT@ is used to read one or more records from a Cassandra column family. It returns a result-set of rows, where each row consists of a key and a collection of columns corresponding to the query.
h3. Specifying Columns
bc.
SELECT [FIRST N] [REVERSED] name1, name2, name3 FROM ...
SELECT [FIRST N] [REVERSED] name1..nameN FROM ...
The SELECT expression determines which columns will appear in the results and takes the form of either a comma separated list of names, or a range. The range notation consists of a start and end column name separated by two periods (@..@). The set of columns returned for a range is start and end inclusive.
The @FIRST@ option accepts an integer argument and can be used to apply a limit to the number of columns returned per row. When this limit is left unset it defaults to 10,000 columns.
The @REVERSED@ option causes the sort order of the results to be reversed.
It is worth noting that unlike the projection in a SQL SELECT, there is no guarantee that the results will contain all of the columns specified. This is because Cassandra is schema-less and there are no guarantees that a given column exists.
h3. Column Family
bc.
SELECT ... FROM <COLUMN FAMILY> ...
The @FROM@ clause is used to specify the Cassandra column family applicable to a @SELECT@ query.
h3. Consistency Level
bc.
SELECT ... [USING <CONSISTENCY>] ...
Following the column family clause is an optional "consistency level specification":#consistency.
h3. Filtering rows
bc.
SELECT ... WHERE KEY = keyname AND name1 = value1
SELECT ... WHERE KEY >= startkey and KEY =< endkey AND name1 = value1
The WHERE clause provides for filtering the rows that appear in results. The clause can filter on a key name, or range of keys, and in the case of indexed columns, on column values. Key filters are specified using the @KEY@ keyword, a relational operator, (one of @=@, @>@, @>=@, @<@, and @<=@), and a term value. When terms appear on both sides of a relational operator it is assumed the filter applies to an indexed column. With column index filters, the term on the left of the operator is the name, the term on the right is the value to filter __on__.
__Note: The greater-than and less-than operators (@>@ and @<@) result in key ranges that are inclusive of the terms. There is no supported notion of "strictly" greater-than or less-than; these operators are merely supported as aliases to @>=@ and @<=@.__
h3. Limits
bc.
SELECT ... WHERE <CLAUSE> [LIMIT N] ...
Limiting the number of rows returned can be achieved by adding the @LIMIT@ option to a @SELECT@ expression. @LIMIT@ defaults to 10,000 when left unset.
h2. UPDATE
_Synopsis:_
bc.
UPDATE <COLUMN FAMILY> [USING CONSISTENCY.<CL>] WITH
ROW(<KEY>, COL(<NAME>, <VALUE>), ...);
An @UPDATE@ is used to write one or more records to a Cassandra column family. No results are returned.
h3. Column Family
bc.
UPDATE <COLUMN FAMILY> ...
Statements begin with the @UPDATE@ keyword followed by a Cassandra column family name.
h3. Consistency Level
bc.
SELECT ... [USING <CONSISTENCY>] ...
Following the column family identifier is an optional "consistency level specification":#consistency.
h3. Rows and Columns
bc.
... WITH ROW(<KEY>, COL(<NAME>, <VALUE>), ...)[, ROW(<KEY>, ...)];
Rows are constructed by creating a parenthesized expression using the @ROW@ keyword. Within the parenthesis, row specifications contain a key "term":#terms, followed by a comma, and one or more comma delimited column specifications. Columns are in turn a parenthesized expression using the @COLUMN@ keyword, with two comma delimited "term":#terms arguments, the column name and value respectively. More than one row can be specified by separating them with commas.
_NOTE: While there are no isolation guarantees, @UPDATE@ queries are atomic._
h2. Common Idioms
h3(#consistency). Specifying Consistency
bc.
... USING <CONSISTENCY> ...
Consistency level specifications are made up the keyword @USING@, followed by a consistency level identifier. Valid consistency levels are as follows:
* @CONSISTENCY.ZERO@
* @CONSISTENCY.ONE@ (default)
* @CONSISTENCY.QUORUM@
* @CONSISTENCY.ALL@
* @CONSISTENCY.DCQUORUM@
* @CONSISTENCY.DCQUORUMSYNC@
h3(#terms). Term specification
Where possible, the type of terms are inferred; the following term types are supported:
h4. String Literals
String literals are any value enclosed in double-quotes, (`"`). String literals are treated as raw bytes; no interpolation is performed.
h4. Integers / longs
Integers are any term consisting soley of unquoted numericals, longs are any otherwise valid integer term followed by an upper case "L", (e.g. 100L). It is an error to specify an integer term that will not fit in 4 bytes unsigned, or a long that will not fit in 8 bytes unsigned.