Cassandra - unique constraint on row key
Unfortunately, no, because Cassandra does not perform any checks on writes. In order to implement something like that, Cassandra would have to do a read before every write, to check whether the write is allowed. This would greatly slow down writes. (The whole point is that writes are streamed out sequentially without needing to do any disk seeks -- reads interrupt this pattern and force seeks to occur.)
I can't think of a way that counters would help, either. Counters are not implemented using an atomic test-and-set. Instead, they essentially store lots of deltas, which are added together when you read the counter value.
Lightweight transactions?
http://www.datastax.com/documentation/cassandra/2.0/cassandra/dml/dml_ltwt_transaction_c.html
INSERT INTO customer_account (customerID, customer_email)
VALUES (‘LauraS’, ‘[email protected]’)
IF NOT EXISTS;
Cassandra - a unique constraint can be implemented with the help of a primary key constrain. You need to put all the columns as primary key, those you want to be unique. Cassandra will tackle the rest on it own.
CREATE TABLE users (firstname text, lastname text, age int,
email text, city text, PRIMARY KEY (firstname, lastname));
It means Cassandra will not insert two different rows in this users
table when firstname
and lastname
are the same.