Hi Angelo, Thank you so much for your advice.
Shame on me. I didn't realize that error was from the set. It works now. Sorry for having such a stupid question. On Wed, Sep 29, 2021 at 3:19 PM Angelo Polo <language.de...@gmail.com> wrote: > Hi Yu-Wei, > > Collections#emptySet returns an immutable Set, so it should be > mutations.add(mutation); > that's throwing the UnsupportedOperationException rather than anything > related to C*. > > If you're going to add something to a set later, use the regular > constructor. Most likely HashSet: > new HashSet<>(); > > Best, > Angelo > > On Wed, Sep 29, 2021 at 3:48 AM Yu-Wei Su <plenty...@scalar-labs.com> > wrote: > >> Hi, >> >> I am thinking of using the Cassandra trigger to delete or update data >> right after they are inserted. >> >> First, I tried deleting the data. >> >> This is my table. >> >> ``` >> CREATE TABLE mykeyspace.mytable ( >> mycolumn text PRIMARY KEY >> ) >> ``` >> >> and this is my trigger >> >> ``` >> public class MyTrigger implements ITrigger { >> public Collection<Mutation> augment(Partition partition) { >> Collection<Mutation> mutations = Collections.emptySet(); >> >> PartitionUpdate.SimpleBuilder partitionUpdateBuilder = Mutation >> .simpleBuilder(partition.metadata().ksName, >> partition.partitionKey()) >> .update(partition.metadata()); >> >> Row.SimpleBuilder rowBuilder = >> partitionUpdateBuilder.row(Clustering.EMPTY); >> >> rowBuilder.delete(); >> >> Mutation mutation = partitionUpdateBuilder.buildAsMutation(); >> >> mutations.add(mutation); >> >> return mutations; >> } >> } >> ``` >> >> then, I got this error message (/var/log/cassandra/system.log) at >> run-time. >> >> >> ``` >> ERROR [Native-Transport-Requests-1] 2021-09-28 06:49:12,748 >> ErrorMessage.java:384 - Unexpected exception during request >> java.lang.RuntimeException: Exception while executing trigger on table >> with ID: 27a4dfa0-2028-11ec-a91c-6d2c86545d91 >> at >> org.apache.cassandra.triggers.TriggerExecutor.executeInternal(TriggerExecutor.java:246) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> at >> org.apache.cassandra.triggers.TriggerExecutor.execute(TriggerExecutor.java:124) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> at >> org.apache.cassandra.service.StorageProxy.mutateWithTriggers(StorageProxy.java:957) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> at >> org.apache.cassandra.cql3.statements.ModificationStatement.executeWithoutCondition(ModificationStatement.java:435) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> at >> org.apache.cassandra.cql3.statements.ModificationStatement.execute(ModificationStatement.java:421) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> at >> org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:225) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> at >> org.apache.cassandra.cql3.QueryProcessor.processPrepared(QueryProcessor.java:532) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> at >> org.apache.cassandra.cql3.QueryProcessor.processPrepared(QueryProcessor.java:509) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> at >> org.apache.cassandra.transport.messages.ExecuteMessage.execute(ExecuteMessage.java:146) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> at >> org.apache.cassandra.transport.Message$Dispatcher.processRequest(Message.java:687) >> [apache-cassandra-3.11.11.jar:3.11.11] >> at >> org.apache.cassandra.transport.Message$Dispatcher.lambda$channelRead0$0(Message.java:593) >> [apache-cassandra-3.11.11.jar:3.11.11] >> at >> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) >> ~[na:1.8.0_302] >> at >> org.apache.cassandra.concurrent.AbstractLocalAwareExecutorService$FutureTask.run(AbstractLocalAwareExecutorService.java:162) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> at >> org.apache.cassandra.concurrent.SEPWorker.run(SEPWorker.java:113) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_302] >> Caused by: java.lang.UnsupportedOperationException: null >> at java.util.AbstractCollection.add(AbstractCollection.java:262) >> ~[na:1.8.0_302] >> at MyTrigger.augment(MyTrigger.java:26) ~[na:na] >> at >> org.apache.cassandra.triggers.TriggerExecutor.executeInternal(TriggerExecutor.java:234) >> ~[apache-cassandra-3.11.11.jar:3.11.11] >> ... 14 common frames omitted >> ``` >> >> I guess I made a mistake in my trigger implementation. >> Not sure if it is the correct way to do that. >> >> Could you give me some advice? >> >> Thank you. >> >