3

I was going through the triggers implementation in cassandra. I wanted to implement triggers so as to update a table with old values of the tables that has been modified. suppose i have a table say test_table in keyspace keyspace1. i also have a table say table_track in the same keyspace with columns columnname and columnvalue. now when a row is updated in test_table, i would like to populate the track_table with row data(in test_table before update query was executed) in to the columns columnname and columnvalue respectively.

i couldn't find any proper documentation regarding cassandra triggers anywhere. i managed to somehow implement InvertedIndex and some minor examples

public Collection<Mutation> augment(ByteBuffer key, ColumnFamily update)
{
    List<Mutation> mutations = new ArrayList<Mutation>(update.getColumnCount());

    for (Cell cell : update)
    {
        // Skip the row marker and other empty values, since they lead to an empty key.
        if (cell.value().remaining() > 0)
        {
            Mutation mutation = new Mutation(properties.getProperty("keyspace"), cell.value());
            mutation.add(properties.getProperty("columnfamily"), cell.name(), key, System.currentTimeMillis());
            mutations.add(mutation);
        }
    }

    return mutations;
}

how can i modify the augment method to implement the functionality. Tnx

1 Answers1

0

You are using wrong key to create Mutation instance
Here is the working code

public Collection<Mutation> augment(ByteBuffer key, ColumnFamily update) 
{    
    List<Mutation> mutations = new ArrayList<Mutation>(update.getColumnCount());

    for (Cell cell : update)
    {
        if (cell.value().remaining() > 0)
        {
            Mutation mutation = new Mutation(properties.getProperty("keyspace"), key);
            mutation.add(properties.getProperty("columnfamily"), cell.name(), cell.value(), System.currentTimeMillis());
            mutations.add(mutation);
        }
   }
   return mutations;
}
Ashraful Islam
  • 12,470
  • 3
  • 32
  • 53