mirror of https://github.com/apache/cassandra
add test of KeyRange.filter
patch by jbellis; reviewed by brandonwilliams for CASSANDRA-2878
This commit is contained in:
parent
e31879e595
commit
ee5dbdb8d3
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue