You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2012/10/31 15:32:45 UTC
git commit: Force provided columns in clustering key order in
'CLUSTERING ORDER BY'
Updated Branches:
refs/heads/trunk da3ab363b -> 7a1a7b9b7
Force provided columns in clustering key order in 'CLUSTERING ORDER BY'
patch by slebresne; reviewed by jbellis for CASSANDRA-4881
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/7a1a7b9b
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/7a1a7b9b
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/7a1a7b9b
Branch: refs/heads/trunk
Commit: 7a1a7b9b790f786a7b091406cac322fc861085dc
Parents: da3ab36
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Wed Oct 31 15:32:10 2012 +0100
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Wed Oct 31 15:32:10 2012 +0100
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../statements/CreateColumnFamilyStatement.java | 25 ++++++++++++++-
2 files changed, 25 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/7a1a7b9b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 12cc92a..48cb945 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -43,6 +43,7 @@
* Fix binary protocol NEW_NODE event (CASSANDRA-4679)
* Fix potential infinite loop in tombstone compaction (CASSANDRA-4781)
* Remove system tables accounting from schema (CASSANDRA-4850)
+ * Force provided columns in clustering key order in 'CLUSTERING ORDER BY' (CASSANDRA-4881)
Merged from 1.1:
* add get[Row|Key]CacheEntries to CacheServiceMBean (CASSANDRA-4859)
* fix get_paged_slice to wrap to next row correctly (CASSANDRA-4816)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/7a1a7b9b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
index 1775398..b8ea732 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.cql3.statements;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -144,7 +145,7 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
private final List<List<ColumnIdentifier>> keyAliases = new ArrayList<List<ColumnIdentifier>>();
private final List<ColumnIdentifier> columnAliases = new ArrayList<ColumnIdentifier>();
- private final Map<ColumnIdentifier, Boolean> definedOrdering = new HashMap<ColumnIdentifier, Boolean>();
+ private final Map<ColumnIdentifier, Boolean> definedOrdering = new LinkedHashMap<ColumnIdentifier, Boolean>(); // Insertion ordering is important
private boolean useCompactStorage;
private final Multiset<ColumnIdentifier> definedNames = HashMultiset.create(1);
@@ -305,6 +306,28 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
: CFDefinition.definitionType;
}
+
+ // If we give a clustering order, we must explicitely do so for all aliases and in the order of the PK
+ if (!definedOrdering.isEmpty())
+ {
+ if (definedOrdering.size() > columnAliases.size())
+ throw new InvalidRequestException("Too much columns provided for CLUSTERING ORDER");
+
+ int i = 0;
+ for (ColumnIdentifier id : definedOrdering.keySet())
+ {
+ ColumnIdentifier c = columnAliases.get(i);
+ if (!id.equals(c))
+ {
+ if (definedOrdering.containsKey(c))
+ throw new InvalidRequestException(String.format("The order of columns in the CLUSTERING ORDER directive must be the one of the clustering key (%s must appear before %s)", c, id));
+ else
+ throw new InvalidRequestException(String.format("Missing CLUSTERING ORDER for column %s", c));
+ }
+ ++i;
+ }
+ }
+
return new ParsedStatement.Prepared(stmt);
}