Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Fix partition directed queries using dummy column syntax in skinny ta…
Browse files Browse the repository at this point in the history
…bles
  • Loading branch information
adelapena committed Aug 26, 2016
1 parent fbe580f commit 0b34b75
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Allow associativity in search-time geospatial transformations
* Simplify naming of builder static methods for creating geospatial transformations
* Fix paged index-sorted queries matching more than 65535 rows
* Fix partition directed queries using dummy column syntax in skinny tables

## 3.0.8.1 (August 02, 2016)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,6 @@ private Optional<Query> query(ReadCommand command) {
*/
abstract Optional<Query> query(DataRange dataRange);

/**
* Returns a Lucene {@link Query} to retrieve all the rows in the specified partition range.
*
* @param start the lower accepted partition position, {@code null} means no lower limit
* @param stop the upper accepted partition position, {@code null} means no upper limit
* @return the query to retrieve all the rows in the specified range
*/
Optional<Query> query(PartitionPosition start, PartitionPosition stop) {
return tokenMapper.query(start, stop);
}

private Query after(IndexPagingState pagingState, ReadCommand command) {
try {
if (pagingState != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

import java.util.*;

import static org.apache.cassandra.db.PartitionPosition.Kind.*;

/**
* {@link IndexService} for skinny rows.
*
Expand Down Expand Up @@ -106,9 +108,15 @@ public Query query(DecoratedKey key, ClusteringIndexFilter filter) {
/** {@inheritDoc} */
@Override
public Optional<Query> query(DataRange dataRange) {
PartitionPosition startPosition = dataRange.startKey();
PartitionPosition stopPosition = dataRange.stopKey();
return query(startPosition, stopPosition);
PartitionPosition start = dataRange.startKey();
PartitionPosition stop = dataRange.stopKey();
if (start.kind() == ROW_KEY && stop.kind() == ROW_KEY && start.equals(stop)) {
return Optional.of(partitionMapper.query((DecoratedKey) start));
}
return tokenMapper.query(start.getToken(),
stop.getToken(),
start.kind() == MIN_BOUND,
stop.kind() == MAX_BOUND);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import static org.apache.cassandra.db.PartitionPosition.Kind.MAX_BOUND;
import static org.apache.cassandra.db.PartitionPosition.Kind.MIN_BOUND;
import static org.apache.cassandra.db.PartitionPosition.Kind.ROW_KEY;
import static org.apache.lucene.search.BooleanClause.Occur.SHOULD;

/**
Expand Down Expand Up @@ -139,7 +140,7 @@ public Query query(DecoratedKey key, ClusteringIndexFilter filter) {
}

private Query query(PartitionPosition position) {
return position instanceof DecoratedKey
return position.kind() == ROW_KEY
? partitionMapper.query((DecoratedKey) position)
: tokenMapper.query(position.getToken());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import static org.apache.cassandra.utils.ByteBufferUtil.EMPTY_BYTE_BUFFER;
import static org.apache.lucene.search.BooleanClause.Occur.SHOULD;
import static org.apache.cassandra.db.PartitionPosition.Kind.ROW_KEY;

/**
* Class for several clustering key mappings between Cassandra and Lucene.
Expand Down Expand Up @@ -261,7 +262,7 @@ public static Optional<ClusteringPrefix> startClusteringPrefix(DataRange dataRan
Token token = startPosition.getToken();

ClusteringIndexFilter filter;
if (startPosition instanceof DecoratedKey) {
if (startPosition.kind() == ROW_KEY) {
DecoratedKey startKey = (DecoratedKey) startPosition;
filter = dataRange.clusteringIndexFilter(startKey);
} else {
Expand Down Expand Up @@ -293,7 +294,7 @@ public static Optional<ClusteringPrefix> stopClusteringPrefix(DataRange dataRang
Token token = stopPosition.getToken();

ClusteringIndexFilter filter;
if (stopPosition instanceof DecoratedKey) {
if (stopPosition.kind() == ROW_KEY) {
DecoratedKey stopKey = (DecoratedKey) stopPosition;
filter = dataRange.clusteringIndexFilter(stopKey);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.io.IOException;
import java.nio.ByteBuffer;

import static org.apache.cassandra.db.PartitionPosition.Kind.ROW_KEY;

/**
* {@link MultiTermQuery} to get a range of clustering keys.
*
Expand Down Expand Up @@ -58,7 +60,7 @@ class KeyQuery extends MultiTermQuery {
this.mapper = mapper;
this.start = start;
this.stop = stop;
key = position instanceof DecoratedKey ? (DecoratedKey) position : null;
key = position.kind() == ROW_KEY ? (DecoratedKey) position : null;
collatedToken = TokenMapper.toCollated(position.getToken());
clusteringComparator = mapper.clusteringComparator();
seek = mapper.seek(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.stratio.cassandra.lucene.IndexException;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.DecoratedKey;
import org.apache.cassandra.db.PartitionPosition;
import org.apache.cassandra.db.marshal.UTF8Type;
import org.apache.cassandra.dht.Murmur3Partitioner;
import org.apache.cassandra.dht.Token;
Expand Down Expand Up @@ -113,26 +112,6 @@ public SortField sortField() {
return new SortField(FIELD_NAME, SortField.Type.LONG);
}

/**
* Returns if the specified lower partition position must be included in a filtered range.
*
* @param position a {@link PartitionPosition}
* @return {@code true} if {@code position} must be included, {@code false} otherwise
*/
private static boolean includeStart(PartitionPosition position) {
return position.kind() == PartitionPosition.Kind.MIN_BOUND;
}

/**
* Returns if the specified upper partition position must be included in a filtered range.
*
* @param position a {@link PartitionPosition}
* @return {@code true} if {@code position} must be included, {@code false} otherwise
*/
private static boolean includeStop(PartitionPosition position) {
return position.kind() == PartitionPosition.Kind.MAX_BOUND;
}

/**
* Returns if doc values should be used for retrieving token ranges between the specified values.
*
Expand Down Expand Up @@ -175,18 +154,6 @@ public Optional<Query> query(Token lower, Token upper, boolean includeLower, boo
return Optional.of(query);
}

/**
* Returns a Lucene {@link Query} to find the {@link Document}s containing a {@link Token} inside the specified
* {@link PartitionPosition}s.
*
* @param start the start position
* @param stop the stop position
* @return the query to find the documents containing a token inside the range
*/
public Optional<Query> query(PartitionPosition start, PartitionPosition stop) {
return query(start.getToken(), stop.getToken(), includeStart(start), includeStop(stop));
}

/**
* Returns a Lucene {@link Query} to find the {@link Document}s containing the specified {@link Token}.
*
Expand Down

0 comments on commit 0b34b75

Please sign in to comment.