You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2020/02/27 13:28:20 UTC

[cassandra] branch trunk updated: Reverted to the behavior of CLUSTERING ORDER on CREATE TABLE

This is an automated email from the ASF dual-hosted git repository.

aleksey pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1f242c9  Reverted to the behavior of CLUSTERING ORDER on CREATE TABLE
1f242c9 is described below

commit 1f242c900bb087770a4cffeade6986ef19ba303d
Author: Ekaterina Dimitrova <ek...@datastax.com>
AuthorDate: Mon Feb 24 19:49:16 2020 -0500

    Reverted to the behavior of CLUSTERING ORDER on CREATE TABLE
    
    patch by Ekaterina Dimitrova; reviewed by Aleksey Yeschenko for
    CASSANDRA-15271
---
 CHANGES.txt                                        |  1 +
 .../statements/schema/CreateTableStatement.java    | 22 ++++++++++++++++------
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index ab91023..19906d3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.0-alpha4
+ * Reverted to the original behavior of CLUSTERING ORDER on CREATE TABLE (CASSANDRA-15271)
  * Correct inaccurate logging message (CASSANDRA-15549)
  * Add documentation of dynamo (CASSANDRA-15486)
  * Added documentation for Guarantees (CASSANDRA-15482)
diff --git a/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java b/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java
index be7907f..0b3e14d 100644
--- a/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java
@@ -27,10 +27,8 @@ import org.apache.cassandra.auth.DataResource;
 import org.apache.cassandra.auth.IResource;
 import org.apache.cassandra.auth.Permission;
 import org.apache.cassandra.cql3.*;
-import org.apache.cassandra.db.Keyspace;
 import org.apache.cassandra.db.marshal.*;
 import org.apache.cassandra.exceptions.AlreadyExistsException;
-import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.schema.*;
 import org.apache.cassandra.schema.Keyspaces.KeyspacesDiff;
 import org.apache.cassandra.service.ClientState;
@@ -207,10 +205,22 @@ public final class CreateTableStatement extends AlterSchemaStatement
             clusteringTypes.add(reverse ? ReversedType.getInstance(type.getType()) : type.getType());
         });
 
-        // If we give a clustering order, we must explicitly do so for all aliases and in the order of the PK
-        // This wasn't previously enforced because of a bug in the implementation
-        if (!clusteringOrder.isEmpty() && !clusteringColumns.equals(new ArrayList<>(clusteringOrder.keySet())))
-            throw ire("Clustering key columns must exactly match columns in CLUSTERING ORDER BY directive");
+        if (clusteringOrder.size() > clusteringColumns.size())
+            throw ire("Only clustering columns can be defined in CLUSTERING ORDER directive");
+
+        int n = 0;
+        for (ColumnIdentifier id : clusteringOrder.keySet())
+        {
+            ColumnIdentifier c = clusteringColumns.get(n);
+            if (!id.equals(c))
+            {
+                if (clusteringOrder.containsKey(c))
+                    throw ire("The order of columns in the CLUSTERING ORDER directive must match that of the clustering columns (%s must appear before %s)", c, id);
+                else
+                    throw ire("Missing CLUSTERING ORDER for column %s", c);
+            }
+            ++n;
+        }
 
         // Static columns only make sense if we have at least one clustering column. Otherwise everything is static anyway
         if (clusteringColumns.isEmpty() && !staticColumns.isEmpty())


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org