Merge branch 'cassandra-2.0' into cassandra-2.1

Conflicts:
        CHANGES.txt
        src/java/org/apache/cassandra/cql3/statements/SelectStatement.java


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/94f25ce1
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/94f25ce1
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/94f25ce1

Branch: refs/heads/trunk
Commit: 94f25ce15923e9a790a01a8210e141606f9091a4
Parents: 7abd76e 20e058b
Author: Sylvain Lebresne <sylv...@datastax.com>
Authored: Wed May 21 11:36:18 2014 +0200
Committer: Sylvain Lebresne <sylv...@datastax.com>
Committed: Wed May 21 11:36:18 2014 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cql3/statements/SelectStatement.java        | 20 +++++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/94f25ce1/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 12de385,bd0031e..0b8be6e
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -57,6 -28,25 +57,7 @@@ Merged from 2.0
   * Re-add parameter columns to tracing session (CASSANDRA-6942)
   * Fix writetime/ttl functions for static columns (CASSANDRA-7081)
   * Suggest CTRL-C or semicolon after three blank lines in cqlsh 
(CASSANDRA-7142)
 - * (Hadoop) support authentication in CqlRecordReader (CASSANDRA-7221)
 - * (Hadoop) Close java driver Cluster in CQLRR.close (CASSANDRA-7228)
 - * Fix potential SlabAllocator yield-starvation (CASSANDRA-7133)
 - * Warn when 'USING TIMESTAMP' is used on a CAS BATCH (CASSANDRA-7067)
 - * Starting threads in OutboundTcpConnectionPool constructor causes race 
conditions (CASSANDRA-7177)
 - * return all cpu values from BackgroundActivityMonitor.readAndCompute 
(CASSANDRA-7183)
 - * fix c* launch issues on Russian os's due to output of linux 'free' cmd 
(CASSANDRA-6162)
 - * Fix disabling autocompaction (CASSANDRA-7187)
 - * Fix potential NumberFormatException when deserializing IntegerType 
(CASSANDRA-7088)
 - * cqlsh can't tab-complete disabling compaction (CASSANDRA-7185)
 - * cqlsh: Accept and execute CQL statement(s) from command-line parameter 
(CASSANDRA-7172)
 - * Fix IllegalStateException in CqlPagingRecordReader (CASSANDRA-7198)
 - * Fix the InvertedIndex trigger example (CASSANDRA-7211)
 - * Add --resolve-ip option to 'nodetool ring' (CASSANDRA-7210)
 - * Fix duplicated error messages on directory creation error at startup 
(CASSANDRA-5818)
 - * reduce garbage on codec flag deserialization (CASSANDRA-7244) 
 - * Proper null handle for IF with map element access (CASSANDRA-7155)
 - * Improve compaction visibility (CASSANDRA-7242)
+  * Fix 2ndary index queries with DESC clustering order (CASSANDRA-6950)
  Merged from 1.2:
   * Add Cloudstack snitch (CASSANDRA-7147)
   * Update system.peers correctly when relocating tokens (CASSANDRA-7126)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/94f25ce1/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 55ce6f9,6b4309f..ca990a4
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@@ -927,8 -922,19 +927,14 @@@ public class SelectStatement implement
                  {
                      if (slice.hasBound(b))
                      {
 -                        ByteBuffer value = slice.bound(b, variables);
 -                        if (value == null)
 -                            throw new 
InvalidRequestException(String.format("Unsupported null value for indexed 
column %s", name));
 -                        if (value.remaining() > 0xFFFF)
 -                            throw new InvalidRequestException("Index 
expression values may not be larger than 64K");
 -
 +                        ByteBuffer value = validateIndexedValue(def, 
slice.bound(b, options));
-                         expressions.add(new IndexExpression(def.name.bytes, 
slice.getIndexOperator(b), value));
+                         IndexOperator op = slice.getIndexOperator(b);
+                         // If the underlying comparator for name is reversed, 
we need to reverse the IndexOperator: user operation
+                         // always refer to the "forward" sorting even if the 
clustering order is reversed, but the 2ndary code does
+                         // use the underlying comparator as is.
+                         if (name.type instanceof ReversedType)
+                             op = reverse(op);
 -                        expressions.add(new IndexExpression(name.name.key, 
op, value));
++                        expressions.add(new IndexExpression(def.name.bytes, 
op, value));
                      }
                  }
              }
@@@ -960,45 -956,19 +966,57 @@@
          return expressions;
      }
  
 +    private static ByteBuffer validateIndexedValue(ColumnDefinition def, 
ByteBuffer value) throws InvalidRequestException
 +    {
 +        if (value == null)
 +            throw new InvalidRequestException(String.format("Unsupported null 
value for indexed column %s", def.name));
 +        if (value.remaining() > 0xFFFF)
 +            throw new InvalidRequestException("Index expression values may 
not be larger than 64K");
 +        return value;
 +    }
 +
 +    private Iterator<Cell> applySliceRestriction(final Iterator<Cell> cells, 
final QueryOptions options) throws InvalidRequestException
 +    {
 +        assert sliceRestriction != null;
 +
 +        final CellNameType type = cfm.comparator;
 +        final CellName excludedStart = 
sliceRestriction.isInclusive(Bound.START) ? null : 
type.makeCellName(sliceRestriction.bound(Bound.START, options));
 +        final CellName excludedEnd = sliceRestriction.isInclusive(Bound.END) 
? null : type.makeCellName(sliceRestriction.bound(Bound.END, options));
 +
 +        return new AbstractIterator<Cell>()
 +        {
 +            protected Cell computeNext()
 +            {
 +                while (cells.hasNext())
 +                {
 +                    Cell c = cells.next();
 +
 +                    // For dynamic CF, the column could be out of the 
requested bounds (because we don't support strict bounds internally (unless
 +                    // the comparator is composite that is)), filter here
 +                    if ( (excludedStart != null && type.compare(c.name(), 
excludedStart) == 0)
 +                      || (excludedEnd != null && type.compare(c.name(), 
excludedEnd) == 0) )
 +                        continue;
 +
 +                    return c;
 +                }
 +                return endOfData();
 +            }
 +        };
 +    }
 +
+     private static IndexOperator reverse(IndexOperator op)
+     {
+         switch (op)
+         {
+             case LT:  return IndexOperator.GT;
+             case LTE: return IndexOperator.GTE;
+             case GT:  return IndexOperator.LT;
+             case GTE: return IndexOperator.LTE;
+             default: return op;
+         }
+     }
+ 
 -    private ResultSet process(List<Row> rows, List<ByteBuffer> variables, int 
limit, long now) throws InvalidRequestException
 +    private ResultSet process(List<Row> rows, QueryOptions options, int 
limit, long now) throws InvalidRequestException
      {
          Selection.ResultSetBuilder result = selection.resultSetBuilder(now);
          for (org.apache.cassandra.db.Row row : rows)

Reply via email to