I worked on a custom PerRowSecondaryIndex to synchronize data to another system 
and there was no way to know the difference between an insert and an update at 
this level (I'm using Cassandra 2.2). The solution for me was simply to us an 
upsert operation in the target system.

There is also the QueryHandler interface that would allow you to intercept the 
queries, but I found it difficult to use because you have to make you how query 
interpreter.

However, with Cassandra 3.x the Index interface was refactored and you now have 
insert and update methods, you even have the old and new rows in the update!
Check the SASI index implementation: 
https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/index/sasi/SASIIndex.java

If I'm not mistaken the Mutation are only used with thrift and don't have the 
notion of insert or updates with columnFamilies. Currently CQL queries use the 
native protocol: 
https://git-wip-us.apache.org/repos/asf?p=cassandra.git;a=blob_plain;f=doc/native_protocol_v3.spec.
 If you want to stay at protocol level you need to check native protocol 
implementation and how to decode it.


--
Jacques-Henri Berthemet

-----Original Message-----
From: J. D. Jordan [mailto:jeremiah.jor...@gmail.com] 
Sent: mercredi 23 novembre 2016 07:13
To: dev@cassandra.apache.org
Subject: Re: Cassandra Mutation object decoding

You may also want to look at the triggers interface.

> On Nov 22, 2016, at 7:45 PM, Chris Lohfink <chris.lohf...@datastax.com> wrote:
> 
> There are different kinds of tombstones, a partition tombstone is held in
> the MutableDeletionInfo of the PartitionUpdate that you can get from
> deletionInfo() method which returns the private deletionInfo field from the
> holder. There are also row and cell deletions so you have to handle each of
> those. It can be a little non-trivial to work backwards but all the
> information is there in the Mutation (if you have full access to cfmetadata
> etc), may be easier to go directly to whatever output your looking for.
> 
> A lot of the metadata is driven from system though, you need to be either
> be on a Cassandra node or rebuild them with the same cfids. In sstable-tools
> <https://github.com/tolbertam/sstable-tools> we rebuild the tables from the
> source cluster to parse the Mutations for replaying/viewing hints and
> commitlogs. But that had to be a bit (massively) hackier since its for 3.7
> before CASSANDRA-8844 <https://issues.apache.org/jira/browse/CASSANDRA-8844>.
> Its definitely possible but not easy (which is probably why it hasn't been
> added in yet).
> 
> Chris
> 
> On Tue, Nov 22, 2016 at 6:59 PM, Sanal Vasudevan <get2sa...@gmail.com>
> wrote:
> 
>> Hi Bejamin,
>> 
>> Nice to hear from you.
>> 
>> My goal is to reconstruct the CQL operation from the Mutation object.
>> So that I can trigger the same action on another NoSQL target like MongoDB.
>> 
>> Please let me know know if you have ideas?
>> 
>> Many thanks.
>> Sanal
>> 
>> 
>> On Tue, Nov 22, 2016 at 7:28 PM, Benjamin Lerer <
>> benjamin.le...@datastax.com
>>> wrote:
>> 
>>> Hi Sanal,
>>> 
>>> What you want to do is not an easy stuff and it might break with new
>> major
>>> releases.
>>> 
>>> My question would be: why do you want to do that? There might be another
>>> way to reach the same goal.
>>> 
>>> Benjamin
>>> 
>>> On Mon, Nov 21, 2016 at 7:14 PM, Sanal Vasudevan <get2sa...@gmail.com>
>>> wrote:
>>> 
>>>> Thank you Vladimir.
>>>> Anyone else has any other ideas as to how this can be done?
>>>> 
>>>> 
>>>> Many thanks,
>>>> Sanal
>>>> 
>>>> 
>>>> On Sun, Nov 20, 2016 at 4:46 AM, Vladimir Yudovin <
>> vla...@winguzone.com>
>>>> wrote:
>>>> 
>>>>> Hi Sanal,
>>>>> 
>>>>> 
>>>>> 
>>>>> &gt;do we have metadata inside Mutation object to decode whether the
>>> CQL
>>>>> was an INSERT or UPDATE operation?
>>>>> 
>>>>> I'm not sure it's possible to distinguish them - both of them just
>> add
>>>>> data to SSTable.
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> Best regards, Vladimir Yudovin,
>>>>> 
>>>>> Winguzone - Hosted Cloud Cassandra
>>>>> Launch your cluster in minutes.
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> ---- On Fri, 18 Nov 2016 15:55:00 -0500Sanal Vasudevan &
>>>>> lt;get2sa...@gmail.com&gt; wrote ----
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> Hi there,
>>>>> 
>>>>> 
>>>>> 
>>>>> I am trying to read the Commit logs to decode the original CQL which
>>>> used.
>>>>> 
>>>>> I get to the point an implemention of CommitLogReadHandler is able to
>>>> push
>>>>> 
>>>>> back Mutation objects from the Commit logs.
>>>>> 
>>>>> 
>>>>> 
>>>>> Questions:
>>>>> 
>>>>> 1) CQL: delete from myks.mytable where key1 = 1;
>>>>> 
>>>>> For the above CQL, the Mutation object has zero objects of
>>>>> 
>>>>> org.apache.cassandra.db.rows.Row inside ParitionUpdate object.
>>>>> 
>>>>> Is this the only way to detect a DELETE operation? or we have any
>> other
>>>>> 
>>>>> metadata to indicate a DELETE operation?
>>>>> 
>>>>> mutation.getPartitionUpdates().forEach(rows -&gt; {
>>> if(rows.isEmpty())
>>>>> 
>>>>> System.out.println("May be a DELETE operation") });
>>>>> 
>>>>> 2) Likewise do we have metadata inside Mutation object to decode
>>> whether
>>>>> 
>>>>> the CQL was an INSERT or UPDATE operation?
>>>>> 
>>>>> 
>>>>> 
>>>>> Josh Mckenzie indicated that PartitionUpdate.deletionInfo
>>>>> 
>>>>> (MutableDeletionInfo) may have some information but deletionInfo is
>>>>> private.
>>>>> 
>>>>> 
>>>>> 
>>>>> Basically, I am looking for help to find a way to classify Mutation
>>>> object
>>>>> 
>>>>> to INSERT/UPDATE/DELETE with related column and key information.
>>>>> 
>>>>> 
>>>>> 
>>>>> Many thanks.
>>>>> 
>>>>> --
>>>>> 
>>>>> Sanal
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> --
>>>> Sanal Vasudevan Nair
>>>> 
>>> 
>> 
>> 
>> 
>> --
>> Sanal Vasudevan Nair
>> 

Reply via email to