Repository: cassandra Updated Branches: refs/heads/cassandra-2.2 6dcc89f81 -> eecfb07d4
Make "truncate table X" an alias for "truncate X" patch by Benjamin Lerer; reviewed by Robert Stupp for CASSANDRA-9585 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4e3555c1 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4e3555c1 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4e3555c1 Branch: refs/heads/cassandra-2.2 Commit: 4e3555c1d99b6a3273262443befffe73f86c203d Parents: ba5837e Author: blerer <[email protected]> Authored: Thu Sep 17 22:02:45 2015 +0200 Committer: blerer <[email protected]> Committed: Thu Sep 17 22:02:45 2015 +0200 ---------------------------------------------------------------------- NEWS.txt | 7 +++ bin/cqlsh | 2 +- doc/cql3/CQL.textile | 8 +++- pylib/cqlshlib/cql3handling.py | 2 +- src/java/org/apache/cassandra/cql3/Cql.g | 2 +- .../apache/cassandra/cql3/QueryProcessor.java | 2 +- .../validation/operations/TruncateTest.java | 48 ++++++++++++++++++++ 7 files changed, 65 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/4e3555c1/NEWS.txt ---------------------------------------------------------------------- diff --git a/NEWS.txt b/NEWS.txt index 297bf40..6ec24ef 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -13,6 +13,13 @@ restore snapshots created with the previous major version using the 'sstableloader' tool. You can upgrade the file format of your snapshots using the provided 'sstableupgrade' tool. +2.1.10 +===== + +New features +------------ + - The syntax TRUNCATE TABLE X is now accepted as an alias for TRUNCATE X + 2.1.9 ===== http://git-wip-us.apache.org/repos/asf/cassandra/blob/4e3555c1/bin/cqlsh ---------------------------------------------------------------------- diff --git a/bin/cqlsh b/bin/cqlsh index 82d9464..b649ab7 100755 --- a/bin/cqlsh +++ b/bin/cqlsh @@ -129,7 +129,7 @@ from cqlshlib.util import get_file_encoding_bomsize, trim_if_present DEFAULT_HOST = '127.0.0.1' DEFAULT_PORT = 9042 -DEFAULT_CQLVER = '3.2.0' +DEFAULT_CQLVER = '3.2.1' DEFAULT_PROTOCOL_VERSION = 3 DEFAULT_CONNECT_TIMEOUT_SECONDS = 5 http://git-wip-us.apache.org/repos/asf/cassandra/blob/4e3555c1/doc/cql3/CQL.textile ---------------------------------------------------------------------- diff --git a/doc/cql3/CQL.textile b/doc/cql3/CQL.textile index 648c39f..cc041df 100644 --- a/doc/cql3/CQL.textile +++ b/doc/cql3/CQL.textile @@ -1,6 +1,6 @@ <link rel="StyleSheet" href="CQL.css" type="text/css" media="screen"> -h1. Cassandra Query Language (CQL) v3.2.0 +h1. Cassandra Query Language (CQL) v3.2.1 <span id="tableOfContents"> @@ -425,7 +425,7 @@ h3(#truncateStmt). TRUNCATE __Syntax:__ -bc(syntax). <truncate-stmt> ::= TRUNCATE <tablename> +bc(syntax). <truncate-stmt> ::= TRUNCATE ( TABLE | COLUMNFAMILY )? <tablename> __Sample:__ @@ -1531,6 +1531,10 @@ h2(#changes). Changes The following describes the changes in each version of CQL. +h3. 3.2.1 + +* The syntax @TRUNCATE TABLE X@ is now accepted as an alias for @TRUNCATE X@ + h3. 3.2.0 * User-defined types are now supported through "@CREATE TYPE@":#createTypeStmt, "@ALTER TYPE@":#alterTypeStmt, and "@DROP TYPE@":#dropTypeStmt http://git-wip-us.apache.org/repos/asf/cassandra/blob/4e3555c1/pylib/cqlshlib/cql3handling.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index bc4f2ef..5f93003 100644 --- a/pylib/cqlshlib/cql3handling.py +++ b/pylib/cqlshlib/cql3handling.py @@ -913,7 +913,7 @@ def batch_opt_completer(ctxt, cass): return opts syntax_rules += r''' -<truncateStatement> ::= "TRUNCATE" cf=<columnFamilyName> +<truncateStatement> ::= "TRUNCATE" ("COLUMNFAMILY" | "TABLE")? cf=<columnFamilyName> ; ''' http://git-wip-us.apache.org/repos/asf/cassandra/blob/4e3555c1/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 db8ef25..fc8f614 100644 --- a/src/java/org/apache/cassandra/cql3/Cql.g +++ b/src/java/org/apache/cassandra/cql3/Cql.g @@ -699,7 +699,7 @@ dropIndexStatement returns [DropIndexStatement expr] * TRUNCATE <CF>; */ truncateStatement returns [TruncateStatement stmt] - : K_TRUNCATE cf=columnFamilyName { $stmt = new TruncateStatement(cf); } + : K_TRUNCATE (K_COLUMNFAMILY)? cf=columnFamilyName { $stmt = new TruncateStatement(cf); } ; /** http://git-wip-us.apache.org/repos/asf/cassandra/blob/4e3555c1/src/java/org/apache/cassandra/cql3/QueryProcessor.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/QueryProcessor.java b/src/java/org/apache/cassandra/cql3/QueryProcessor.java index d59d84f..d4ca76f 100644 --- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java +++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java @@ -64,7 +64,7 @@ import org.github.jamm.MemoryMeter; public class QueryProcessor implements QueryHandler { - public static final SemanticVersion CQL_VERSION = new SemanticVersion("3.2.0"); + public static final SemanticVersion CQL_VERSION = new SemanticVersion("3.2.1"); public static final QueryProcessor instance = new QueryProcessor(); http://git-wip-us.apache.org/repos/asf/cassandra/blob/4e3555c1/test/unit/org/apache/cassandra/cql3/validation/operations/TruncateTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/TruncateTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/TruncateTest.java new file mode 100644 index 0000000..78a42fc --- /dev/null +++ b/test/unit/org/apache/cassandra/cql3/validation/operations/TruncateTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.cql3.validation.operations; + +import org.junit.Test; + +import org.apache.cassandra.cql3.CQLTester; + +public class TruncateTest extends CQLTester +{ + @Test + public void testTruncate() throws Throwable + { + for (String table : new String[] { "", "TABLE" }) + { + createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY(a, b))"); + + execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 0, 0); + execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1, 1); + + flush(); + + execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 1, 0, 2); + execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 1, 1, 3); + + assertRows(execute("SELECT * FROM %s"), row(1, 0, 2), row(1, 1, 3), row(0, 0, 0), row(0, 1, 1)); + + execute("TRUNCATE " + table + " %s"); + + assertEmpty(execute("SELECT * FROM %s")); + } + } +}
