java - Cassandra 在更新另一个表时触发更新另一个表

标签 java triggers cassandra cassandra-2.1

我正在研究 cassandra 中的触发器实现。 我想实现触发器,以便使用已修改的表的旧值更新表。 假设我在键空间 keyspace1 中有一个表 test_table。 我在同一键空间中还有一个表 table_track,其中包含列名和列值。 现在,当在 test_table 中更新一行时,我想将行数据(在执行更新查询之前在 test_table 中)分别填充到 track_table 的列名和列值中。

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

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

最佳答案

您使用了错误的 key 来创建 Mutation 实例
这是工作代码

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

关于java - Cassandra 在更新另一个表时触发更新另一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32866697/

相关文章:

PostgreSQL 触发器 : switch from after to before the trigger dont fire

python - Cassandra:如何获得总表大小/估计行数

sql - 如何判断触发器代码是否正在复制订阅服务器上执行?

service - 本地计算机上的 Datastax cassandra 社区服务器 2.1.10 服务启动然后停止

Cassandra - 选择而不复制

java - map 并发修改问题

java - 将此 if-then-else 语句替换为单个 return 语句

java - 在 Spring Reactive 中自定义 ErrorAttributeOptions 的问题

java - 如何使用 eXist-db 2.2 XMLDB 嵌入的 java API 设置 UID

postgresql - 触发器中的多个过程调用?