Add boolean as literals in CQL3 patch by slebresne and iamaleksey; reviewed by jbellis for CASSANDRA-4776
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/ff817cf6 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ff817cf6 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ff817cf6 Branch: refs/heads/trunk Commit: ff817cf633cfd38f4ddff7d51c86511e73d5d338 Parents: 10777f2 Author: Sylvain Lebresne <[email protected]> Authored: Thu Oct 25 17:55:58 2012 +0200 Committer: Sylvain Lebresne <[email protected]> Committed: Thu Oct 25 17:57:30 2012 +0200 ---------------------------------------------------------------------- CHANGES.txt | 1 + pylib/cqlshlib/cql3handling.py | 6 ++++++ src/java/org/apache/cassandra/cql3/Cql.g | 7 +++++-- src/java/org/apache/cassandra/cql3/Term.java | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/ff817cf6/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index e067d9c..8325a93 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -36,6 +36,7 @@ * Fix Subcolumn slice ends not respected (CASSANDRA-4826) * Fix Assertion error in cql3 select (CASSANDRA-4783) * Fix list prepend logic (CQL3) (CASSANDRA-4835) + * Add booleans as literals in CQL3 (CASSANDRA-4776) Merged from 1.1: * fix get_paged_slice to wrap to next row correctly (CASSANDRA-4816) * fix indexing empty column values (CASSANDRA-4832) http://git-wip-us.apache.org/repos/asf/cassandra/blob/ff817cf6/pylib/cqlshlib/cql3handling.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index 8e0d987..089b2b9 100644 --- a/pylib/cqlshlib/cql3handling.py +++ b/pylib/cqlshlib/cql3handling.py @@ -208,6 +208,9 @@ JUNK ::= /([ \t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ; <brackets> ::= /[][{}]/ ; <integer> ::= "-"? <wholenumber> ; +<boolean> ::= "true" + | "false" + ; <unclosedString> ::= /'([^']|'')*/ ; <unclosedName> ::= /"([^"]|"")*/ ; @@ -217,6 +220,7 @@ JUNK ::= /([ \t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ; | <integer> | <float> | <uuid> + | <boolean> ; <tokenDefinition> ::= token="TOKEN" "(" <term> ( "," <term> )* ")" @@ -841,6 +845,8 @@ def insert_newval_completer(ctxt, cass): return ['{'] if coltype == 'list': return ['['] + if coltype == 'boolean': + return ['true', 'false'] return [Hint('<value for %s (%s)>' % (maybe_escape_name(curcol), cqltype.cql_parameterized_type()))] http://git-wip-us.apache.org/repos/asf/cassandra/blob/ff817cf6/src/java/org/apache/cassandra/cql3/Cql.g ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g index 76f2509..0f7668e 100644 --- a/src/java/org/apache/cassandra/cql3/Cql.g +++ b/src/java/org/apache/cassandra/cql3/Cql.g @@ -578,7 +578,7 @@ map_literal returns [Map<Term, Term> value] ; term returns [Term term] - : t=(STRING_LITERAL | UUID | INTEGER | FLOAT ) { $term = new Term($t.text, $t.type); } + : t=(STRING_LITERAL | UUID | INTEGER | FLOAT | K_TRUE | K_FALSE ) { $term = new Term($t.text, $t.type); } | t=QMARK { $term = new Term($t.text, $t.type, ++currentBindMarkerIdx); } ; @@ -641,7 +641,7 @@ property[PropertyDefinitions props] ; propertyValue returns [String str] - : v=(STRING_LITERAL | IDENT | INTEGER | FLOAT) { $str = $v.text; } + : v=(STRING_LITERAL | IDENT | INTEGER | FLOAT | K_TRUE | K_FALSE) { $str = $v.text; } | u=unreserved_keyword { $str = u; } ; @@ -823,6 +823,9 @@ K_WRITETIME: W R I T E T I M E; K_MAP: M A P; K_LIST: L I S T; +K_TRUE: T R U E; +K_FALSE: F A L S E; + // Case-insensitive alpha characters fragment A: ('a'|'A'); fragment B: ('b'|'B'); http://git-wip-us.apache.org/repos/asf/cassandra/blob/ff817cf6/src/java/org/apache/cassandra/cql3/Term.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/Term.java b/src/java/org/apache/cassandra/cql3/Term.java index 6eaba14..cfea259 100644 --- a/src/java/org/apache/cassandra/cql3/Term.java +++ b/src/java/org/apache/cassandra/cql3/Term.java @@ -30,7 +30,7 @@ public class Term { public enum Type { - STRING, INTEGER, UUID, FLOAT, QMARK; + STRING, INTEGER, UUID, FLOAT, BOOLEAN, QMARK; static Type forInt(int type) { @@ -42,6 +42,8 @@ public class Term return UUID; else if (type == CqlParser.FLOAT) return FLOAT; + else if (type == CqlParser.K_TRUE || type == CqlParser.K_FALSE) + return BOOLEAN; else if (type == CqlParser.QMARK) return QMARK;
