Correctly validate order by queries patch by slebresne; reviewed by jbellis for CASSANDRA-4246
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/fd92c09d Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/fd92c09d Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/fd92c09d Branch: refs/heads/trunk Commit: fd92c09d95a53d582cb8c4b0e77ac47fdd884935 Parents: a0e0e2c Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Thu May 17 14:37:49 2012 +0200 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Thu May 17 19:37:12 2012 +0200 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/cql3/statements/SelectStatement.java | 16 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/fd92c09d/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 70d9bbe..46646bf 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -48,6 +48,7 @@ * fix SecondaryIndex LelevedManifest save upon snapshot (CASSANDRA-4230) * fix missing arrayOffset in FBUtilities.hash (CASSANDRA-4250) * (cql3) Add name of parameters in CqlResultSet (CASSANDRA-4242) + * (cql3) Correctly validat order by queries (CASSANDRA-4246) Merged from 1.0: * Fix super columns bug where cache is not updated (CASSANDRA-4190) * fix maxTimestamp to include row tombstones (CASSANDRA-4116) http://git-wip-us.apache.org/repos/asf/cassandra/blob/fd92c09d/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 d3fb50a..35cb943 100644 --- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java @@ -757,7 +757,8 @@ public class SelectStatement implements CQLStatement cqlRows.add(new CqlRow(row.key.key, thriftColumns)); } } - // We don't allow reversed on range scan, but we do on multiget (IN (...)), so let's reverse the rows there too. + + // Internal calls always return columns in the comparator order, even when reverse was set if (isReversed) Collections.reverse(cqlRows); @@ -1013,14 +1014,13 @@ public class SelectStatement implements CQLStatement } assert isReversed != null; stmt.isReversed = isReversed; - } - // Only allow reversed if the row key restriction is an equality, - // since we don't know how to reverse otherwise - if (stmt.isReversed) - { - if (stmt.keyRestriction == null || !stmt.keyRestriction.isEquality()) - throw new InvalidRequestException("Descending order is only supported is the first part of the PRIMARY KEY is restricted by an Equal or a IN"); + // Only allow ordering if the row key restriction is an equality, + // since otherwise the order will be primarily on the row key. + // TODO: we could allow ordering for IN queries, as we can do the + // sorting post-query easily, but we will have to add it + if (stmt.keyRestriction == null || !stmt.keyRestriction.isEquality() || stmt.keyRestriction.eqValues.size() != 1) + throw new InvalidRequestException("Ordering is only supported is the first part of the PRIMARY KEY is restricted by an Equal or a IN"); } // If this is a query on tokens, it's necessary a range query (there can be more than one key per token), so reject IN queries (as we don't know how to do them)