cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ble...@apache.org
Subject [1/4] cassandra git commit: Add support for GROUP BY to SELECT statement
Date Thu, 04 Aug 2016 15:13:49 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 90ba50f6a -> 4205011c0


http://git-wip-us.apache.org/repos/asf/cassandra/blob/4205011c/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
index 7f43c6b..19f798f 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
@@ -80,8 +80,12 @@ public class SelectMultiColumnRelationTest extends CQLTester
                                  "SELECT * FROM %s WHERE a = 0 AND (c, d) > (?, ?)", 0,
0);
 
             // Nulls
-            assertInvalidMessage("Invalid null value in condition for columns: [b, c, d]",
+            assertInvalidMessage("Invalid null value for column d",
+                                 "SELECT * FROM %s WHERE a = 0 AND (b, c, d) = (?, ?, ?)",
1, 2, null);
+            assertInvalidMessage("Invalid null value for column d",
                                  "SELECT * FROM %s WHERE a = 0 AND (b, c, d) IN ((?, ?, ?))",
1, 2, null);
+            assertInvalidMessage("Invalid null value in condition for columns: [b, c, d]",
+                                 "SELECT * FROM %s WHERE a = 0 AND (b, c, d) IN ((?, ?, ?),
(?, ?, ?))", 1, 2, null, 2, 1 ,4);
 
             // Wrong type for 'd'
             assertInvalid("SELECT * FROM %s WHERE a = 0 AND (b, c, d) = (?, ?, ?)", 1, 2,
"foobar");
@@ -955,16 +959,17 @@ public class SelectMultiColumnRelationTest extends CQLTester
                    row(0, 0, 1, 1, 1, 5));
 
         assertInvalidMessage("Partition key parts: b must be restricted as other parts are",
-                             "SELECT * FROM %s WHERE a = ? AND (c, d) IN ((?, ?)) ALLOW FILTERING",
0, 1, 1);
+                             "SELECT * FROM %s WHERE a = ? AND (c, d) IN ((?, ?), (?, ?))
ALLOW FILTERING", 0, 1, 1, 2, 1);
 
         assertInvalidMessage("Partition key parts: b must be restricted as other parts are",
                              "SELECT * FROM %s WHERE a = ? AND (c, d) >= (?, ?) ALLOW
FILTERING", 0, 1, 1);
 
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND b = ? AND (c) IN ((?)) AND f
= ?", 0, 0, 1, 5),
                    row(0, 0, 1, 1, 1, 5));
+
         assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
-                             "SELECT * FROM %s WHERE a = ? AND (c) IN ((?)) AND f = ?", 0,
1, 5);
-        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (c) IN ((?)) AND f = ? ALLOW
FILTERING", 0, 1, 5),
+                             "SELECT * FROM %s WHERE a = ? AND (c) IN ((?), (?)) AND f =
?", 0, 1, 3, 5);
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND (c) IN ((?), (?)) AND f = ?
ALLOW FILTERING", 0, 1, 3, 5),
                    row(0, 0, 1, 1, 1, 5));
 
         assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4205011c/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
index 0e2517b..a52ce66 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
@@ -499,14 +499,14 @@ public class SelectSingleColumnRelationTest extends CQLTester
                    row(0, 0, 1, 1, 1, 5));
 
         assertInvalidMessage("Partition key parts: b must be restricted as other parts are",
-                             "SELECT * FROM %s WHERE a = ? AND c IN (?) AND  d IN (?) ALLOW
FILTERING", 0, 1, 1);
+                             "SELECT * FROM %s WHERE a = ? AND c IN (?, ?) AND  d IN (?)
ALLOW FILTERING", 0, 0, 1, 1);
 
         assertInvalidMessage("Partition key parts: b must be restricted as other parts are",
                              "SELECT * FROM %s WHERE a = ? AND (c, d) >= (?, ?) ALLOW
FILTERING", 0, 1, 1);
 
         assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
-                             "SELECT * FROM %s WHERE a = ? AND c IN (?) AND f = ?", 0, 1,
5);
-        assertRows(execute("SELECT * FROM %s WHERE a = ? AND c IN (?) AND f = ? ALLOW FILTERING",
0, 1, 5),
+                             "SELECT * FROM %s WHERE a = ? AND c IN (?, ?) AND f = ?", 0,
0, 1, 5);
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND c IN (?, ?) AND f = ? ALLOW
FILTERING", 0, 1, 3, 5),
                    row(0, 0, 1, 1, 1, 5));
 
         assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
@@ -516,8 +516,8 @@ public class SelectSingleColumnRelationTest extends CQLTester
                    row(0, 0, 2, 0, 0, 5));
 
         assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
-                             "SELECT * FROM %s WHERE a = ? AND c IN (?) AND d IN (?) AND
f = ?", 0, 1, 0, 3);
-        assertRows(execute("SELECT * FROM %s WHERE a = ? AND c IN (?) AND d IN (?) AND f
= ? ALLOW FILTERING", 0, 1, 0, 3),
+                             "SELECT * FROM %s WHERE a = ? AND c IN (?, ?) AND d IN (?) AND
f = ?", 0, 1, 3, 0, 3);
+        assertRows(execute("SELECT * FROM %s WHERE a = ? AND c IN (?, ?) AND d IN (?) AND
f = ? ALLOW FILTERING", 0, 1, 3, 0, 3),
                    row(0, 0, 1, 0, 0, 3));
 
         assertInvalidMessage("Partition key parts: b must be restricted as other parts are",

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4205011c/test/unit/org/apache/cassandra/db/aggregation/GroupMakerTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/aggregation/GroupMakerTest.java b/test/unit/org/apache/cassandra/db/aggregation/GroupMakerTest.java
new file mode 100644
index 0000000..6a55921
--- /dev/null
+++ b/test/unit/org/apache/cassandra/db/aggregation/GroupMakerTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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.db.aggregation;
+
+import java.nio.ByteBuffer;
+
+import org.junit.Test;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.Clustering;
+import org.apache.cassandra.db.ClusteringComparator;
+import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.db.marshal.Int32Type;
+import org.apache.cassandra.db.marshal.ReversedType;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class GroupMakerTest
+{
+    @Test
+    public void testIsNewGroupWithClusteringColumns()
+    {
+        ClusteringComparator comparator = newComparator(false, false, false);
+        GroupMaker groupMaker = GroupMaker.newInstance(comparator, 2);
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 1)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 2)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 3)));
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 2, 1)));
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 1)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 2)));
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 1)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 2)));
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(2), clustering(2, 2, 1)));
+    }
+
+    @Test
+    public void testIsNewGroupWithOneClusteringColumnsPrefix()
+    {
+        ClusteringComparator comparator = newComparator(false, false, false);
+        GroupMaker groupMaker = GroupMaker.newInstance(comparator, 1);
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 1)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 2)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 3)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 2, 1)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 1)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 2)));
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 1)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 2)));
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(2), clustering(2, 2, 1)));
+    }
+
+    @Test
+    public void testIsNewGroupWithReversedClusteringColumns()
+    {
+        ClusteringComparator comparator = newComparator(true, true, true);
+
+        GroupMaker groupMaker = GroupMaker.newInstance(comparator, 2);
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 2)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 1)));
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 2, 1)));
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 3)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 2)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 1)));
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 2)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 1)));
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(2), clustering(2, 2, 1)));
+    }
+
+    @Test
+    public void testIsNewGroupWithOneReversedClusteringColumns()
+    {
+        ClusteringComparator comparator = newComparator(true, false, false);
+
+        GroupMaker groupMaker = GroupMaker.newInstance(comparator, 2);
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 1)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 2)));
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 2, 1)));
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 1)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 2)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 3)));
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 1)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 2)));
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(2), clustering(2, 2, 1)));
+    }
+
+    @Test
+    public void testIsNewGroupWithStaticClusteringColumns()
+    {
+        ClusteringComparator comparator = newComparator(false, false, false);
+        GroupMaker groupMaker = GroupMaker.newInstance(comparator, 2);
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 1)));
+        assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 2)));
+
+        assertTrue(groupMaker.isNewGroup(partitionKey(2), Clustering.STATIC_CLUSTERING));
+        assertTrue(groupMaker.isNewGroup(partitionKey(3), Clustering.STATIC_CLUSTERING));
+        assertTrue(groupMaker.isNewGroup(partitionKey(4), clustering(1, 1, 2)));
+    }
+
+    @Test
+    public void testIsNewGroupWithOnlyPartitionKeyComponents()
+    {
+        ClusteringComparator comparator = newComparator(false, false, false);
+        GroupMaker goupMaker = GroupMaker.newInstance(comparator, 2);
+
+        assertTrue(goupMaker.isNewGroup(partitionKey(1, 1), clustering(1, 1, 1)));
+        assertFalse(goupMaker.isNewGroup(partitionKey(1, 1), clustering(1, 1, 2)));
+
+        assertTrue(goupMaker.isNewGroup(partitionKey(1, 2), clustering(1, 1, 2)));
+        assertTrue(goupMaker.isNewGroup(partitionKey(1, 2), clustering(2, 2, 2)));
+
+        assertTrue(goupMaker.isNewGroup(partitionKey(2, 2), clustering(1, 1, 2)));
+    }
+
+    private static DecoratedKey partitionKey(int... components)
+    {
+        ByteBuffer buffer = ByteBuffer.allocate(components.length * 4);
+        for (int component : components)
+        {
+            buffer.putInt(component);
+        }
+        buffer.flip();
+        return DatabaseDescriptor.getPartitioner().decorateKey(buffer);
+    }
+
+    private static Clustering clustering(int... components)
+    {
+        return Clustering.make(toByteBufferArray(components));
+    }
+
+    private static ByteBuffer[] toByteBufferArray(int[] values)
+    {
+        ByteBuffer[] buffers = new ByteBuffer[values.length];
+
+        for (int i = 0; i < values.length; i++)
+        {
+            buffers[i] = Int32Type.instance.decompose(values[i]);
+        }
+
+        return buffers;
+    }
+
+    private static ClusteringComparator newComparator(boolean... reversed)
+    {
+        AbstractType<?>[] types = new AbstractType<?>[reversed.length];
+        for (int i = 0, m = reversed.length; i < m; i++)
+            types[i] = reversed[i] ? ReversedType.getInstance(Int32Type.instance) : Int32Type.instance;
+
+        return new ClusteringComparator(types);
+    }
+}


Mime
View raw message