Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra Java Driver: How are insert, update, and delete results reported?

I am writing an application and I need to be able to tell if an inserts and updates succeed. I am using "INSERT ... IF NOT EXISTS" to get the light weight transaction behavior and noticed that the result set returned from execute, contains a row with updated data and an "[applied]" column that can be queried. That is great. But I have an update statement that is returning an empty ResultSet. It appears as though the update is succeeding but I want an programatic way to verify that.

To Clarify:

I have turned on some logging of the result sets returned by my mutations. I have found that "INSERT...IF NOT EXIST"s returns a ResultSet with a boolean column named "[applied]". If "[applied]" is false, it also returns the row that already exits.

With UPDATE, I always see an empty ResultSet.

So I have two questions:

  1. Where is the documentation on what the ResultSet should contain for each type of mutation? I did not see it in the CQL docs or in the Java Driver docs. I even tried looking at other language integrations' docs and did not find any description of the ResultSet contents for mutations.
  2. Is there any way to find out how many rows were modified by an UPDATE or deleted by a DELETE?
like image 331
AlphaGeek Avatar asked Jan 15 '14 20:01

AlphaGeek


People also ask

What is Upsert in Cassandra?

Upsert means that Cassandra will insert a row if a primary key does not exist already otherwise if primary key already exists, it will update that row.

How to connect Cassandra db using Java?

In order to connect to Cassandra from Java, we need to build a Cluster object. An address of a node needs to be provided as a contact point. If we don't provide a port number, the default port (9042) will be used. These settings allow the driver to discover the current topology of a cluster.

Does Cassandra support GROUP by?

Conclusion. The tutorial has just illustrated about using Group By in Apache Cassandra. Currently, Apache Cassandra 3.10 only supports group by with Partition Key or Partition Key and Clustering Key.


1 Answers

Even I am stuck with the same issue . One thing (a bad hack though) I discovered is if the update or insert fails the column definitions in the result set are more than one and if mutations succeeds the column definition contain only one column i.e "applied" . The problem is ResultSet does not contain the value of "applied" column which is "true" in case the mutation succeeds and "false" when the transactions prevent changing the data . I am using this hack as of now in my application but I don't think its a good solution , so even Im looking for a better solution.

like image 114
Rohan Avatar answered Sep 19 '22 20:09

Rohan