cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [3/6] git commit: Update ORDER BY syntax for CQL3
Date Mon, 20 Feb 2012 10:15:41 GMT
Update ORDER BY syntax for CQL3

patch by slebresne; reviewed by jbellis for CASSANDRA-3925


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

Branch: refs/heads/trunk
Commit: 058307b65ebf6d85027c8960e26ed10a4f4bfd80
Parents: 14d5738
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Mon Feb 20 11:04:00 2012 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Mon Feb 20 11:04:00 2012 +0100

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 src/java/org/apache/cassandra/cql3/Cql.g           |    5 ++++-
 .../cassandra/cql3/statements/SelectStatement.java |   15 ++++++++++++++-
 3 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/058307b6/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 596ceeb..b8ffb10 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,7 @@
    (CASSANDRA-3921)
  * fix concurrency issues with CQL keyspace creation (CASSANDRA-3903)
  * Show Effective Owership via Nodetool ring <keyspace> (CASSANDRA-3412)
+ * Update ORDER BY syntax for CQL3 (CASSANDRA-3925)
 
 1.1-beta1
  * add nodetool rebuild_index (CASSANDRA-3583)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/058307b6/src/java/org/apache/cassandra/cql3/Cql.g
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g
index 4c9cfe4..ec6e8e0 100644
--- a/src/java/org/apache/cassandra/cql3/Cql.g
+++ b/src/java/org/apache/cassandra/cql3/Cql.g
@@ -157,16 +157,18 @@ selectStatement returns [SelectStatement.RawStatement expr]
         ConsistencyLevel cLevel = ConsistencyLevel.ONE;
         int limit = 10000;
         boolean reversed = false;
+        ColumnIdentifier orderBy = null;
     }
     : K_SELECT ( sclause=selectClause | (K_COUNT '(' sclause=selectClause ')' { isCount =
true; }) )
       K_FROM cf=columnFamilyName
       ( K_USING K_CONSISTENCY K_LEVEL { cLevel = ConsistencyLevel.valueOf($K_LEVEL.text.toUpperCase());
} )?
       ( K_WHERE wclause=whereClause )?
-      ( K_ORDER (K_ASC | K_DESC { reversed = true; }) )?
+      ( K_ORDER K_BY c=cident { orderBy = c; } (K_ASC | K_DESC { reversed = true; })? )?
       ( K_LIMIT rows=INTEGER { limit = Integer.parseInt($rows.text); } )?
       {
           SelectStatement.Parameters params = new SelectStatement.Parameters(cLevel,
                                                                              limit,
+                                                                             orderBy,
                                                                              reversed,
                                                                              isCount);
           $expr = new SelectStatement.RawStatement(cf, params, sclause, wclause);
@@ -533,6 +535,7 @@ K_TYPE:        T Y P E;
 K_COMPACT:     C O M P A C T;
 K_STORAGE:     S T O R A G E;
 K_ORDER:       O R D E R;
+K_BY:          B Y;
 K_ASC:         A S C;
 K_DESC:        D E S C;
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/058307b6/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 3b699b9..e8b7c45 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -915,6 +915,17 @@ public class SelectStatement implements CQLStatement
                 }
             }
 
+            // We only support order by on the the second PK column
+            if (stmt.parameters.orderBy != null)
+            {
+                CFDefinition.Name name = cfDef.get(stmt.parameters.orderBy);
+                if (name == null)
+                    throw new InvalidRequestException(String.format("Order by on unknown
column %s", stmt.parameters.orderBy));
+
+                if (name.kind != CFDefinition.Name.Kind.COLUMN_ALIAS || name.position !=
0)
+                    throw new InvalidRequestException(String.format("Order by is currently
only supported on the second column of the PRIMARY KEY (if any), got %s", stmt.parameters.orderBy));
+            }
+
             // Only allow reversed if the row key restriction is an equality,
             // since we don't know how to reverse otherwise
             if (stmt.parameters.isColumnsReversed)
@@ -1079,13 +1090,15 @@ public class SelectStatement implements CQLStatement
     {
         private final int limit;
         private final ConsistencyLevel consistencyLevel;
+        private final ColumnIdentifier orderBy;
         private final boolean isColumnsReversed;
         private final boolean isCount;
 
-        public Parameters(ConsistencyLevel consistency, int limit, boolean reversed, boolean
isCount)
+        public Parameters(ConsistencyLevel consistency, int limit, ColumnIdentifier orderBy,
boolean reversed, boolean isCount)
         {
             this.consistencyLevel = consistency;
             this.limit = limit;
+            this.orderBy = orderBy;
             this.isColumnsReversed = reversed;
             this.isCount = isCount;
         }


Mime
View raw message