Package org.apache.cassandra.db.filter
Class RowFilter
- java.lang.Object
-
- org.apache.cassandra.db.filter.RowFilter
-
- All Implemented Interfaces:
java.lang.Iterable<RowFilter.Expression>
public abstract class RowFilter extends java.lang.Object implements java.lang.Iterable<RowFilter.Expression>
A filter on which rows a given query should include or exclude.This corresponds to the restrictions on rows that are not handled by the query
ClusteringIndexFilter. Some of the expressions of this filter may be handled by a 2ndary index, and the rest is simply filtered out from the result set (the later can only happen if the query was using ALLOW FILTERING).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRowFilter.CustomExpressionA custom index expression for use with 2i implementations which support custom syntax and which are not necessarily linked to a single column in the base table.static classRowFilter.Expressionstatic classRowFilter.Serializerstatic classRowFilter.SimpleExpressionAn expression of the form 'column' 'op' 'value'.static classRowFilter.UserExpressionA user defined filtering expression.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<RowFilter.Expression>expressionsstatic RowFilterNONEstatic RowFilter.Serializerserializer
-
Constructor Summary
Constructors Modifier Constructor Description protectedRowFilter(java.util.List<RowFilter.Expression> expressions)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description RowFilter.SimpleExpressionadd(ColumnMetadata def, Operator op, java.nio.ByteBuffer value)voidaddCustomIndexExpression(TableMetadata metadata, IndexMetadata targetIndex, java.nio.ByteBuffer value)voidaddMapEquality(ColumnMetadata def, java.nio.ByteBuffer key, Operator op, java.nio.ByteBuffer value)voidaddUserExpression(RowFilter.UserExpression e)booleanclusteringKeyRestrictionsAreSatisfiedBy(Clustering<?> clustering)Returns true if all of the expressions within this filter that apply to the clustering key are satisfied by the given Clustering, false otherwise.static RowFiltercreate()static RowFiltercreate(int capacity)PartitionIteratorfilter(PartitionIterator iter, TableMetadata metadata, int nowInSec)Filters the provided iterator so that only the row satisfying the expression of this filter are included in the resulting iterator.UnfilteredPartitionIteratorfilter(UnfilteredPartitionIterator iter, int nowInSec)Filters the provided iterator so that only the row satisfying the expression of this filter are included in the resulting iterator.protected abstract Transformation<BaseRowIterator<?>>filter(TableMetadata metadata, int nowInSec)java.util.List<RowFilter.Expression>getExpressions()booleanhasExpressionOnClusteringOrRegularColumns()Checks if some of the expressions apply to clustering or regular columns.booleanisEmpty()booleanisSatisfiedBy(TableMetadata metadata, DecoratedKey partitionKey, Row row, int nowInSec)Whether the provided row in the provided partition satisfies this filter.java.util.Iterator<RowFilter.Expression>iterator()booleanpartitionKeyRestrictionsAreSatisfiedBy(DecoratedKey key, AbstractType<?> keyValidator)Returns true if all of the expressions within this filter that apply to the partition key are satisfied by the given key, false otherwise.java.lang.StringtoCQLString()Returns a CQL representation of this row filter.java.lang.StringtoString()protected abstract RowFilterwithNewExpressions(java.util.List<RowFilter.Expression> expressions)RowFilterwithout(RowFilter.Expression expression)Returns this filter but without the provided expression.RowFilterwithout(ColumnMetadata column, Operator op, java.nio.ByteBuffer value)Returns a copy of this filter but without the provided expression.RowFilterwithoutExpressions()
-
-
-
Field Detail
-
serializer
public static final RowFilter.Serializer serializer
-
NONE
public static final RowFilter NONE
-
expressions
protected final java.util.List<RowFilter.Expression> expressions
-
-
Constructor Detail
-
RowFilter
protected RowFilter(java.util.List<RowFilter.Expression> expressions)
-
-
Method Detail
-
create
public static RowFilter create()
-
create
public static RowFilter create(int capacity)
-
add
public RowFilter.SimpleExpression add(ColumnMetadata def, Operator op, java.nio.ByteBuffer value)
-
addMapEquality
public void addMapEquality(ColumnMetadata def, java.nio.ByteBuffer key, Operator op, java.nio.ByteBuffer value)
-
addCustomIndexExpression
public void addCustomIndexExpression(TableMetadata metadata, IndexMetadata targetIndex, java.nio.ByteBuffer value)
-
addUserExpression
public void addUserExpression(RowFilter.UserExpression e)
-
getExpressions
public java.util.List<RowFilter.Expression> getExpressions()
-
hasExpressionOnClusteringOrRegularColumns
public boolean hasExpressionOnClusteringOrRegularColumns()
Checks if some of the expressions apply to clustering or regular columns.- Returns:
trueif some of the expressions apply to clustering or regular columns,falseotherwise.
-
filter
protected abstract Transformation<BaseRowIterator<?>> filter(TableMetadata metadata, int nowInSec)
-
filter
public UnfilteredPartitionIterator filter(UnfilteredPartitionIterator iter, int nowInSec)
Filters the provided iterator so that only the row satisfying the expression of this filter are included in the resulting iterator.- Parameters:
iter- the iterator to filternowInSec- the time of query in seconds.- Returns:
- the filtered iterator.
-
filter
public PartitionIterator filter(PartitionIterator iter, TableMetadata metadata, int nowInSec)
Filters the provided iterator so that only the row satisfying the expression of this filter are included in the resulting iterator.- Parameters:
iter- the iterator to filternowInSec- the time of query in seconds.- Returns:
- the filtered iterator.
-
isSatisfiedBy
public boolean isSatisfiedBy(TableMetadata metadata, DecoratedKey partitionKey, Row row, int nowInSec)
Whether the provided row in the provided partition satisfies this filter.- Parameters:
metadata- the table metadata.partitionKey- the partition key for partition to test.row- the row to test.nowInSec- the current time in seconds (to know what is live and what isn't).- Returns:
trueifrowin partitionpartitionKeysatisfies this row filter.
-
partitionKeyRestrictionsAreSatisfiedBy
public boolean partitionKeyRestrictionsAreSatisfiedBy(DecoratedKey key, AbstractType<?> keyValidator)
Returns true if all of the expressions within this filter that apply to the partition key are satisfied by the given key, false otherwise.
-
clusteringKeyRestrictionsAreSatisfiedBy
public boolean clusteringKeyRestrictionsAreSatisfiedBy(Clustering<?> clustering)
Returns true if all of the expressions within this filter that apply to the clustering key are satisfied by the given Clustering, false otherwise.
-
without
public RowFilter without(RowFilter.Expression expression)
Returns this filter but without the provided expression. This method *assumes* that the filter contains the provided expression.
-
without
public RowFilter without(ColumnMetadata column, Operator op, java.nio.ByteBuffer value)
Returns a copy of this filter but without the provided expression. If this filter doesn't contain the specified expression this method will just return an identical copy of this filter.
-
withoutExpressions
public RowFilter withoutExpressions()
-
withNewExpressions
protected abstract RowFilter withNewExpressions(java.util.List<RowFilter.Expression> expressions)
-
isEmpty
public boolean isEmpty()
-
iterator
public java.util.Iterator<RowFilter.Expression> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<RowFilter.Expression>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toCQLString
public java.lang.String toCQLString()
Returns a CQL representation of this row filter.- Returns:
- a CQL representation of this row filter
-
-