You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by vi...@apache.org on 2013/07/12 06:37:51 UTC
git commit: Add trigger examples patch by Vijay;
reviewed by jbellis for CASSANDRA-5574
Updated Branches:
refs/heads/trunk b320cd9cd -> 829688f9e
Add trigger examples
patch by Vijay; reviewed by jbellis for CASSANDRA-5574
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/829688f9
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/829688f9
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/829688f9
Branch: refs/heads/trunk
Commit: 829688f9ebf941f90d2168fcfaa8b9385eb14318
Parents: b320cd9
Author: Vijay Parthasarathy <vi...@gmail.com>
Authored: Thu Jul 11 21:36:30 2013 -0700
Committer: Vijay Parthasarathy <vi...@gmail.com>
Committed: Thu Jul 11 21:36:30 2013 -0700
----------------------------------------------------------------------
examples/triggers/README.txt | 21 ++++++++++
examples/triggers/build.xml | 40 ++++++++++++++++++
examples/triggers/conf/InvertedIndex.properties | 2 +
.../cassandra/triggers/InvertedIndex.java | 43 ++++++++++++++++++++
4 files changed, 106 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/829688f9/examples/triggers/README.txt
----------------------------------------------------------------------
diff --git a/examples/triggers/README.txt b/examples/triggers/README.txt
new file mode 100644
index 0000000..974d29c
--- /dev/null
+++ b/examples/triggers/README.txt
@@ -0,0 +1,21 @@
+Cassandra Trigger's Example:
+=========================
+
+InvertedIndex class will create a inverted index of
+RowKey:ColumnName:Value to Value:ColumnName:RowKey
+
+NOTE: This example is limited to append-only workloads,
+ doesn't delete indexes on deletes.
+
+Installation:
+============
+change directory to <cassandra_src_dir>/examples/triggers
+run "ant jar"
+Copy build/trigger-example.jar to <cassandra_home>/triggers/
+Copy conf/* to <cassandra_home>/conf/
+Create column family configured in InvertedIndex.properties
+ Example: Keyspace1.InvertedIndex as configured in InvertedIndex.properties
+Configure trigger on the table.
+ Example: CREATE TRIGGER test1 ON "Keyspace1"."Standard1"
+ EXECUTE ('org.apache.cassandra.triggers.InvertedIndex');
+Start inserting data to the column family which has the triggers.
http://git-wip-us.apache.org/repos/asf/cassandra/blob/829688f9/examples/triggers/build.xml
----------------------------------------------------------------------
diff --git a/examples/triggers/build.xml b/examples/triggers/build.xml
new file mode 100644
index 0000000..55fccce
--- /dev/null
+++ b/examples/triggers/build.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project default="jar" name="trigger-example">
+ <property name="cassandra.dir" value="../.." />
+ <property name="cassandra.dir.lib" value="${cassandra.dir}/lib" />
+ <property name="cassandra.classes" value="${cassandra.dir}/build/classes/main" />
+ <property name="build.src" value="${basedir}/src" />
+ <property name="build.dir" value="${basedir}/build" />
+ <property name="build.classes" value="${build.dir}/classes" />
+ <property name="final.name" value="trigger-example" />
+
+ <path id="build.classpath">
+ <fileset dir="${cassandra.dir.lib}">
+ <include name="**/*.jar" />
+ </fileset>
+ <fileset dir="${cassandra.dir}/build/lib/jars">
+ <include name="**/*.jar" />
+ </fileset>
+ <pathelement location="${cassandra.classes}" />
+ </path>
+ <target name="init">
+ <mkdir dir="${build.classes}" />
+ </target>
+
+ <target name="build" depends="init">
+ <javac destdir="${build.classes}" debug="true" includeantruntime="false">
+ <src path="${build.src}" />
+ <classpath refid="build.classpath" />
+ </javac>
+ </target>
+
+ <target name="jar" depends="build">
+ <jar jarfile="${build.dir}/${final.name}.jar">
+ <fileset dir="${build.classes}" />
+ </jar>
+ </target>
+
+ <target name="clean">
+ <delete dir="${build.dir}" />
+ </target>
+</project>
http://git-wip-us.apache.org/repos/asf/cassandra/blob/829688f9/examples/triggers/conf/InvertedIndex.properties
----------------------------------------------------------------------
diff --git a/examples/triggers/conf/InvertedIndex.properties b/examples/triggers/conf/InvertedIndex.properties
new file mode 100644
index 0000000..6db6d61
--- /dev/null
+++ b/examples/triggers/conf/InvertedIndex.properties
@@ -0,0 +1,2 @@
+keyspace=Keyspace1
+columnfamily=InvertedIndex
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cassandra/blob/829688f9/examples/triggers/src/org/apache/cassandra/triggers/InvertedIndex.java
----------------------------------------------------------------------
diff --git a/examples/triggers/src/org/apache/cassandra/triggers/InvertedIndex.java b/examples/triggers/src/org/apache/cassandra/triggers/InvertedIndex.java
new file mode 100644
index 0000000..6eb0cbd
--- /dev/null
+++ b/examples/triggers/src/org/apache/cassandra/triggers/InvertedIndex.java
@@ -0,0 +1,43 @@
+package org.apache.cassandra.triggers;
+
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.cassandra.db.ColumnFamily;
+import org.apache.cassandra.db.RowMutation;
+import org.apache.cassandra.io.util.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InvertedIndex implements ITrigger {
+ private static final Logger logger = LoggerFactory.getLogger(InvertedIndex.class);
+ private Properties properties = loadProperties();
+
+ public Collection<RowMutation> augment(ByteBuffer key, ColumnFamily update) {
+ List<RowMutation> mutations = new ArrayList<RowMutation>();
+ for (ByteBuffer name : update.getColumnNames()) {
+ RowMutation mutation = new RowMutation(properties.getProperty("keyspace"), update.getColumn(name).value());
+ mutation.add(properties.getProperty("columnfamily"), name, key, System.currentTimeMillis());
+ mutations.add(mutation);
+ }
+ return mutations;
+ }
+
+ private static Properties loadProperties() {
+ Properties properties = new Properties();
+ InputStream stream = InvertedIndex.class.getClassLoader().getResourceAsStream("InvertedIndex.properties");
+ try {
+ properties.load(stream);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ FileUtils.closeQuietly(stream);
+ }
+ logger.info("loaded property file, InvertedIndex.properties");
+ return properties;
+ }
+}