Updated Branches: refs/heads/cassandra-1.1 732d82b4d -> 6ddcf0388
Fix CQL3 'is reversed' logic patch by slebresne; reviewed by tjake for CASSANDRA-4716 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/6ddcf038 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/6ddcf038 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/6ddcf038 Branch: refs/heads/cassandra-1.1 Commit: 6ddcf0388b5e968b52ec3dee5b2d9a4482e371e5 Parents: 732d82b Author: Sylvain Lebresne <[email protected]> Authored: Tue Oct 2 18:44:29 2012 +0200 Committer: Sylvain Lebresne <[email protected]> Committed: Tue Oct 2 18:44:29 2012 +0200 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/cql3/statements/SelectStatement.java | 29 ++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/6ddcf038/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 1363c22..e922c3c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -13,6 +13,7 @@ * fix re-created keyspace disappering after 1.1.5 upgrade (CASSANDRA-4698) * (CLI) display elapsed time in 2 fraction digits (CASSANDRA-3460) * add authentication support to sstableloader (CASSANDRA-4712) + * Fix CQL3 'is reversed' logic (CASSANDRA-4716) Merged from 1.0: * Switch from NBHM to CHM in MessagingService's callback map, which prevents OOM in long-running instances (CASSANDRA-4708) http://git-wip-us.apache.org/repos/asf/cassandra/blob/6ddcf038/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java index bbddee3..fac0deb 100644 --- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java @@ -88,10 +88,16 @@ public class SelectStatement implements CQLStatement START(0), END(1); public final int idx; + Bound(int idx) { this.idx = idx; } + + public static Bound reverse(Bound b) + { + return b == START ? END : START; + } }; public SelectStatement(CFDefinition cfDef, int boundTerms, Parameters parameters) @@ -189,8 +195,8 @@ public class SelectStatement implements CQLStatement // ...a range (slice) of column names if (isColumnRange()) { - ByteBuffer start = getRequestedBound(isReversed ? Bound.END : Bound.START, variables); - ByteBuffer finish = getRequestedBound(isReversed ? Bound.START : Bound.END, variables); + ByteBuffer start = getRequestedBound(Bound.START, variables); + ByteBuffer finish = getRequestedBound(Bound.END, variables); // Note that we use the total limit for every key. This is // potentially inefficient, but then again, IN + LIMIT is not a @@ -478,13 +484,18 @@ public class SelectStatement implements CQLStatement } } - private ByteBuffer getRequestedBound(Bound b, List<ByteBuffer> variables) throws InvalidRequestException + private ByteBuffer getRequestedBound(Bound bound, List<ByteBuffer> variables) throws InvalidRequestException { assert isColumnRange(); ColumnNameBuilder builder = cfDef.getColumnNameBuilder(); - for (Restriction r : columnRestrictions) + for (CFDefinition.Name name : cfDef.columns.values()) { + // In a restriction, we always have Bound.START < Bound.END for the "base" comparator. + // So if we're doing a reverse slice, we must inverse the bounds when giving them as start and end of the slice filter. + // But if the actual comparator itself is reversed, we must inversed the bounds too. + Bound b = isReversed == isReversedType(name) ? bound : Bound.reverse(bound); + Restriction r = columnRestrictions[name.position]; if (r == null || (!r.isEquality() && r.bound(b) == null)) { // There wasn't any non EQ relation on that key, we select all records having the preceding component as prefix. @@ -926,6 +937,11 @@ public class SelectStatement implements CQLStatement return new CqlRow(key, thriftColumns); } + private static boolean isReversedType(CFDefinition.Name name) + { + return name.type instanceof ReversedType; + } + public static class RawStatement extends CFStatement { private final Parameters parameters; @@ -1159,11 +1175,6 @@ public class SelectStatement implements CQLStatement return new ParsedStatement.Prepared(stmt, Arrays.<CFDefinition.Name>asList(names)); } - private static boolean isReversedType(CFDefinition.Name name) - { - return name.type instanceof ReversedType; - } - Restriction updateRestriction(CFDefinition.Name name, Restriction restriction, Relation newRel) throws InvalidRequestException { if (newRel.onToken && name.kind != CFDefinition.Name.Kind.KEY_ALIAS)
