add test of KeyRange.filter patch by jbellis; reviewed by brandonwilliams for CASSANDRA-2878
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/ee5dbdb8 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ee5dbdb8 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ee5dbdb8 Branch: refs/heads/trunk Commit: ee5dbdb8d355bd1fa5de535fdbebbfcb7344810b Parents: e31879e Author: Jonathan Ellis <[email protected]> Authored: Fri Jan 20 17:54:07 2012 -0600 Committer: Jonathan Ellis <[email protected]> Committed: Mon Jan 23 16:02:52 2012 -0600 ---------------------------------------------------------------------- examples/hadoop_word_count/src/WordCount.java | 10 +++-- examples/hadoop_word_count/src/WordCountSetup.java | 27 +++++++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/ee5dbdb8/examples/hadoop_word_count/src/WordCount.java ---------------------------------------------------------------------- diff --git a/examples/hadoop_word_count/src/WordCount.java b/examples/hadoop_word_count/src/WordCount.java index 6c203d7..e4bd631 100644 --- a/examples/hadoop_word_count/src/WordCount.java +++ b/examples/hadoop_word_count/src/WordCount.java @@ -20,9 +20,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.*; -import org.apache.cassandra.thrift.Column; -import org.apache.cassandra.thrift.ColumnOrSuperColumn; -import org.apache.cassandra.thrift.Mutation; +import org.apache.cassandra.thrift.*; import org.apache.cassandra.hadoop.ColumnFamilyOutputFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,7 +30,6 @@ import static com.google.common.base.Charsets.UTF_8; import org.apache.cassandra.db.IColumn; import org.apache.cassandra.hadoop.ColumnFamilyInputFormat; import org.apache.cassandra.hadoop.ConfigHelper; -import org.apache.cassandra.thrift.SlicePredicate; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; @@ -197,6 +194,11 @@ public class WordCount extends Configured implements Tool ConfigHelper.setInputColumnFamily(job.getConfiguration(), KEYSPACE, COLUMN_FAMILY); SlicePredicate predicate = new SlicePredicate().setColumn_names(Arrays.asList(ByteBufferUtil.bytes(columnName))); ConfigHelper.setInputSlicePredicate(job.getConfiguration(), predicate); + if (i == 4) + { + IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("int4"), IndexOperator.EQ, ByteBufferUtil.bytes(0)); + ConfigHelper.setInputRange(job.getConfiguration(), Arrays.asList(expr)); + } job.waitForCompletion(true); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/ee5dbdb8/examples/hadoop_word_count/src/WordCountSetup.java ---------------------------------------------------------------------- diff --git a/examples/hadoop_word_count/src/WordCountSetup.java b/examples/hadoop_word_count/src/WordCountSetup.java index 0139ea4..66476aa 100644 --- a/examples/hadoop_word_count/src/WordCountSetup.java +++ b/examples/hadoop_word_count/src/WordCountSetup.java @@ -36,7 +36,7 @@ public class WordCountSetup { private static final Logger logger = LoggerFactory.getLogger(WordCountSetup.class); - public static final int TEST_COUNT = 4; + public static final int TEST_COUNT = 5; public static void main(String[] args) throws Exception { @@ -82,6 +82,25 @@ public class WordCountSetup client.batch_mutate(mutationMap, ConsistencyLevel.ONE); logger.info("added text3"); + // text4: 1000 rows, 1 word, one column to filter on + mutationMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>(); + for (int i = 0; i < 1000; i++) + { + Column c1 = new Column() + .setName(ByteBufferUtil.bytes("text4")) + .setValue(ByteBufferUtil.bytes("word1")) + .setTimestamp(System.currentTimeMillis()); + Column c2 = new Column() + .setName(ByteBufferUtil.bytes("int4")) + .setValue(ByteBufferUtil.bytes(i % 4)) + .setTimestamp(System.currentTimeMillis()); + ByteBuffer key = ByteBufferUtil.bytes("key" + i); + addToMutationMap(mutationMap, key, WordCount.COLUMN_FAMILY, c1); + addToMutationMap(mutationMap, key, WordCount.COLUMN_FAMILY, c2); + } + client.batch_mutate(mutationMap, ConsistencyLevel.ONE); + logger.info("added text4"); + // sentence data for the counters final ByteBuffer key = ByteBufferUtil.bytes("key-if-verse1"); final ColumnParent colParent = new ColumnParent(WordCountCounters.COUNTER_COLUMN_FAMILY); @@ -134,7 +153,11 @@ public class WordCountSetup List<CfDef> cfDefList = new ArrayList<CfDef>(); CfDef input = new CfDef(WordCount.KEYSPACE, WordCount.COLUMN_FAMILY); input.setComparator_type("AsciiType"); - input.setDefault_validation_class("AsciiType"); + input.setColumn_metadata(Arrays.asList(new ColumnDef(ByteBufferUtil.bytes("text1"), "AsciiType"), + new ColumnDef(ByteBufferUtil.bytes("text2"), "AsciiType"), + new ColumnDef(ByteBufferUtil.bytes("text3"), "AsciiType"), + new ColumnDef(ByteBufferUtil.bytes("text4"), "AsciiType"), + new ColumnDef(ByteBufferUtil.bytes("int4"), "Int32Type").setIndex_name("int4idx").setIndex_type(IndexType.KEYS))); cfDefList.add(input); CfDef output = new CfDef(WordCount.KEYSPACE, WordCount.OUTPUT_COLUMN_FAMILY);
