From b73f9d42315311e3573018749aeba34f77f1419e Mon Sep 17 00:00:00 2001 From: Sylvain Lebresne Date: Fri, 21 Jun 2013 11:21:54 +0200 Subject: [PATCH] Conditional create/drop ks/table/index statements patch by michalm; reviewed by slebresne for CASSANDRA-2737 --- CHANGES.txt | 1 + doc/cql3/CQL.textile | 26 ++++++++--- pylib/cqlshlib/cql3handling.py | 16 +++---- src/java/org/apache/cassandra/cql3/Cql.g | 45 +++++++++++-------- .../CreateColumnFamilyStatement.java | 22 +++++++-- .../cql3/statements/CreateIndexStatement.java | 14 +++++- .../statements/CreateKeyspaceStatement.java | 15 ++++++- .../statements/DropColumnFamilyStatement.java | 15 ++++++- .../cql3/statements/DropIndexStatement.java | 22 +++++++-- .../statements/DropKeyspaceStatement.java | 14 +++++- 10 files changed, 141 insertions(+), 49 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ca27791e99..044add4527 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -61,6 +61,7 @@ * Include a timestamp with all read commands to determine column expiration (CASSANDRA-5149) * Streaming 2.0 (CASSANDRA-5286) + * Conditional create/drop ks/table/index statements in CQL3 (CASSANDRA-2737) 1.2.6 * Fix cross-DC mutation forwarding (CASSANDRA-5632) diff --git a/doc/cql3/CQL.textile b/doc/cql3/CQL.textile index 287a480c7e..34a0c12514 100644 --- a/doc/cql3/CQL.textile +++ b/doc/cql3/CQL.textile @@ -134,7 +134,7 @@ h3(#createKeyspaceStmt). CREATE KEYSPACE __Syntax:__ bc(syntax).. - ::= CREATE KEYSPACE WITH + ::= CREATE KEYSPACE (IF NOT EXISTS)? WITH p. __Sample:__ @@ -159,6 +159,8 @@ The @replication@ @@ is mandatory. It must at least contains the @'cla * @'NetworkTopologyStrategy'@: A replication strategy that allows to set the replication factor independently for each data-center. The rest of the sub-options are key-value pairs where each time the key is the name of a datacenter and the value the replication factor for that data-center. * @'OldNetworkTopologyStrategy'@: A legacy replication strategy. You should avoid this strategy for new keyspaces and prefer @'NetworkTopologyStrategy'@. +Attempting to create an already existing keyspace will return an error unless the @IF NOT EXISTS@ option is used. If it is used, the statement will be a no-op if the keyspace already exists. + h3(#useStmt). USE __Syntax:__ @@ -192,7 +194,7 @@ h3(#dropKeyspaceStmt). DROP KEYSPACE __Syntax:__ -bc(syntax). ::= DROP KEYSPACE +bc(syntax). ::= DROP KEYSPACE ( IF EXISTS )? __Sample:__ @@ -200,13 +202,15 @@ bc(sample). DROP KEYSPACE myApp; A @DROP KEYSPACE@ statement results in the immediate, irreversible removal of an existing keyspace, including all column families in it, and all data contained in those column families. +If the keyspace does not exists, the statement will return an error, unless @IF EXISTS@ is used in which case the operation is a no-op. + h3(#createTableStmt). CREATE TABLE __Syntax:__ bc(syntax).. - ::= CREATE (TABLE | COLUMNFAMILY) + ::= CREATE ( TABLE | COLUMNFAMILY ) ( IF NOT EXISTS )? '(' ( ',' )* ')' ( WITH