title: How to implement trigger in Cassandra?
body: <p>Is there any good example or guide on how to implement a Cassandra trigger step-by-step?</p>
  
  <p>I'm looking for something advanced, like manipulating other rows in same partition after an INSERT or UPDATE is performed.</p>
  
  <p>Unfortunately the documentation is very limited, I only found these links so far:</p>
  
  <ul>
  <li><a href="http://cassandra.apache.org/doc/latest/cql/triggers.html" rel="nofollow noreferrer">Official documentation</a></li>
  <li><a href="https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlCreateTrigger.html" rel="nofollow noreferrer">Documentation at DataStax</a></li>
  <li><a href="https://github.com/apache/cassandra/blob/trunk/examples/triggers/src/org/apache/cassandra/triggers/AuditTrigger.java" rel="nofollow noreferrer">Example
  implementation in official repo</a></li>
  </ul>
  
  <h1>Example</h1>
  
  <p>Let's say you want to put logs into a table and aggregate them whenever you reach a certain number of log entries.</p>
  
  <pre><code>CREATE TABLE simple_log (
      id int,
      event_id timeuuid,
      message text,
      PRIMARY KEY(id)
  );
  
  INSERT INTO simple_log (id, event_id, message) VALUES (1, now(), 'first');
  INSERT INTO simple_log (id, event_id, message)  VALUES (1, now(), 'second');
  INSERT INTO simple_log (id, event_id, message)  VALUES (1, now(), 'third');
  </code></pre>
  
  <p>Whenever you select top the logs by ID, you should get back an aggregated result:</p>
  
  <pre><code>SELECT * FROM simple_log WHERE id = 1;
  
   id | event_id                             | message
  ----+--------------------------------------+---------
    1 | d97f92d1-b5a4-11e7-825c-495e6ea8608a |   first-second-third
  </code></pre>