当另一个更新时,Cassandra触发更新表 [英] Cassandra triggers for updating a table when another is updated

查看:310
本文介绍了当另一个更新时,Cassandra触发更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过cassandra中的触发器实现。
我想实现触发器,以便用已修改的表的旧值更新表。
假设我有一个表说test_table在keyspace keyspace1。
我也有一个表说table_track在相同的keyspace与列columnname和columnvalue。
现在当一个行在test_table中更新时,我想填充track_table行数据(在执行更新查询之前的test_table)到columnname和columnvalue。

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.

我找不到任何关于cassandra触发器的任何正确的文档。
我设法以某种方式实现InvertedIndex和一些小例子

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;
}

如何修改扩充方法以实现该功能。
Tnx

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

推荐答案

您使用错误的键来创建Mutation实例_工作代码

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;
}

这篇关于当另一个更新时,Cassandra触发更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆