You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ty...@apache.org on 2015/02/04 18:24:17 UTC
cassandra git commit: Add support for UPDATE ... IF EXISTS
Repository: cassandra
Updated Branches:
refs/heads/cassandra-2.0 2d8bddb06 -> 0f5ab577b
Add support for UPDATE ... IF EXISTS
Patch by Prajakta Bhosale; reviewed by Tyler Hobbs for CASSANDRA-8610
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/0f5ab577
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/0f5ab577
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/0f5ab577
Branch: refs/heads/cassandra-2.0
Commit: 0f5ab577bcc106aa487dd5b05ca0b991c9a96a04
Parents: 2d8bddb
Author: Prajakta Bhosale <pr...@yahoo.co.in>
Authored: Wed Feb 4 11:23:41 2015 -0600
Committer: Tyler Hobbs <ty...@datastax.com>
Committed: Wed Feb 4 11:23:41 2015 -0600
----------------------------------------------------------------------
CHANGES.txt | 1 +
pylib/cqlshlib/cql3handling.py | 2 +-
pylib/cqlshlib/helptopics.py | 3 ++-
src/java/org/apache/cassandra/cql3/Cql.g | 6 ++++--
.../apache/cassandra/cql3/statements/UpdateStatement.java | 8 +++++---
5 files changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/0f5ab577/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 375dcfe..f4c96dc 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
2.0.13:
+ * Add support for UPDATE ... IF EXISTS (CASSANDRA-8610)
* Fix reversal of list prepends (CASSANDRA-8733)
* Prevent non-zero default_time_to_live on tables with counters
(CASSANDRA-8678)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/0f5ab577/pylib/cqlshlib/cql3handling.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py
index 0b7863c..9e9b6ad 100644
--- a/pylib/cqlshlib/cql3handling.py
+++ b/pylib/cqlshlib/cql3handling.py
@@ -15,7 +15,6 @@
# limitations under the License.
import re
-from warnings import warn
from .cqlhandling import CqlParsingRuleSet, Hint
from cql.cqltypes import (cql_types, lookup_casstype, CompositeType, UTF8Type,
ColumnToCollectionType, CounterColumnType, DateType)
@@ -715,6 +714,7 @@ syntax_rules += r'''
( "AND" [updateopt]=<usingOption> )* )?
"SET" <assignment> ( "," <assignment> )*
"WHERE" <whereClause>
+ ( "IF" "EXISTS" )?
;
<assignment> ::= updatecol=<cident>
( "=" update_rhs=( <value> | <cident> )
http://git-wip-us.apache.org/repos/asf/cassandra/blob/0f5ab577/pylib/cqlshlib/helptopics.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/helptopics.py b/pylib/cqlshlib/helptopics.py
index 2af8db2..0b08726 100644
--- a/pylib/cqlshlib/helptopics.py
+++ b/pylib/cqlshlib/helptopics.py
@@ -563,7 +563,8 @@ class CQL3HelpTopics(CQLHelpTopics):
UPDATE [<keyspace>.]<columnFamily>
[USING [TIMESTAMP <timestamp>]
[AND TTL <timeToLive>]]
- SET name1 = value1, name2 = value2 WHERE <keycol> = keyval;
+ SET name1 = value1, name2 = value2 WHERE <keycol> = keyval
+ [IF EXISTS];
An UPDATE is used to write one or more columns to a record in a table.
No results are returned. The record's primary key must be completely
http://git-wip-us.apache.org/repos/asf/cassandra/blob/0f5ab577/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 a80746c..0595c25 100644
--- a/src/java/org/apache/cassandra/cql3/Cql.g
+++ b/src/java/org/apache/cassandra/cql3/Cql.g
@@ -360,18 +360,20 @@ updateStatement returns [UpdateStatement.ParsedUpdate expr]
@init {
Attributes.Raw attrs = new Attributes.Raw();
List<Pair<ColumnIdentifier.Raw, Operation.RawUpdate>> operations = new ArrayList<Pair<ColumnIdentifier.Raw, Operation.RawUpdate>>();
+ boolean ifExists = false;
}
: K_UPDATE cf=columnFamilyName
( usingClause[attrs] )?
K_SET columnOperation[operations] (',' columnOperation[operations])*
K_WHERE wclause=whereClause
- ( K_IF conditions=updateConditions )?
+ ( K_IF ( K_EXISTS { ifExists = true; } | conditions=updateConditions ))?
{
return new UpdateStatement.ParsedUpdate(cf,
attrs,
operations,
wclause,
- conditions == null ? Collections.<Pair<ColumnIdentifier.Raw, ColumnCondition.Raw>>emptyList() : conditions);
+ conditions == null ? Collections.<Pair<ColumnIdentifier.Raw, ColumnCondition.Raw>>emptyList() : conditions,
+ ifExists);
}
;
http://git-wip-us.apache.org/repos/asf/cassandra/blob/0f5ab577/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java b/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
index 9d98c84..594b5db 100644
--- a/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
@@ -207,14 +207,16 @@ public class UpdateStatement extends ModificationStatement
* @param attrs additional attributes for statement (timestamp, timeToLive)
* @param updates a map of column operations to perform
* @param whereClause the where clause
- */
+ * @param ifExists flag to check if row exists
+ * */
public ParsedUpdate(CFName name,
Attributes.Raw attrs,
List<Pair<ColumnIdentifier.Raw, Operation.RawUpdate>> updates,
List<Relation> whereClause,
- List<Pair<ColumnIdentifier.Raw, ColumnCondition.Raw>> conditions)
+ List<Pair<ColumnIdentifier.Raw, ColumnCondition.Raw>> conditions,
+ boolean ifExists)
{
- super(name, attrs, conditions, false, false);
+ super(name, attrs, conditions, false, ifExists);
this.updates = updates;
this.whereClause = whereClause;
}