cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xe...@apache.org
Subject svn commit: r1200943 - in /cassandra/branches/cassandra-1.0: CHANGES.txt src/java/org/apache/cassandra/cql/Cql.g src/java/org/apache/cassandra/cql/UpdateStatement.java
Date Fri, 11 Nov 2011 16:48:14 GMT
Author: xedin
Date: Fri Nov 11 16:48:14 2011
New Revision: 1200943

URL: http://svn.apache.org/viewvc?rev=1200943&view=rev
Log:
(CQL) fix for counter decrement syntax
patch by Pavel Yaskevich; reviewed by Jonathan Ellis for CASSANDRA-3418

Modified:
    cassandra/branches/cassandra-1.0/CHANGES.txt
    cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cql/Cql.g
    cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cql/UpdateStatement.java

Modified: cassandra/branches/cassandra-1.0/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/CHANGES.txt?rev=1200943&r1=1200942&r2=1200943&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/CHANGES.txt (original)
+++ cassandra/branches/cassandra-1.0/CHANGES.txt Fri Nov 11 16:48:14 2011
@@ -9,6 +9,7 @@
  * add sstable forward-compatibility (CASSANDRA-3478)
  * report compression ratio in CFSMBean (CASSANDRA-3393)
  * fix incorrect size exception during streaming of counters (CASSANDRA-3481)
+ * (CQL) fix for counter decrement syntax (CASSANDRA-3418)
 Merged from 0.8:
  * Make counter shard merging thread safe (CASSANDRA-3178)
  * fix updating CF row_cache_provider (CASSANDRA-3414)

Modified: cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cql/Cql.g
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cql/Cql.g?rev=1200943&r1=1200942&r2=1200943&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cql/Cql.g (original)
+++ cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cql/Cql.g Fri Nov 11 16:48:14
2011
@@ -59,6 +59,13 @@ options {
         if (recognitionErrors.size() > 0)
             throw new InvalidRequestException(recognitionErrors.get((recognitionErrors.size()-1)));
     }
+
+    // used by UPDATE of the counter columns to validate if '-' was supplied by user
+    public void validateMinusSupplied(Object op, final Term value, IntStream stream) throws
MissingTokenException
+    {
+        if (op == null && Long.parseLong(value.getText()) > 0)
+            throw new MissingTokenException(102, stream, value);
+    }
 }
 
 @lexer::header {
@@ -454,10 +461,16 @@ termPair[Map<Term, Term> columns]
     :   key=term '=' value=term { columns.put(key, value); }
     ;
 
+intTerm returns [Term integer]
+    : t=INTEGER { $integer = new Term($t.text, $t.type); }
+    ;
+
 termPairWithOperation[Map<Term, Operation> columns]
     : key=term '=' (value=term { columns.put(key, new Operation(value)); }
-		    | c=term ( '+' v=term { columns.put(key, new Operation(c, org.apache.cassandra.cql.Operation.OperationType.PLUS,
v)); }
-                            | '-' v=term { columns.put(key, new Operation(c, org.apache.cassandra.cql.Operation.OperationType.MINUS,
v)); } ))
+		               | c=term ( '+'  v=term { columns.put(key, new Operation(c, org.apache.cassandra.cql.Operation.OperationType.PLUS,
v)); }
+                            | op='-'? v=intTerm
+                                  { validateMinusSupplied(op, v, input);
+                                    columns.put(key, new Operation(c, org.apache.cassandra.cql.Operation.OperationType.MINUS,
v)); } ))
     ;
 
 // Note: ranges are inclusive so >= and >, and < and <= all have the same semantics.
 

Modified: cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cql/UpdateStatement.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cql/UpdateStatement.java?rev=1200943&r1=1200942&r2=1200943&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cql/UpdateStatement.java
(original)
+++ cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cql/UpdateStatement.java
Fri Nov 11 16:48:14 2011
@@ -220,7 +220,7 @@ public class UpdateStatement extends Abs
 
                     if (op.type == OperationType.MINUS)
                     {
-                        value *= -1;
+                        if (value > 0) value *= -1;
                     }
                 }
                 catch (NumberFormatException e)



Mime
View raw message