【问题标题】:Cassandra triggers for updating a table when another is updatedCassandra 触发器用于在更新另一个表时更新一个表
【发布时间】:2015-12-28 06:36:03
【问题描述】:

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

我在任何地方都找不到有关 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;
}

如何修改增强方法来实现功能。 天呐

【问题讨论】:

    标签: java triggers cassandra cassandra-2.1


    【解决方案1】:

    您使用了错误的密钥来创建 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-15
      • 2022-01-15
      • 2015-05-28
      • 2011-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多