diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ade85c73..66ee135fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/plugin/src/main/java/com/stratio/cassandra/lucene/IndexService.java b/plugin/src/main/java/com/stratio/cassandra/lucene/IndexService.java index 8c1f32f69..2914437b6 100644 --- a/plugin/src/main/java/com/stratio/cassandra/lucene/IndexService.java +++ b/plugin/src/main/java/com/stratio/cassandra/lucene/IndexService.java @@ -550,17 +550,6 @@ private Optional query(ReadCommand command) { */ abstract Optional 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(PartitionPosition start, PartitionPosition stop) { - return tokenMapper.query(start, stop); - } - private Query after(IndexPagingState pagingState, ReadCommand command) { try { if (pagingState != null) { diff --git a/plugin/src/main/java/com/stratio/cassandra/lucene/IndexServiceSkinny.java b/plugin/src/main/java/com/stratio/cassandra/lucene/IndexServiceSkinny.java index 365b7d53c..e904f9cef 100644 --- a/plugin/src/main/java/com/stratio/cassandra/lucene/IndexServiceSkinny.java +++ b/plugin/src/main/java/com/stratio/cassandra/lucene/IndexServiceSkinny.java @@ -34,6 +34,8 @@ import java.util.*; +import static org.apache.cassandra.db.PartitionPosition.Kind.*; + /** * {@link IndexService} for skinny rows. * @@ -106,9 +108,15 @@ public Query query(DecoratedKey key, ClusteringIndexFilter filter) { /** {@inheritDoc} */ @Override public Optional 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} */ diff --git a/plugin/src/main/java/com/stratio/cassandra/lucene/IndexServiceWide.java b/plugin/src/main/java/com/stratio/cassandra/lucene/IndexServiceWide.java index 0d49cb9a6..4fad4acaf 100644 --- a/plugin/src/main/java/com/stratio/cassandra/lucene/IndexServiceWide.java +++ b/plugin/src/main/java/com/stratio/cassandra/lucene/IndexServiceWide.java @@ -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; /** @@ -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()); } diff --git a/plugin/src/main/java/com/stratio/cassandra/lucene/key/KeyMapper.java b/plugin/src/main/java/com/stratio/cassandra/lucene/key/KeyMapper.java index 45b70579e..e7692380d 100644 --- a/plugin/src/main/java/com/stratio/cassandra/lucene/key/KeyMapper.java +++ b/plugin/src/main/java/com/stratio/cassandra/lucene/key/KeyMapper.java @@ -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. @@ -261,7 +262,7 @@ public static Optional 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 { @@ -293,7 +294,7 @@ public static Optional 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 { diff --git a/plugin/src/main/java/com/stratio/cassandra/lucene/key/KeyQuery.java b/plugin/src/main/java/com/stratio/cassandra/lucene/key/KeyQuery.java index 815b8a70b..ac8359dfa 100644 --- a/plugin/src/main/java/com/stratio/cassandra/lucene/key/KeyQuery.java +++ b/plugin/src/main/java/com/stratio/cassandra/lucene/key/KeyQuery.java @@ -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. * @@ -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); diff --git a/plugin/src/main/java/com/stratio/cassandra/lucene/key/TokenMapper.java b/plugin/src/main/java/com/stratio/cassandra/lucene/key/TokenMapper.java index 119222314..961319d6c 100644 --- a/plugin/src/main/java/com/stratio/cassandra/lucene/key/TokenMapper.java +++ b/plugin/src/main/java/com/stratio/cassandra/lucene/key/TokenMapper.java @@ -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; @@ -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. * @@ -175,18 +154,6 @@ public Optional 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(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}. *