gpt4 book ai didi

java - 在 cassandra 中使用触发器

转载 作者:搜寻专家 更新时间:2023-10-31 19:55:43 24 4
gpt4 key购买 nike

我尝试使用示例 https://github.com/apache/cassandra/tree/trunk/examples/triggers

我寻求帮助并编写了自己的触发器。但是我通过 UnsortedColumns.getColumn(UnsortedColumns.java:105) 得到 UnsupportedOperationException。这是网络上唯一活跃的例子。此示例弃用了其他人。我该如何解决这个问题?

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.cassandra.db.ColumnFamily;
import org.apache.cassandra.db.RowMutation;
import org.apache.cassandra.triggers.ITrigger;

public class FirstTrigger implements ITrigger {

@Override
public Collection<RowMutation> augment(ByteBuffer key, ColumnFamily update) {
List<RowMutation> mutations = new ArrayList<RowMutation>();
for (ByteBuffer name : update.getColumnNames()) {
RowMutation mutation = new RowMutation("mykeyspace", update.getColumn(name).value());
mutation.add("trigger_log", name, key, System.currentTimeMillis());
mutations.add(mutation);
}
return mutations;
}

}

存储日志事件的模式是:

use mykeyspace;   
create table if not exists TRIGGER_LOG (
transaction_id int,
log varchar,
PRIMARY KEY (transaction_id));

我的错误是

ERROR [Thrift:1] 2013-10-28 03:53:53,120 ProcessFunction.java (line 41) Internal error processing execute_prepared_cql3_query
java.lang.RuntimeException: Exception while creating trigger on CF with ID: 08f73f2f-c4c4-3a23-b2ae-3fdc92559012
at org.apache.cassandra.triggers.TriggerExecutor.execute(TriggerExecutor.java:131)
at org.apache.cassandra.triggers.TriggerExecutor.execute(TriggerExecutor.java:73)
at org.apache.cassandra.service.StorageProxy.mutateWithTriggers(StorageProxy.java:535)
at org.apache.cassandra.cql3.statements.ModificationStatement.executeWithoutCondition(ModificationStatement.java:360)
at org.apache.cassandra.cql3.statements.ModificationStatement.execute(ModificationStatement.java:344)
at org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:101)
at org.apache.cassandra.cql3.QueryProcessor.processPrepared(QueryProcessor.java:235)
at org.apache.cassandra.thrift.CassandraServer.execute_prepared_cql3_query(CassandraServer.java:2045)
at org.apache.cassandra.thrift.Cassandra$Processor$execute_prepared_cql3_query.getResult(Cassandra.java:4480)
at org.apache.cassandra.thrift.Cassandra$Processor$execute_prepared_cql3_query.getResult(Cassandra.java:4464)
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
at org.apache.cassandra.thrift.CustomTThreadPoolServer$WorkerProcess.run(CustomTThreadPoolServer.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsupportedOperationException
at org.apache.cassandra.db.UnsortedColumns.getColumn(UnsortedColumns.java:105)
at com.symantec.paranoid.trigger.FirstTrigger.augment(FirstTrigger.java:18)
at org.apache.cassandra.triggers.TriggerExecutor.execute(TriggerExecutor.java:123)
... 15 more

最佳答案

不是迭代单元格名称,而是迭代单元格本身。

for (Column cell : update)
{
// stuff
}

该示例已更正。

关于java - 在 cassandra 中使用触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19633090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com