From 79ef219422ab013220fc8bae16457d9aa41f4e47 Mon Sep 17 00:00:00 2001 From: Eric Evans Date: Fri, 25 Feb 2011 21:38:53 +0000 Subject: [PATCH] CASSANDRA-2025 updated consistency level spec (removed '.') Patch by eevans for CASSANDRA-2025 git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@1074709 13f79535-47bb-0310-9956-ffa450edef68 --- doc/cql/CQL.html | 4 ++-- doc/cql/CQL.textile | 14 +++++++------- src/java/org/apache/cassandra/cql/Cql.g | 8 ++++---- test/system/test_cql.py | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/doc/cql/CQL.html b/doc/cql/CQL.html index 31a3652599..ab455c7341 100644 --- a/doc/cql/CQL.html +++ b/doc/cql/CQL.html @@ -8,7 +8,7 @@ SELECT [FIRST N] [REVERSED] name1..nameN FROM ...

Following the column family clause is an optional consistency level specification.

Filtering rows

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 <=.

Limits

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.

UPDATE

Synopsis:

UPDATE <COLUMN FAMILY> [USING CONSISTENCY.<CL>]
+

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.

UPDATE

Synopsis:

UPDATE <COLUMN FAMILY> [USING CONSISTENCY <CL>]
         SET name1 = value1, name2 = value2 WHERE KEY = keyname;
 

An UPDATE is used to write one or more columns to a record in a Cassandra column family. No results are returned.

Column Family

UPDATE <COLUMN FAMILY> ...
 

Statements begin with the UPDATE keyword followed by a Cassandra column family name.

Consistency Level

UPDATE ... [USING <CONSISTENCY>] ...
@@ -34,4 +34,4 @@ UPDATE ... WHERE KEY IN (keyname1, keyname2)
 

It is possible to assign columns a type during column family creation. Columns configured with a type are validated accordingly when a write occurs. Column types are specified as a parenthesized, comma-separated list of column term and type pairs. The list of recognized types are:

typedescription
bytesArbitrary bytes (no validation)
asciiASCII character string
utf8UTF8 encoded string
timeuuidType 1 UUID
uuidType 4 UUID
int4-byte integer
long8-byte long

Note: In addition to the recognized types listed above, it is also possible to supply a string containing the name of a class (a sub-class of AbstractType), either fully qualified, or relative to the org.apache.cassandra.db.marshal package.

Column Family Options (optional)

CREATE COLUMNFAMILY ... WITH keyword1 = arg1 AND keyword2 = arg2;
 

A number of optional keyword arguments can be supplied to control the configuration of a new column family.

keyworddefaultdescription
comparatorbytesDetermines sorting and validation of column names. Valid values are identical to the types listed in Specifying Column Type above.
commentnoneA free-form, human-readable comment.
row_cache_size0Number of rows whose entire contents to cache in memory.
key_cache_size200000Number of keys per SSTable whose locations are kept in memory in “mostly LRU” order.
read_repair_chance1.0The probability with which read repairs should be invoked on non-quorum reads.
gc_grace_seconds864000Time to wait before garbage collecting tombstones (deletion markers).
default_validationbytesDetermines validation of column values. Valid values are identical to the types listed in Specifying Column Type above.
min_compaction_threshold4Minimum number of SSTables needed to start a minor compaction.
max_compaction_threshold32Maximum number of SSTables allowed before a minor compaction is forced.
row_cache_save_period_in_seconds0Number of seconds between saving row caches.
key_cache_save_period_in_seconds14400Number of seconds between saving key caches.
memtable_flush_after_mins60Maximum time to leave a dirty table unflushed.
memtable_throughput_in_mbdynamicMaximum size of the memtable before it is flushed.
memtable_operations_in_millionsdynamicNumber of operations in millions before the memtable is flushed.
replicate_on_writefalse

CREATE INDEX

Synopsis:

CREATE INDEX [index_name] ON <column_family> (column_name);
 

A CREATE INDEX statement is used to create a new, automatic secondary index for the named column.

Common Idioms

Specifying Consistency

... USING <CONSISTENCY> ...
-

Consistency level specifications are made up the keyword USING, followed by a consistency level identifier. Valid consistency levels are as follows:

Term specification

Where possible, the type of terms are inferred; the following term types are supported:

String Literals

String literals are any value enclosed in double-quotes, (`"`). String literals are treated as raw bytes; no interpolation is performed.

Unicode

Unicode terms are any double-quoted string prefixed with a lower-case u, for example u"© 2011 The Apache Software Foundation". Unicode terms are identical to standard string literals, with the exception that they are encoded to bytes using the UTF-8 charset.

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.

UUIDs

There are two types of UUIDs supported by the CQL specification, time-based (version 1) and randomly generated (version 4). These are specified in statements using the timeuuid(<UUID STRING>) and uuid(<UUID STRING>) notations respectively.

In addition to the hex-based string representation, timeuuid() terms also accept arguments to specify the data-time component. The full list of timeuuid() arguments are:

argumentexamplebehavior
nonetimeuuid()Results in the creation of a new UUID based on system time of the node parsing the query.
nowtimeuuid(“now”)Results in the creation of a new UUID based on system time of the node parsing the query.
milliseconds since epochtimeuuid(1296755320376)Creates a UUID with a time component that is based on the supplied time-stamp.
iso8601 timestamptimeuuid(“2011-02-01T14:00-0600”)Creates a UUID with a time component that is based on the supplied time-stamp.
string representation (hex)timeuuid(“e9229b24-2fbe-11e0-a4de-0026c650d722”)Reproduces the specified version 1 UUID node-side.
\ No newline at end of file +

Consistency level specifications are made up the keyword USING, followed by a consistency level identifier. Valid consistency levels are as follows:

Term specification

Where possible, the type of terms are inferred; the following term types are supported:

String Literals

String literals are any value enclosed in double-quotes, (`"`). String literals are treated as raw bytes; no interpolation is performed.

Unicode

Unicode terms are any double-quoted string prefixed with a lower-case u, for example u"© 2011 The Apache Software Foundation". Unicode terms are identical to standard string literals, with the exception that they are encoded to bytes using the UTF-8 charset.

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.

UUIDs

There are two types of UUIDs supported by the CQL specification, time-based (version 1) and randomly generated (version 4). These are specified in statements using the timeuuid(<UUID STRING>) and uuid(<UUID STRING>) notations respectively.

In addition to the hex-based string representation, timeuuid() terms also accept arguments to specify the data-time component. The full list of timeuuid() arguments are:

argumentexamplebehavior
nonetimeuuid()Results in the creation of a new UUID based on system time of the node parsing the query.
nowtimeuuid(“now”)Results in the creation of a new UUID based on system time of the node parsing the query.
milliseconds since epochtimeuuid(1296755320376)Creates a UUID with a time component that is based on the supplied time-stamp.
iso8601 timestamptimeuuid(“2011-02-01T14:00-0600”)Creates a UUID with a time component that is based on the supplied time-stamp.
string representation (hex)timeuuid(“e9229b24-2fbe-11e0-a4de-0026c650d722”)Reproduces the specified version 1 UUID node-side.
\ No newline at end of file diff --git a/doc/cql/CQL.textile b/doc/cql/CQL.textile index 27bc0ceac6..1277a3171c 100644 --- a/doc/cql/CQL.textile +++ b/doc/cql/CQL.textile @@ -73,7 +73,7 @@ h2. UPDATE _Synopsis:_ bc. -UPDATE [USING CONSISTENCY.] +UPDATE [USING CONSISTENCY ] SET name1 = value1, name2 = value2 WHERE KEY = keyname; An @UPDATE@ is used to write one or more columns to a record in a Cassandra column family. No results are returned. @@ -244,12 +244,12 @@ bc. 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@ +* @CONSISTENCY ZERO@ +* @CONSISTENCY ONE@ (default) +* @CONSISTENCY QUORUM@ +* @CONSISTENCY ALL@ +* @CONSISTENCY DCQUORUM@ +* @CONSISTENCY DCQUORUMSYNC@ h3(#terms). Term specification diff --git a/src/java/org/apache/cassandra/cql/Cql.g b/src/java/org/apache/cassandra/cql/Cql.g index c412e7f6ac..50750472ac 100644 --- a/src/java/org/apache/cassandra/cql/Cql.g +++ b/src/java/org/apache/cassandra/cql/Cql.g @@ -94,7 +94,7 @@ selectStatement returns [SelectStatement expr] | K_COUNT '(' s2=selectExpression ')' { expression = s2; isCountOp = true; } ) K_FROM columnFamily=IDENT - ( K_USING K_CONSISTENCY '.' K_LEVEL { cLevel = ConsistencyLevel.valueOf($K_LEVEL.text); } )? + ( K_USING K_CONSISTENCY K_LEVEL { cLevel = ConsistencyLevel.valueOf($K_LEVEL.text); } )? ( K_WHERE whereClause )? ( K_LIMIT rows=INTEGER { numRecords = Integer.parseInt($rows.text); } )? endStmnt @@ -141,7 +141,7 @@ batchUpdateStatement returns [BatchUpdateStatement expr] ConsistencyLevel cLevel = ConsistencyLevel.ONE; List updates = new ArrayList(); } - K_BEGIN K_BATCH ( K_USING K_CONSISTENCY '.' K_LEVEL { cLevel = ConsistencyLevel.valueOf($K_LEVEL.text); } )? + K_BEGIN K_BATCH ( K_USING K_CONSISTENCY K_LEVEL { cLevel = ConsistencyLevel.valueOf($K_LEVEL.text); } )? u1=updateStatement { updates.add(u1); } ( uN=updateStatement { updates.add(uN); } )* K_APPLY K_BATCH EOF { @@ -166,7 +166,7 @@ updateStatement returns [UpdateStatement expr] Map columns = new HashMap(); } K_UPDATE columnFamily=IDENT - (K_USING K_CONSISTENCY '.' K_LEVEL { cLevel = ConsistencyLevel.valueOf($K_LEVEL.text); })? + (K_USING K_CONSISTENCY K_LEVEL { cLevel = ConsistencyLevel.valueOf($K_LEVEL.text); })? K_SET termPair[columns] (',' termPair[columns])* K_WHERE K_KEY '=' key=term endStmnt { @@ -192,7 +192,7 @@ deleteStatement returns [DeleteStatement expr] } K_DELETE ( cols=termList { columnsList = $cols.items; })? - K_FROM columnFamily=IDENT ( K_USING K_CONSISTENCY '.' K_LEVEL )? + K_FROM columnFamily=IDENT ( K_USING K_CONSISTENCY K_LEVEL )? K_WHERE ( K_KEY '=' key=term { keyList = Collections.singletonList(key); } | K_KEY K_IN '(' keys=termList { keyList = $keys.items; } ')' )? diff --git a/test/system/test_cql.py b/test/system/test_cql.py index e563745962..8f184368cf 100644 --- a/test/system/test_cql.py +++ b/test/system/test_cql.py @@ -34,7 +34,7 @@ def load_sample(dbconn): """) dbconn.execute(""" - BEGIN BATCH USING CONSISTENCY.ONE + BEGIN BATCH USING CONSISTENCY ONE UPDATE StandardLong1 SET 1L="1", 2L="2", 3L="3", 4L="4" WHERE KEY="aa"; UPDATE StandardLong1 SET 5L="5", 6L="6", 7L="8", 9L="9" WHERE KEY="ab"; UPDATE StandardLong1 SET 9L="9", 8L="8", 7L="7", 6L="6" WHERE KEY="ac"; @@ -46,7 +46,7 @@ def load_sample(dbconn): """) dbconn.execute(""" - BEGIN BATCH USING CONSISTENCY.ONE + BEGIN BATCH USING CONSISTENCY ONE UPDATE StandardInteger1 SET 10="a", 20="b", 30="c", 40="d" WHERE KEY="k1"; UPDATE StandardInteger1 SET 10="e", 20="f", 30="g", 40="h" WHERE KEY="k2"; UPDATE StandardInteger1 SET 10="i", 20="j", 30="k", 40="l" WHERE KEY="k3";