bereng commented on code in PR #3095:
URL: https://github.com/apache/cassandra/pull/3095#discussion_r1551346985
##########
src/java/org/apache/cassandra/cql3/restrictions/PartitionKeyRestrictions.java:
##########
@@ -18,52 +18,355 @@
package org.apache.cassandra.cql3.restrictions;
import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.*;
-import org.apache.cassandra.schema.TableMetadata;
+import com.google.common.collect.BoundType;
+import com.google.common.collect.ImmutableRangeSet;
+import com.google.common.collect.Range;
+import com.google.common.collect.RangeSet;
+import com.google.common.collect.TreeRangeSet;
+
+import org.apache.cassandra.cql3.functions.Function;
+import org.apache.cassandra.db.PartitionPosition;
+import org.apache.cassandra.db.guardrails.Guardrails;
+import org.apache.cassandra.dht.AbstractBounds;
+import org.apache.cassandra.dht.Bounds;
+import org.apache.cassandra.dht.IPartitioner;
+import org.apache.cassandra.dht.Token;
+import org.apache.cassandra.dht.Token.TokenFactory;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.schema.ColumnMetadata;
import org.apache.cassandra.cql3.QueryOptions;
-import org.apache.cassandra.cql3.statements.Bound;
+import org.apache.cassandra.db.ClusteringComparator;
+import org.apache.cassandra.db.ClusteringPrefix;
+import org.apache.cassandra.db.MultiCBuilder;
import org.apache.cassandra.service.ClientState;
/**
* A set of restrictions on the partition key.
*
*/
-interface PartitionKeyRestrictions extends Restrictions
+final class PartitionKeyRestrictions extends RestrictionSetWrapper
{
- public PartitionKeyRestrictions mergeWith(Restriction restriction);
+ /**
+ * The composite type.
+ */
+ private final ClusteringComparator comparator;
+
+ /**
+ * The token restrictions or {@code null} if there are no restritions on
tokens.
+ */
+ private final SingleRestriction tokenRestrictions;
+
+
+ @Override
+ public boolean isOnToken()
+ {
+ // if all partition key columns have non-token restrictions and do not
need filtering,
+ // we can simply use the token range to filter those restrictions and
then ignore the token range
+ return tokenRestrictions != null && (restrictions.isEmpty() ||
needFiltering());
+ }
+
+ public PartitionKeyRestrictions(ClusteringComparator comparator)
+ {
+ super(RestrictionSet.empty());
+ this.comparator = comparator;
+ this.tokenRestrictions = null;
+ }
+
+ private PartitionKeyRestrictions(PartitionKeyRestrictions pkRestrictions,
+ SingleRestriction restriction)
+ {
+ super(restriction.isOnToken() ? pkRestrictions.restrictions
+ :
pkRestrictions.restrictions.addRestriction(restriction));
+ this.comparator = pkRestrictions.comparator;
+ this.tokenRestrictions = restriction.isOnToken() ?
pkRestrictions.tokenRestrictions == null ? restriction
+
: pkRestrictions.tokenRestrictions.mergeWith(restriction)
+ :
pkRestrictions.tokenRestrictions;
+ }
+
+ public PartitionKeyRestrictions mergeWith(Restriction restriction)
+ {
+ return new PartitionKeyRestrictions(this, (SingleRestriction)
restriction);
+ }
+
+ @Override
+ public void addFunctionsTo(List<Function> functions)
+ {
+ if (tokenRestrictions != null)
+ tokenRestrictions.addFunctionsTo(functions);
+ super.addFunctionsTo(functions);
+ }
+
+ /**
+ * Returns the partitions selected by this set of restrictions
+ *
+ * @param partitioner the partitioner
+ * @param options the query options
+ * @param state the client state
+ * @return the partitions selected by this set of restrictions
+ */
+ public List<ByteBuffer> values(IPartitioner partitioner, QueryOptions
options, ClientState state)
+ {
+ // if we need to perform filtering its means that this query is a
partition range query and that
+ // this method should not be called
+ if (isEmpty() || needFiltering())
+ throw new IllegalStateException("the query is a partition range
query and this method should not be called");
+
+ List<ByteBuffer> nonTokenRestrictionValues =
nonTokenRestrictionValues(options, state);
- public List<ByteBuffer> values(QueryOptions options, ClientState state);
+ if (tokenRestrictions == null)
+ return nonTokenRestrictionValues;
- public List<ByteBuffer> bounds(Bound b, QueryOptions options);
+ return filter(partitioner, nonTokenRestrictionValues, options);
+ }
/**
- * Checks if the specified bound is set or not.
- * @param b the bound type
- * @return <code>true</code> if the specified bound is set,
<code>false</code> otherwise
+ * Returns the range of partitions selected by this set of restrictions
+ *
+ * @param partitioner the partitioner
+ * @param options the query options
+ * @return the range of partitions selected by this set of restrictions
*/
- public boolean hasBound(Bound b);
+ public AbstractBounds<PartitionPosition> bounds(IPartitioner partitioner,
QueryOptions options)
+ {
+ if (tokenRestrictions != null && (restrictions.isEmpty() ||
needFiltering()))
Review Comment:
isOnToken()?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]