cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xe...@apache.org
Subject git commit: (cql3) fix defining more than one PK to be invalid patch by Sylvain Lebresne; reviewed by Pavel Yaskevich for CASSANDRA-4477
Date Wed, 15 Aug 2012 10:12:30 GMT
Updated Branches:
  refs/heads/trunk afbbe1abc -> fe784f58e


(cql3) fix defining more than one PK to be invalid
patch by Sylvain Lebresne; reviewed by Pavel Yaskevich for CASSANDRA-4477


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/fe784f58
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/fe784f58
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/fe784f58

Branch: refs/heads/trunk
Commit: fe784f58e6520c6180e5c02e2b919f3d0edc49d1
Parents: afbbe1a
Author: Pavel Yaskevich <xedin@apache.org>
Authored: Wed Aug 15 12:57:20 2012 +0300
Committer: Pavel Yaskevich <xedin@apache.org>
Committed: Wed Aug 15 12:57:20 2012 +0300

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 src/java/org/apache/cassandra/cql3/Cql.g           |    6 ++--
 .../statements/CreateColumnFamilyStatement.java    |   17 ++++++++-------
 3 files changed, 13 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/fe784f58/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5d878bc..5a2848d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -35,6 +35,7 @@
  * (cql3) Add support for row key composites (CASSANDRA-4179)
  * improve DynamicEndpointSnitch by using reservoir sampling (CASSANDRA-4038)
  * (cql3) Add support for 2ndary indexes (CASSANDRA-3680)
+ * (cql3) fix defining more than one PK to be invalid (CASSANDRA-4477)
 
 
 1.1.4

http://git-wip-us.apache.org/repos/asf/cassandra/blob/fe784f58/src/java/org/apache/cassandra/cql3/Cql.g
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g
index cb5a265..5a67820 100644
--- a/src/java/org/apache/cassandra/cql3/Cql.g
+++ b/src/java/org/apache/cassandra/cql3/Cql.g
@@ -370,13 +370,13 @@ cfamDefinition[CreateColumnFamilyStatement.RawStatement expr]
     ;
 
 cfamColumns[CreateColumnFamilyStatement.RawStatement expr]
-    : k=cident v=comparatorType { $expr.addDefinition(k, v); } (K_PRIMARY K_KEY { $expr.addKeyAlias(k);
})?
+    : k=cident v=comparatorType { $expr.addDefinition(k, v); } (K_PRIMARY K_KEY { $expr.addKeyAliases(Collections.singletonList(k));
})?
     | K_PRIMARY K_KEY '(' pkDef[expr] (',' c=cident { $expr.addColumnAlias(c); } )* ')'
     ;
 
 pkDef[CreateColumnFamilyStatement.RawStatement expr]
-    : k=cident { $expr.addKeyAlias(k); }
-    | '(' k1=cident { $expr.addKeyAlias(k1); } ( ',' kn=cident { $expr.addKeyAlias(kn); }
)* ')'
+    : k=cident { $expr.addKeyAliases(Collections.singletonList(k)); }
+    | '(' { List<ColumnIdentifier> l = new ArrayList<ColumnIdentifier>(); } k1=cident
{ l.add(k1); } ( ',' kn=cident { l.add(kn); } )* ')' { $expr.addKeyAliases(l); }
     ;
 
 cfamProperty[CreateColumnFamilyStatement.RawStatement expr]

http://git-wip-us.apache.org/repos/asf/cassandra/blob/fe784f58/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 0f14ba1..b8618b0 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
@@ -133,7 +133,7 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
         private final Map<ColumnIdentifier, ParsedType> definitions = new HashMap<ColumnIdentifier,
ParsedType>();
         private final CFPropDefs properties = new CFPropDefs();
 
-        private final List<ColumnIdentifier> keyAliases = new ArrayList<ColumnIdentifier>();
+        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>();
 
@@ -181,12 +181,13 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
                     stmt.columns.put(id, pt.getType()); // we'll remove what is not a column
below
                 }
 
-                // Ensure that at least one key has been specified.
-                if (keyAliases.size() == 0)
-                    throw new InvalidRequestException("You must specify a PRIMARY KEY");
+                if (keyAliases.size() != 1)
+                    throw new InvalidRequestException("You must specify one and only one
PRIMARY KEY");
 
-                List<AbstractType<?>> keyTypes = new ArrayList<AbstractType<?>>(keyAliases.size());
-                for (ColumnIdentifier alias : keyAliases)
+                List<ColumnIdentifier> kAliases = keyAliases.get(0);
+
+                List<AbstractType<?>> keyTypes = new ArrayList<AbstractType<?>>(kAliases.size());
+                for (ColumnIdentifier alias : kAliases)
                 {
                     stmt.keyAliases.add(alias.key);
                     AbstractType<?> t = getTypeAndRemove(stmt.columns, alias);
@@ -323,9 +324,9 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
             definitions.put(def, type);
         }
 
-        public void addKeyAlias(ColumnIdentifier alias)
+        public void addKeyAliases(List<ColumnIdentifier> aliases)
         {
-            keyAliases.add(alias);
+            keyAliases.add(aliases);
         }
 
         public void addColumnAlias(ColumnIdentifier alias)


Mime
View raw message