cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r1029362 - in /cassandra/trunk: doc/cql/ src/java/org/apache/cassandra/avro/ src/java/org/apache/cassandra/cql/
Date Sun, 31 Oct 2010 14:37:09 GMT
Author: eevans
Date: Sun Oct 31 14:37:08 2010
New Revision: 1029362

URL: http://svn.apache.org/viewvc?rev=1029362&view=rev
Log:
implement `USE <keyspace>' statement

Patch by eevans

Modified:
    cassandra/trunk/doc/cql/CQL.textile
    cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g
    cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/StatementType.java

Modified: cassandra/trunk/doc/cql/CQL.textile
URL: http://svn.apache.org/viewvc/cassandra/trunk/doc/cql/CQL.textile?rev=1029362&r1=1029361&r2=1029362&view=diff
==============================================================================
--- cassandra/trunk/doc/cql/CQL.textile (original)
+++ cassandra/trunk/doc/cql/CQL.textile Sun Oct 31 14:37:08 2010
@@ -4,6 +4,15 @@ h2. Table of Contents
 
 {toc}
 
+h2. USE
+
+__Synopsis:__
+
+bc. 
+USE <KEYSPACE>;
+
+A @USE@ statement consists of the @USE@ keyword, followed by a valid keyspace name.  Its
purpose is to assign the per-connection, current working keyspace.  All subsequent keyspace-specific
actions will be performed in the context of the supplied value.
+
 h2. SELECT
 
 __Synopsis:__

Modified: cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java?rev=1029362&r1=1029361&r2=1029362&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java Sun Oct 31 14:37:08
2010
@@ -1208,7 +1208,7 @@ public class CassandraServer implements 
         
         try
         {
-            return QueryProcessor.process(queryString, state().getKeyspace());
+            return QueryProcessor.process(queryString, state());
         }
         catch (RecognitionException e)
         {

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g?rev=1029362&r1=1029361&r2=1029362&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g Sun Oct 31 14:37:08 2010
@@ -16,6 +16,12 @@ options {
 query returns [CQLStatement stmnt]
     : selectStatement { $stmnt = new CQLStatement(StatementType.SELECT, $selectStatement.expr);
}
     | updateStatement { $stmnt = new CQLStatement(StatementType.UPDATE, $updateStatement.expr);
}
+    | useStatement    { $stmnt = new CQLStatement(StatementType.USE, $useStatement.keyspace);
}
+    ;
+
+// USE <KEYSPACE>;
+useStatement returns [String keyspace]
+    : K_USE IDENT { $keyspace = $IDENT.text; } ';'
     ;
 
 /**
@@ -127,6 +133,7 @@ K_LEVEL:       ( Z E R O
                | D C Q U O R U M S Y N C
                )
                ;
+K_USE:         U S E;
 
 // Case-insensitive alpha characters
 fragment A: ('a'|'A');

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java?rev=1029362&r1=1029361&r2=1029362&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java Sun Oct 31 14:37:08
2010
@@ -54,6 +54,7 @@ import org.apache.cassandra.db.filter.Qu
 import org.apache.cassandra.dht.AbstractBounds;
 import org.apache.cassandra.dht.Bounds;
 import org.apache.cassandra.dht.IPartitioner;
+import org.apache.cassandra.service.ClientState;
 import org.apache.cassandra.service.StorageProxy;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.thrift.ConsistencyLevel;
@@ -105,13 +106,14 @@ public class QueryProcessor
         return columnFamilyKeyMap;
     }
 
-    public static CqlResult process(String queryString, String keyspace)
+    public static CqlResult process(String queryString, ClientState clientState)
     throws RecognitionException, UnavailableException, InvalidRequestException, TimedOutException
     {
         logger.debug("CQL QUERY: {}", queryString);
         
         CqlParser parser = getParser(queryString);
         CQLStatement statement = parser.query();
+        String keyspace = clientState.getKeyspace();
         
         CqlResult avroResult = new CqlResult();
         
@@ -284,6 +286,12 @@ public class QueryProcessor
                 }
                     
                 return avroResult;
+                
+            case USE:
+                clientState.setKeyspace((String)statement.statement);
+                avroResult.type = CqlResultType.VOID;
+                
+                return avroResult;
         }
         
         return null;    // We should never get here.

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/StatementType.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/StatementType.java?rev=1029362&r1=1029361&r2=1029362&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/StatementType.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/StatementType.java Sun Oct 31 14:37:08
2010
@@ -23,5 +23,5 @@ package org.apache.cassandra.cql;
 
 public enum StatementType
 {
-    SELECT, UPDATE;
+    SELECT, UPDATE, USE;
 }



Mime
View raw message