Skip to content

Commit

Permalink
(CQL) fix for counter decrement syntax
Browse files Browse the repository at this point in the history
patch by Pavel Yaskevich; reviewed by Jonathan Ellis for CASSANDRA-3418

git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-1.0@1200943 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
xedin committed Nov 11, 2011
1 parent b1b1772 commit 3d8eec9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions src/java/org/apache/cassandra/cql/Cql.g
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/java/org/apache/cassandra/cql/UpdateStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private IMutation mutationForKey(String keyspace, ByteBuffer key, CFMetaData met

if (op.type == OperationType.MINUS)
{
value *= -1;
if (value > 0) value *= -1;
}
}
catch (NumberFormatException e)
Expand Down

0 comments on commit 3d8eec9

Please sign in to comment.