例を使用してみました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