CQL for Cassandra 2.1

CREATE TRIGGER

Registers a trigger on a table.

Registers a trigger on a table.

Synopsis

CREATE TRIGGER IF NOT EXISTS trigger_name ON table_name
USING 'java_class'

Synopsis Legend

  • Uppercase means literal
  • Lowercase means not literal
  • Italics mean optional
  • The pipe (|) symbol means OR or AND/OR
  • Ellipsis (...) means repeatable
  • Orange ( and ) means not literal, indicates scope

A semicolon that terminates CQL statements is not included in the synopsis.

Description

The implementation of triggers includes the capability to register a trigger on a table using the familiar CREATE TRIGGER syntax. This implementation is experimental.
CREATE TRIGGER myTrigger
  ON myTable
  USING 'org.apache.cassandra.triggers.InvertedIndex'

In Cassandra 2.1, you need to enclose trigger names that use uppercase characters in single quotation marks. The logic comprising the trigger can be written in any Java (JVM) language and exists outside the database. The Java class in this example that implements the trigger is named org.apache.cassandra.triggers and defined in an Apache repository. The trigger defined on a table fires before a requested DML statement occurs to ensures the atomicity of the transaction.

Place the custom trigger code (JAR) in the triggers directory on every node. The custom JAR loads at startup. The location of triggers directory depends on the installation:
  • Cassandra 2.0.x tarball: install_location/lib/triggers
  • Cassandra 2.1.x tarball: install_location/conf/triggers
  • Datastax Enterprise 4.5 and later: Installer-No Services and tarball: install_location/resources/cassandra/conf/triggers
  • Datastax Enterprise 4.5 and later: Installer-Services and packages: /etc/dse/cassandra/triggers

Cassandra 2.1.1 and later supports lightweight transactions for creating a trigger. Attempting to create an existing trigger returns an error unless the IF NOT EXISTS option is used. If the option is used, the statement is a no-op if the table already exists.

Loading Search