cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ble...@apache.org
Subject cassandra git commit: Check column names in IN restrictions
Date Thu, 20 Aug 2015 11:50:27 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 de2e0a6c9 -> 62fc314c5


Check column names in IN restrictions

patch by Benjamin Lerer; reviewed by Robert Stupp  for CASSANDRA-10043


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

Branch: refs/heads/cassandra-2.2
Commit: 62fc314c582e9f218987e96c79db6c1aa0ba6c1e
Parents: de2e0a6
Author: blerer <benjamin.lerer@datastax.com>
Authored: Thu Aug 20 13:45:54 2015 +0200
Committer: blerer <benjamin.lerer@datastax.com>
Committed: Thu Aug 20 13:45:54 2015 +0200

----------------------------------------------------------------------
 .../cassandra/cql3/SingleColumnRelation.java       |  2 +-
 .../org/apache/cassandra/cql3/TokenRelation.java   |  2 +-
 .../operations/SelectMultiColumnRelationTest.java  | 12 ++++++++++++
 .../operations/SelectOrderedPartitionerTest.java   | 10 ++++++++++
 .../operations/SelectSingleColumnRelationTest.java | 17 +++++++++++++++++
 5 files changed, 41 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/62fc314c/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java b/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
index c4c48aa..b206631 100644
--- a/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
+++ b/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
@@ -153,7 +153,7 @@ public final class SingleColumnRelation extends Relation
     protected Restriction newINRestriction(CFMetaData cfm,
                                            VariableSpecifications boundNames) throws InvalidRequestException
     {
-        ColumnDefinition columnDef = cfm.getColumnDefinition(getEntity().prepare(cfm));
+        ColumnDefinition columnDef = toColumnDefinition(cfm, entity);
         List<? extends ColumnSpecification> receivers = toReceivers(columnDef);
         List<Term> terms = toTerms(receivers, inValues, cfm.ksName, boundNames);
         if (terms == null)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/62fc314c/src/java/org/apache/cassandra/cql3/TokenRelation.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/TokenRelation.java b/src/java/org/apache/cassandra/cql3/TokenRelation.java
index 5896fae..46a812c 100644
--- a/src/java/org/apache/cassandra/cql3/TokenRelation.java
+++ b/src/java/org/apache/cassandra/cql3/TokenRelation.java
@@ -109,7 +109,7 @@ public final class TokenRelation extends Relation
     @Override
     public String toString()
     {
-        return String.format("token(%s) %s %s", Tuples.tupleToString(entities), relationType,
value);
+        return String.format("token%s %s %s", Tuples.tupleToString(entities), relationType,
value);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/62fc314c/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 84343a7..b3232d5 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
@@ -1011,4 +1011,16 @@ public class SelectMultiColumnRelationTest extends CQLTester
                    row(0, 0, 2, 2, 2),
                    row(0, 0, 3, 3, 3));
     }
+
+    @Test
+    public void testInvalidColumnNames() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))");
+        assertInvalidMessage("Undefined name e in where clause ('(b, e) = (0, 0)')", "SELECT
* FROM %s WHERE (b, e) = (0, 0)");
+        assertInvalidMessage("Undefined name e in where clause ('(b, e) IN ((0, 1), (2, 4))')",
"SELECT * FROM %s WHERE (b, e) IN ((0, 1), (2, 4))");
+        assertInvalidMessage("Undefined name e in where clause ('(b, e) > (0, 1)')", "SELECT
* FROM %s WHERE (b, e) > (0, 1) and b <= 2");
+        assertInvalidMessage("Aliases aren't allowed in the where clause ('(b, e) = (0, 0)')",
"SELECT c AS e FROM %s WHERE (b, e) = (0, 0)");
+        assertInvalidMessage("Aliases aren't allowed in the where clause ('(b, e) IN ((0,
1), (2, 4))')", "SELECT c AS e FROM %s WHERE (b, e) IN ((0, 1), (2, 4))");
+        assertInvalidMessage("Aliases aren't allowed in the where clause ('(b, e) > (0,
1)')", "SELECT c AS e FROM %s WHERE (b, e) > (0, 1) and b <= 2");
+    }
  }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/62fc314c/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderedPartitionerTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderedPartitionerTest.java
b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderedPartitionerTest.java
index 5152ba9..2ffa15d 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderedPartitionerTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderedPartitionerTest.java
@@ -478,4 +478,14 @@ public class SelectOrderedPartitionerTest extends CQLTester
 
         assertInvalid("SELECT * FROM %s WHERE k >= -1 AND k < 1");
     }
+
+    @Test
+    public void testTokenFunctionWithInvalidColumnNames() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY ((a, b), c))");
+        assertInvalidMessage("Undefined name e in where clause ('token(a, e) = token(0, 0)')",
"SELECT * FROM %s WHERE token(a, e) = token(0, 0)");
+        assertInvalidMessage("Undefined name e in where clause ('token(a, e) > token(0,
1)')", "SELECT * FROM %s WHERE token(a, e) > token(0, 1)");
+        assertInvalidMessage("Aliases aren't allowed in the where clause ('token(a, e) =
token(0, 0)')", "SELECT b AS e FROM %s WHERE token(a, e) = token(0, 0)");
+        assertInvalidMessage("Aliases aren't allowed in the where clause ('token(a, e) >
token(0, 1)')", "SELECT b AS e FROM %s WHERE token(a, e) > token(0, 1)");
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/62fc314c/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 f1bce45..31a84e4 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
@@ -588,4 +588,21 @@ public class SelectSingleColumnRelationTest extends CQLTester
         assertInvalidMessage("Multi-column relations can only be applied to clustering columns
but was applied to: a",
                              "SELECT * FROM %s WHERE (a, b) >= (1, 1) and a = 1");
     }
+
+    @Test
+    public void testInvalidColumnNames() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b int, c map<int, int>, PRIMARY KEY (a,
b))");
+        assertInvalidMessage("Undefined name d in where clause ('d = 0')", "SELECT * FROM
%s WHERE d = 0");
+        assertInvalidMessage("Undefined name d in where clause ('d IN [0, 1]')", "SELECT
* FROM %s WHERE d IN (0, 1)");
+        assertInvalidMessage("Undefined name d in where clause ('d > 0')", "SELECT * FROM
%s WHERE d > 0 and d <= 2");
+        assertInvalidMessage("Undefined name d in where clause ('d CONTAINS 0')", "SELECT
* FROM %s WHERE d CONTAINS 0");
+        assertInvalidMessage("Undefined name d in where clause ('d CONTAINS KEY 0')", "SELECT
* FROM %s WHERE d CONTAINS KEY 0");
+        assertInvalidMessage("Aliases aren't allowed in the where clause ('d = 0')", "SELECT
a AS d FROM %s WHERE d = 0");
+        assertInvalidMessage("Aliases aren't allowed in the where clause ('d IN [0, 1]')",
"SELECT b AS d FROM %s WHERE d IN (0, 1)");
+        assertInvalidMessage("Aliases aren't allowed in the where clause ('d > 0')", "SELECT
b AS d FROM %s WHERE d > 0 and d <= 2");
+        assertInvalidMessage("Aliases aren't allowed in the where clause ('d CONTAINS 0')",
"SELECT c AS d FROM %s WHERE d CONTAINS 0");
+        assertInvalidMessage("Aliases aren't allowed in the where clause ('d CONTAINS KEY
0')", "SELECT c AS d FROM %s WHERE d CONTAINS KEY 0");
+        assertInvalidMessage("Undefined name d in selection clause", "SELECT d FROM %s WHERE
a = 0");
+    }
 }


Mime
View raw message