mirror of https://github.com/apache/cassandra
pass IFilter to getRangeRows instead of column names / slicerange. patch by jbellis
git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@950074 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
242b717f3d
commit
d8342a7736
|
|
@ -860,11 +860,10 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
* @param superColumn Super column to filter by
|
||||
* @param range Either a Bounds, which includes start key, or a Range, which does not.
|
||||
* @param maxResults Maximum rows to return
|
||||
* @param sliceRange Information on how to slice columns
|
||||
* @param columnNames Column names to filter by
|
||||
* @param columnFilter description of the columns we're interested in for each row
|
||||
* @return true if we found all keys we were looking for, otherwise false
|
||||
*/
|
||||
private boolean getRangeRows(List<Row> rows, byte[] superColumn, final AbstractBounds range, int maxResults, SliceRange sliceRange, List<byte[]> columnNames)
|
||||
private boolean getRangeRows(List<Row> rows, byte[] superColumn, final AbstractBounds range, int maxResults, IFilter columnFilter)
|
||||
throws ExecutionException, InterruptedException
|
||||
{
|
||||
final DecoratedKey startWith = new DecoratedKey(range.left, (byte[])null);
|
||||
|
|
@ -873,13 +872,8 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
final int gcBefore = CompactionManager.getDefaultGCBefore();
|
||||
|
||||
final QueryPath queryPath = new QueryPath(columnFamily_, superColumn, null);
|
||||
final SortedSet<byte[]> columnNameSet = new TreeSet<byte[]>(getComparator());
|
||||
if (columnNames != null)
|
||||
columnNameSet.addAll(columnNames);
|
||||
|
||||
final QueryFilter filter = sliceRange == null ? QueryFilter.getNamesFilter(null, queryPath, columnNameSet)
|
||||
: QueryFilter.getSliceFilter(null, queryPath, sliceRange.start, sliceRange.finish, sliceRange.bitmasks, sliceRange.reversed, sliceRange.count);
|
||||
|
||||
final QueryFilter filter = new QueryFilter(null, queryPath, columnFilter);
|
||||
Collection<Memtable> memtables = new ArrayList<Memtable>();
|
||||
memtables.add(getMemtableThreadSafe());
|
||||
memtables.addAll(memtablesPendingFlush);
|
||||
|
|
@ -929,30 +923,29 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
* @param super_column
|
||||
* @param range: either a Bounds, which includes start key, or a Range, which does not.
|
||||
* @param keyMax maximum number of keys to process, regardless of startKey/finishKey
|
||||
* @param sliceRange may be null if columnNames is specified. specifies contiguous columns to return in what order.
|
||||
* @param columnNames may be null if sliceRange is specified. specifies which columns to return in what order. @return list of key->list<column> tuples.
|
||||
* @param columnFilter description of the columns we're interested in for each row
|
||||
* @throws ExecutionException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public List<Row> getRangeSlice(byte[] super_column, final AbstractBounds range, int keyMax, SliceRange sliceRange, List<byte[]> columnNames)
|
||||
public List<Row> getRangeSlice(byte[] super_column, final AbstractBounds range, int keyMax, IFilter columnFilter)
|
||||
throws ExecutionException, InterruptedException
|
||||
{
|
||||
List<Row> rows = new ArrayList<Row>();
|
||||
boolean completed;
|
||||
if ((range instanceof Bounds || !((Range)range).isWrapAround()))
|
||||
{
|
||||
completed = getRangeRows(rows, super_column, range, keyMax, sliceRange, columnNames);
|
||||
completed = getRangeRows(rows, super_column, range, keyMax, columnFilter);
|
||||
}
|
||||
else
|
||||
{
|
||||
// wrapped range
|
||||
Token min = StorageService.getPartitioner().getMinimumToken();
|
||||
Range first = new Range(range.left, min);
|
||||
completed = getRangeRows(rows, super_column, first, keyMax, sliceRange, columnNames);
|
||||
completed = getRangeRows(rows, super_column, first, keyMax, columnFilter);
|
||||
if (!completed && min.compareTo(range.right) < 0)
|
||||
{
|
||||
Range second = new Range(min, range.right);
|
||||
getRangeRows(rows, super_column, second, keyMax, sliceRange, columnNames);
|
||||
getRangeRows(rows, super_column, second, keyMax, columnFilter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1033,8 +1026,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
List<Row> result;
|
||||
try
|
||||
{
|
||||
SliceRange range = new SliceRange(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, false, ROWS);
|
||||
result = getRangeSlice(null, new Bounds(start, min), ROWS, range, null);
|
||||
result = getRangeSlice(null, new Bounds(start, min), ROWS, new IdentityQueryFilter());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import org.apache.cassandra.io.util.FileDataInput;
|
|||
* takes care of putting the two together if subcolumn filtering needs to be done, based on the
|
||||
* querypath that it knows (but that IFilter implementations are oblivious to).
|
||||
*/
|
||||
interface IFilter
|
||||
public interface IFilter
|
||||
{
|
||||
/**
|
||||
* returns an iterator that returns columns from the given memtable
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import org.apache.commons.lang.ArrayUtils;
|
|||
|
||||
import org.apache.cassandra.db.SuperColumn;
|
||||
|
||||
class IdentityQueryFilter extends SliceQueryFilter
|
||||
public class IdentityQueryFilter extends SliceQueryFilter
|
||||
{
|
||||
/**
|
||||
* Only for use in testing; will read entire CF into memory.
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ import java.util.*;
|
|||
|
||||
import org.apache.cassandra.io.sstable.SSTableReader;
|
||||
import org.apache.cassandra.io.util.FileDataInput;
|
||||
import org.apache.cassandra.thrift.SlicePredicate;
|
||||
import org.apache.cassandra.thrift.SliceRange;
|
||||
import org.apache.cassandra.utils.ReducingIterator;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
|
@ -37,7 +39,7 @@ public class QueryFilter
|
|||
private final IFilter filter;
|
||||
private final IFilter superFilter;
|
||||
|
||||
protected QueryFilter(DecoratedKey key, QueryPath path, IFilter filter)
|
||||
public QueryFilter(DecoratedKey key, QueryPath path, IFilter filter)
|
||||
{
|
||||
this.key = key;
|
||||
this.path = path;
|
||||
|
|
@ -178,6 +180,19 @@ public class QueryFilter
|
|||
return new QueryFilter(key, path, new NamesQueryFilter(columns));
|
||||
}
|
||||
|
||||
public static IFilter getFilter(SlicePredicate predicate, AbstractType comparator)
|
||||
{
|
||||
if (predicate.column_names != null)
|
||||
{
|
||||
final SortedSet<byte[]> columnNameSet = new TreeSet<byte[]>(comparator);
|
||||
columnNameSet.addAll(predicate.column_names);
|
||||
return new NamesQueryFilter(columnNameSet);
|
||||
}
|
||||
|
||||
SliceRange range = predicate.slice_range;
|
||||
return new SliceQueryFilter(range.start, range.finish, range.bitmasks, range.reversed, range.count);
|
||||
}
|
||||
|
||||
/**
|
||||
* convenience method for creating a name filter matching a single column
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.apache.cassandra.db.ColumnFamilyStore;
|
|||
import org.apache.cassandra.db.RangeSliceCommand;
|
||||
import org.apache.cassandra.db.RangeSliceReply;
|
||||
import org.apache.cassandra.db.Table;
|
||||
import org.apache.cassandra.db.filter.QueryFilter;
|
||||
import org.apache.cassandra.net.IVerbHandler;
|
||||
import org.apache.cassandra.net.Message;
|
||||
import org.apache.cassandra.net.MessagingService;
|
||||
|
|
@ -42,8 +43,7 @@ public class RangeSliceVerbHandler implements IVerbHandler
|
|||
RangeSliceReply reply = new RangeSliceReply(cfs.getRangeSlice(command.super_column,
|
||||
command.range,
|
||||
command.max_keys,
|
||||
command.predicate.slice_range,
|
||||
command.predicate.column_names));
|
||||
QueryFilter.getFilter(command.predicate, cfs.getComparator())));
|
||||
Message response = reply.getReply(message);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Sending " + reply+ " to " + message.getMessageId() + "@" + message.getFrom());
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.nio.ByteBuffer;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.apache.cassandra.db.filter.IdentityQueryFilter;
|
||||
import org.apache.cassandra.db.filter.QueryFilter;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
|
|
@ -73,8 +74,7 @@ public class Util
|
|||
return cfs.getRangeSlice(null,
|
||||
new Bounds(min, min),
|
||||
10000,
|
||||
new SliceRange(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, false, 10000),
|
||||
null);
|
||||
new IdentityQueryFilter());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -141,8 +141,7 @@ public class ColumnFamilyStoreTest extends CleanupHelper
|
|||
List<Row> result = cfs.getRangeSlice(ArrayUtils.EMPTY_BYTE_ARRAY,
|
||||
Util.range(p, "key15", "key1"),
|
||||
10,
|
||||
null,
|
||||
Arrays.asList("asdf".getBytes()));
|
||||
new NamesQueryFilter("asdf".getBytes()));
|
||||
assertEquals(2, result.size());
|
||||
}
|
||||
|
||||
|
|
@ -155,8 +154,7 @@ public class ColumnFamilyStoreTest extends CleanupHelper
|
|||
List<Row> result = cfs.getRangeSlice(ArrayUtils.EMPTY_BYTE_ARRAY,
|
||||
Util.range(p, "key1", "key2"),
|
||||
10,
|
||||
null,
|
||||
Arrays.asList("asdf".getBytes()));
|
||||
new NamesQueryFilter("asdf".getBytes()));
|
||||
assertEquals(1, result.size());
|
||||
assert Arrays.equals(result.get(0).key.key, "key2".getBytes());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue