Reputation: 7585
I am going from SQL to NoSQL with Cassandra.
I've read Do You Really Need SQL to Do It All in Cassandra?. That speaks about sql select, join, group by and order by, but there is nothing about the "id" concept in sql data base. In SQL, all values have an unique identifier.
Is there something like that with nosql/cassandra? What? Is it safe to do something like newId = lastId + 1
or something like that with Cassandra and how?
Thanks.
Upvotes: 2
Views: 204
Reputation: 20192
If you are going from SQL to noSQL, another option to consider is playOrm
It does Scalable JQL like so (notice the addition of partitions but other than that, SQL is the same)
@NoSqlQuery(name="findJoinOnNullPartition", query="PARTITIONS p(:partId) select p FROM TABLE as p INNER JOIN p.security as s where s.securityType = :type and p.numShares = :shares"),
Also, it will generate unique cluster keys for you as well so you don't always need to deal with key generation ;). An example of playOrm's key generation is here(which is unique within one cluster)...
Upvotes: 0
Reputation: 6172
IDs doesn't exist in Cassandra. It is a simple key / value store you need to provide you with your own document IDs (called keys). The suggested approach is to use UUIDs, which are designed to avoid conflicting keys.
Doing something like newId = lastId + 1
is not safe at all. Cassandra doesn't, by design, support transactions, and no way to make read + write atomic. Concurrent transactions can make this fail:
If you're interested, Cassandra Counters addresses this issue.
Upvotes: 1