Cassandra Sample Trigger Code to get inserted value

cassandra, java, triggers

Solution

To get 'id' and 'data_key' you'll have to split the key (ByteBuffer key, the first argument to augment). 'time' will be in the first part of cell.name() - you'd still need to split it. 'data' will be the cell.value(), no need to do any splitting.

Problem

I need your help on extract column names and values in the trigger augment method. Table Def : ``` create table dy_data ( id timeuuid, data_key text, time timestamp, data text,primary key((id,data_key),time) ) with clustering order by (time desc); ``` Trigger Code : ``` public class ArchiveTrigger implements ITrigger { public Collection<RowMutation> augment(ByteBuffer key, ColumnFamily cf) { try { // Below loop only has 2 columns ( one is "data" and another one may be "time" but i am not sure, because i cannot get value. for (Column cell : cf) { //Got Exception if I try to get column name String name = ByteBufferUtil.string(cell.name()); //Got only "data" column value and empty value for another column may be "time". If I try ByteBufferUtil.toLong(cell.value()) it throws exception String value = ByteBufferUtil.string(cell.value()); log(" name = " + name); log(" value = " + value); } } catch (Exception e) { logger.warn("Exception ", e); } return null; } } ``` I tried my best to search sample code in google. But failed. Please help me with sample code. Thanks in advance.

Original source