From 4e3555c1d99b6a3273262443befffe73f86c203d Mon Sep 17 00:00:00 2001 From: blerer Date: Thu, 17 Sep 2015 22:02:45 +0200 Subject: [PATCH] Make "truncate table X" an alias for "truncate X" patch by Benjamin Lerer; reviewed by Robert Stupp for CASSANDRA-9585 --- 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(-) create mode 100644 test/unit/org/apache/cassandra/cql3/validation/operations/TruncateTest.java diff --git a/NEWS.txt b/NEWS.txt index 297bf4041b..6ec24eff19 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 ===== diff --git a/bin/cqlsh b/bin/cqlsh index 82d9464a32..b649ab72c7 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 diff --git a/doc/cql3/CQL.textile b/doc/cql3/CQL.textile index 648c39faf5..cc041df8b3 100644 --- a/doc/cql3/CQL.textile +++ b/doc/cql3/CQL.textile @@ -1,6 +1,6 @@ -h1. Cassandra Query Language (CQL) v3.2.0 +h1. Cassandra Query Language (CQL) v3.2.1 @@ -425,7 +425,7 @@ h3(#truncateStmt). TRUNCATE __Syntax:__ -bc(syntax). ::= TRUNCATE +bc(syntax). ::= TRUNCATE ( TABLE | COLUMNFAMILY )? __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 diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index bc4f2ef266..5f93003531 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''' - ::= "TRUNCATE" cf= + ::= "TRUNCATE" ("COLUMNFAMILY" | "TABLE")? cf= ; ''' diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g index db8ef251d6..fc8f614123 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 ; */ truncateStatement returns [TruncateStatement stmt] - : K_TRUNCATE cf=columnFamilyName { $stmt = new TruncateStatement(cf); } + : K_TRUNCATE (K_COLUMNFAMILY)? cf=columnFamilyName { $stmt = new TruncateStatement(cf); } ; /** diff --git a/src/java/org/apache/cassandra/cql3/QueryProcessor.java b/src/java/org/apache/cassandra/cql3/QueryProcessor.java index d59d84f67a..d4ca76f30d 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(); 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 0000000000..78a42fcb59 --- /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")); + } + } +}