我正在研究 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/