Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 58BD4181D6 for ; Fri, 27 Nov 2015 10:02:18 +0000 (UTC) Received: (qmail 50819 invoked by uid 500); 27 Nov 2015 10:02:13 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 50786 invoked by uid 500); 27 Nov 2015 10:02:13 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 50764 invoked by uid 99); 27 Nov 2015 10:02:13 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Nov 2015 10:02:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0DE1BE01F4; Fri, 27 Nov 2015 10:02:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: snazy@apache.org To: commits@cassandra.apache.org Date: Fri, 27 Nov 2015 10:02:12 -0000 Message-Id: <84c473dd77d14cc99af50aae506d5a73@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [01/10] cassandra git commit: Some DROP ... IF EXISTS incorrectly result in exceptions on non-existing KS Repository: cassandra Updated Branches: refs/heads/trunk 1c5238c1f -> dbc8dd6a9 Some DROP ... IF EXISTS incorrectly result in exceptions on non-existing KS patch by Robert Stupp; reviewed by Marcus Eriksson for CASSANDRA-10658 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4ecbbc08 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4ecbbc08 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4ecbbc08 Branch: refs/heads/trunk Commit: 4ecbbc08206fc5cd2e91520a5b99ef890f1da75d Parents: b8a8004 Author: Robert Stupp Authored: Fri Nov 27 10:42:38 2015 +0100 Committer: Robert Stupp Committed: Fri Nov 27 10:42:38 2015 +0100 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cql3/statements/DropTypeStatement.java | 10 ++++-- .../cql3/validation/entities/TypeTest.java | 10 ++++++ .../cql3/validation/operations/DropTest.java | 37 ++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ecbbc08/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 48f4e89..4adcf4f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.1.12 + * Some DROP ... IF EXISTS incorrectly result in exceptions on non-existing KS (CASSANDRA-10658) * DeletionTime.compareTo wrong in rare cases (CASSANDRA-10749) * Force encoding when computing statement ids (CASSANDRA-10755) * Properly reject counters as map keys (CASSANDRA-10760) http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ecbbc08/src/java/org/apache/cassandra/cql3/statements/DropTypeStatement.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/statements/DropTypeStatement.java b/src/java/org/apache/cassandra/cql3/statements/DropTypeStatement.java index 94edd01..bc6005d 100644 --- a/src/java/org/apache/cassandra/cql3/statements/DropTypeStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/DropTypeStatement.java @@ -54,7 +54,12 @@ public class DropTypeStatement extends SchemaAlteringStatement { KSMetaData ksm = Schema.instance.getKSMetaData(name.getKeyspace()); if (ksm == null) - throw new InvalidRequestException(String.format("Cannot drop type in unknown keyspace %s", name.getKeyspace())); + { + if (ifExists) + return; + else + throw new InvalidRequestException(String.format("Cannot drop type in unknown keyspace %s", name.getKeyspace())); + } UserType old = ksm.userTypes.getType(name.getUserTypeName()); if (old == null) @@ -140,7 +145,8 @@ public class DropTypeStatement extends SchemaAlteringStatement public boolean announceMigration(boolean isLocalOnly) throws InvalidRequestException, ConfigurationException { KSMetaData ksm = Schema.instance.getKSMetaData(name.getKeyspace()); - assert ksm != null; + if (ksm == null) + return false; // do not assert (otherwise IF EXISTS case fails) UserType toDrop = ksm.userTypes.getType(name.getUserTypeName()); // Can be null with ifExists http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ecbbc08/test/unit/org/apache/cassandra/cql3/validation/entities/TypeTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/TypeTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/TypeTest.java index f27cca8..f23ce35 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/TypeTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/TypeTest.java @@ -28,6 +28,16 @@ import static org.junit.Assert.fail; public class TypeTest extends CQLTester { @Test + public void testNonExistingOnes() throws Throwable + { + assertInvalidMessage("No user type named", "DROP TYPE " + KEYSPACE + ".type_does_not_exist"); + assertInvalidMessage("Cannot drop type in unknown keyspace", "DROP TYPE keyspace_does_not_exist.type_does_not_exist"); + + execute("DROP TYPE IF EXISTS " + KEYSPACE + ".type_does_not_exist"); + execute("DROP TYPE IF EXISTS keyspace_does_not_exist.type_does_not_exist"); + } + + @Test public void testNowToUUIDCompatibility() throws Throwable { createTable("CREATE TABLE %s (a int, b uuid, PRIMARY KEY (a, b))"); http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ecbbc08/test/unit/org/apache/cassandra/cql3/validation/operations/DropTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/DropTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/DropTest.java new file mode 100644 index 0000000..b0c0809 --- /dev/null +++ b/test/unit/org/apache/cassandra/cql3/validation/operations/DropTest.java @@ -0,0 +1,37 @@ +/* + * 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 DropTest extends CQLTester +{ + @Test + public void testNonExistingOnes() throws Throwable + { + assertInvalidMessage("Cannot drop non existing column family", "DROP TABLE " + KEYSPACE + ".table_does_not_exist"); + assertInvalidMessage("Cannot drop non existing column family", "DROP TABLE keyspace_does_not_exist.table_does_not_exist"); + + execute("DROP TABLE IF EXISTS " + KEYSPACE + ".table_does_not_exist"); + execute("DROP TABLE IF EXISTS keyspace_does_not_exist.table_does_not_exist"); + } + +}