ekaterinadimitrova2 commented on code in PR #3095:
URL: https://github.com/apache/cassandra/pull/3095#discussion_r1544910089
##########
src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java:
##########
@@ -827,83 +768,7 @@ private ByteBuffer getPartitionKeyBound(Bound b,
QueryOptions options)
*/
public AbstractBounds<PartitionPosition>
getPartitionKeyBounds(QueryOptions options)
{
- IPartitioner p = table.partitioner;
-
- if (partitionKeyRestrictions.isOnToken())
- {
- return getPartitionKeyBoundsForTokenRestrictions(p, options);
- }
-
- return getPartitionKeyBounds(p, options);
- }
-
- private AbstractBounds<PartitionPosition>
getPartitionKeyBounds(IPartitioner p,
-
QueryOptions options)
- {
- // Deal with unrestricted partition key components (special-casing is
required to deal with 2i queries on the
- // first component of a composite partition key) queries that filter
on the partition key.
- if (partitionKeyRestrictions.needFiltering(table))
- return new Range<>(p.getMinimumToken().minKeyBound(),
p.getMinimumToken().maxKeyBound());
-
- ByteBuffer startKeyBytes = getPartitionKeyBound(Bound.START, options);
- ByteBuffer finishKeyBytes = getPartitionKeyBound(Bound.END, options);
-
- PartitionPosition startKey =
PartitionPosition.ForKey.get(startKeyBytes, p);
- PartitionPosition finishKey =
PartitionPosition.ForKey.get(finishKeyBytes, p);
-
- if (startKey.compareTo(finishKey) > 0 && !finishKey.isMinimum())
- return null;
-
- if (partitionKeyRestrictions.isInclusive(Bound.START))
- {
- return partitionKeyRestrictions.isInclusive(Bound.END)
- ? new Bounds<>(startKey, finishKey)
- : new IncludingExcludingBounds<>(startKey, finishKey);
- }
-
- return partitionKeyRestrictions.isInclusive(Bound.END)
- ? new Range<>(startKey, finishKey)
- : new ExcludingBounds<>(startKey, finishKey);
- }
-
- private AbstractBounds<PartitionPosition>
getPartitionKeyBoundsForTokenRestrictions(IPartitioner p,
-
QueryOptions options)
- {
- Token startToken = getTokenBound(Bound.START, options, p);
- Token endToken = getTokenBound(Bound.END, options, p);
-
- boolean includeStart =
partitionKeyRestrictions.isInclusive(Bound.START);
- boolean includeEnd = partitionKeyRestrictions.isInclusive(Bound.END);
-
- /*
- * If we ask SP.getRangeSlice() for (token(200), token(200)], it will
happily return the whole ring.
- * However, wrapping range doesn't really make sense for CQL, and we
want to return an empty result in that
- * case (CASSANDRA-5573). So special case to create a range that is
guaranteed to be empty.
- *
- * In practice, we want to return an empty result set if either
startToken > endToken, or both are equal but
- * one of the bound is excluded (since [a, a] can contains something,
but not (a, a], [a, a) or (a, a)).
- * Note though that in the case where startToken or endToken is the
minimum token, then this special case
- * rule should not apply.
- */
- int cmp = startToken.compareTo(endToken);
- if (!startToken.isMinimum() && !endToken.isMinimum()
- && (cmp > 0 || (cmp == 0 && (!includeStart || !includeEnd))))
- return null;
-
- PartitionPosition start = includeStart ? startToken.minKeyBound() :
startToken.maxKeyBound();
- PartitionPosition end = includeEnd ? endToken.maxKeyBound() :
endToken.minKeyBound();
-
- return new Range<>(start, end);
- }
-
- private Token getTokenBound(Bound b, QueryOptions options, IPartitioner p)
- {
- if (!partitionKeyRestrictions.hasBound(b))
- return p.getMinimumToken();
-
- ByteBuffer value = partitionKeyRestrictions.bounds(b, options).get(0);
- checkNotNull(value, "Invalid null token value");
Review Comment:
Are we still checking that the token is valid? Wasn't that part of the
reason why we did not use directly the range functions before?
--
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]