mirror of https://github.com/apache/cassandra
implement `USE <keyspace>' statement
Patch by eevans git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@1029362 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
496d4aa46f
commit
f39be9702e
|
|
@ -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:__
|
||||
|
|
|
|||
|
|
@ -1208,7 +1208,7 @@ public class CassandraServer implements Cassandra {
|
|||
|
||||
try
|
||||
{
|
||||
return QueryProcessor.process(queryString, state().getKeyspace());
|
||||
return QueryProcessor.process(queryString, state());
|
||||
}
|
||||
catch (RecognitionException e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ import org.apache.cassandra.db.filter.QueryPath;
|
|||
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();
|
||||
|
||||
|
|
@ -283,6 +285,12 @@ public class QueryProcessor
|
|||
throw new TimedOutException();
|
||||
}
|
||||
|
||||
return avroResult;
|
||||
|
||||
case USE:
|
||||
clientState.setKeyspace((String)statement.statement);
|
||||
avroResult.type = CqlResultType.VOID;
|
||||
|
||||
return avroResult;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,5 +23,5 @@ package org.apache.cassandra.cql;
|
|||
|
||||
public enum StatementType
|
||||
{
|
||||
SELECT, UPDATE;
|
||||
SELECT, UPDATE, USE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue