mirror of https://github.com/apache/cassandra
CQL TRUNCATE implementation + test
Patch by eevans for CASSANDRA-1716 git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@1039595 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
930b4658b3
commit
8a47cff66b
|
|
@ -43,10 +43,11 @@ options {
|
|||
}
|
||||
|
||||
query returns [CQLStatement stmnt]
|
||||
: selectStatement { $stmnt = new CQLStatement(StatementType.SELECT, $selectStatement.expr); }
|
||||
| updateStatement { $stmnt = new CQLStatement(StatementType.UPDATE, $updateStatement.expr); }
|
||||
: selectStatement { $stmnt = new CQLStatement(StatementType.SELECT, $selectStatement.expr); }
|
||||
| updateStatement { $stmnt = new CQLStatement(StatementType.UPDATE, $updateStatement.expr); }
|
||||
| batchUpdateStatement { $stmnt = new CQLStatement(StatementType.BATCH_UPDATE, $batchUpdateStatement.expr); }
|
||||
| useStatement { $stmnt = new CQLStatement(StatementType.USE, $useStatement.keyspace); }
|
||||
| useStatement { $stmnt = new CQLStatement(StatementType.USE, $useStatement.keyspace); }
|
||||
| truncateStatement { $stmnt = new CQLStatement(StatementType.TRUNCATE, $truncateStatement.cfam); }
|
||||
;
|
||||
|
||||
// USE <KEYSPACE>;
|
||||
|
|
@ -168,6 +169,11 @@ selectExpression returns [SelectExpression expr]
|
|||
| start=term '..' finish=term { $expr = new SelectExpression(start, finish, count, reversed); }
|
||||
)
|
||||
;
|
||||
|
||||
// TRUNCATE <CF>;
|
||||
truncateStatement returns [String cfam]
|
||||
: K_TRUNCATE columnFamily=IDENT { $cfam = $columnFamily.text; } endStmnt
|
||||
;
|
||||
|
||||
endStmnt
|
||||
: (EOF | ';')
|
||||
|
|
@ -201,6 +207,7 @@ K_SET: S E T;
|
|||
K_BEGIN: B E G I N;
|
||||
K_APPLY: A P P L Y;
|
||||
K_BATCH: B A T C H;
|
||||
K_TRUNCATE: T R U N C A T E;
|
||||
|
||||
// Case-insensitive alpha characters
|
||||
fragment A: ('a'|'A');
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ import org.slf4j.LoggerFactory;
|
|||
import static org.apache.cassandra.avro.AvroValidation.validateKey;
|
||||
import static org.apache.cassandra.avro.AvroValidation.validateColumnFamily;
|
||||
import static org.apache.cassandra.avro.AvroErrorFactory.newInvalidRequestException;
|
||||
import static org.apache.cassandra.avro.AvroErrorFactory.newUnavailableException;
|
||||
|
||||
public class QueryProcessor
|
||||
{
|
||||
|
|
@ -419,6 +420,29 @@ public class QueryProcessor
|
|||
avroResult.type = CqlResultType.VOID;
|
||||
|
||||
return avroResult;
|
||||
|
||||
case TRUNCATE:
|
||||
String columnFamily = (String)statement.statement;
|
||||
|
||||
try
|
||||
{
|
||||
StorageProxy.truncateBlocking(keyspace, columnFamily);
|
||||
}
|
||||
catch (org.apache.cassandra.thrift.UnavailableException e)
|
||||
{
|
||||
throw newUnavailableException(e);
|
||||
}
|
||||
catch (TimeoutException e)
|
||||
{
|
||||
throw newUnavailableException(e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw newUnavailableException(e);
|
||||
}
|
||||
|
||||
avroResult.type = CqlResultType.VOID;
|
||||
return avroResult;
|
||||
}
|
||||
|
||||
return null; // We should never get here.
|
||||
|
|
|
|||
|
|
@ -22,5 +22,5 @@ package org.apache.cassandra.cql;
|
|||
|
||||
public enum StatementType
|
||||
{
|
||||
SELECT, UPDATE, BATCH_UPDATE, USE;
|
||||
SELECT, UPDATE, BATCH_UPDATE, USE, TRUNCATE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,3 +160,9 @@ class TestCql(AvroTester):
|
|||
r = conn.execute('SELECT COUNT(1L..4L) FROM StandardLong1 WHERE KEY = "aa";')
|
||||
assert r == 4
|
||||
|
||||
def test_truncate_columnfamily(self):
|
||||
"truncating a column family"
|
||||
conn = init()
|
||||
conn.execute('TRUNCATE Standard1;')
|
||||
r = conn.execute('SELECT "cd1" FROM Standard1 WHERE KEY = "kd"')
|
||||
assert len(r) == 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue