Fix filtering on non-primary key columns for thrift static column families

patch by Benjamin Lerer; reviewed by Sam Tunnicliffe for CASSANDRA-6377


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

Branch: refs/heads/cassandra-3.5
Commit: 90fd8deed0d1eaa12906bc80aaf54daf837f3a81
Parents: 0934542
Author: Benjamin Lerer <b.le...@gmail.com>
Authored: Fri Mar 4 22:05:13 2016 +0100
Committer: Benjamin Lerer <b.le...@gmail.com>
Committed: Fri Mar 4 22:05:13 2016 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |   2 +
 .../cassandra/cql3/SingleColumnRelation.java    |   4 -
 .../cql3/restrictions/AbstractRestriction.java  |   4 +-
 .../restrictions/StatementRestrictions.java     |  25 +-
 .../cql3/statements/SelectStatement.java        |   8 +-
 .../db/index/SecondaryIndexManager.java         |  43 +-
 .../entities/FrozenCollectionsTest.java         |   4 +-
 .../validation/entities/SecondaryIndexTest.java |   2 +-
 .../cql3/validation/entities/UFAuthTest.java    |  11 -
 .../entities/UFIdentificationTest.java          |   6 +-
 .../SelectMultiColumnRelationTest.java          |  31 +-
 .../SelectSingleColumnRelationTest.java         |  34 +-
 .../cql3/validation/operations/SelectTest.java  | 829 ++++++++++++++++++-
 .../db/index/PerRowSecondaryIndexTest.java      |   4 +-
 14 files changed, 915 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index db6d79d..5631a28 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 2.2.6
+ * Fix filtering on non-primary key columns for thrift static column families
+   (CASSANDRA-6377)
  * Only log yaml config once, at startup (CASSANDRA-11217)
  * Preserve order for preferred SSL cipher suites (CASSANDRA-11164)
  * Reference leak with parallel repairs on the same table (CASSANDRA-11215)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/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 b206631..dbae5f0 100644
--- a/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
+++ b/src/java/org/apache/cassandra/cql3/SingleColumnRelation.java
@@ -196,10 +196,6 @@ public final class SingleColumnRelation extends Relation
     {
         ColumnSpecification receiver = columnDef;
 
-        checkFalse(columnDef.isCompactValue(),
-                   "Predicates on the non-primary-key column (%s) of a COMPACT 
table are not yet supported",
-                   columnDef.name);
-
         if (isIN())
         {
             // We only allow IN on the row key and the clustering key so far, 
never on non-PK columns, and this even if

http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/src/java/org/apache/cassandra/cql3/restrictions/AbstractRestriction.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/restrictions/AbstractRestriction.java 
b/src/java/org/apache/cassandra/cql3/restrictions/AbstractRestriction.java
index dac7203..385bfbc 100644
--- a/src/java/org/apache/cassandra/cql3/restrictions/AbstractRestriction.java
+++ b/src/java/org/apache/cassandra/cql3/restrictions/AbstractRestriction.java
@@ -93,8 +93,8 @@ abstract class AbstractRestriction  implements Restriction
                                                      ByteBuffer value)
                                                      throws 
InvalidRequestException
     {
-        checkNotNull(value, "Unsupported null value for indexed column %s", 
columnSpec.name);
-        checkBindValueSet(value, "Unsupported unset value for indexed column 
%s", columnSpec.name);
+        checkNotNull(value, "Unsupported null value for column %s", 
columnSpec.name);
+        checkBindValueSet(value, "Unsupported unset value for column %s", 
columnSpec.name);
         checkFalse(value.remaining() > 0xFFFF, "Index expression values may 
not be larger than 64K");
         return value;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java 
b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java
index 55c6808..e0cf743 100644
--- a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java
+++ b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java
@@ -36,6 +36,7 @@ import 
org.apache.cassandra.exceptions.InvalidRequestException;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
+import static org.apache.cassandra.config.ColumnDefinition.toIdentifiers;
 import static 
org.apache.cassandra.cql3.statements.RequestValidations.checkFalse;
 import static 
org.apache.cassandra.cql3.statements.RequestValidations.checkNotNull;
 import static 
org.apache.cassandra.cql3.statements.RequestValidations.checkTrue;
@@ -46,6 +47,11 @@ import static 
org.apache.cassandra.cql3.statements.RequestValidations.invalidReq
  */
 public final class StatementRestrictions
 {
+    public static final String REQUIRES_ALLOW_FILTERING_MESSAGE =
+            "Cannot execute this query as it might involve data filtering and 
" +
+            "thus may have unpredictable performance. If you want to execute " 
+
+            "this query despite the performance unpredictability, use ALLOW 
FILTERING";
+
     /**
      * The Column Family meta data
      */
@@ -101,10 +107,11 @@ public final class StatementRestrictions
     }
 
     public StatementRestrictions(CFMetaData cfm,
-            List<Relation> whereClause,
-            VariableSpecifications boundNames,
-            boolean selectsOnlyStaticColumns,
-            boolean selectACollection) throws InvalidRequestException
+                                 List<Relation> whereClause,
+                                 VariableSpecifications boundNames,
+                                 boolean selectsOnlyStaticColumns,
+                                 boolean selectACollection,
+                                 boolean useFiltering)
     {
         this.cfm = cfm;
         this.partitionKeyRestrictions = new 
PrimaryKeyRestrictionSet(cfm.getKeyValidatorAsCType());
@@ -155,6 +162,16 @@ public final class StatementRestrictions
         // there is restrictions not covered by the PK.
         if (!nonPrimaryKeyRestrictions.isEmpty())
         {
+            if (!hasQueriableIndex)
+            {
+                // Filtering for non-index query is only supported for thrift 
static CFs
+                if (cfm.comparator.isDense() ||  cfm.comparator.isCompound())
+                    throw invalidRequest("Predicates on non-primary-key 
columns (%s) are not yet supported for non secondary index queries",
+                                         Joiner.on(", 
").join(toIdentifiers(nonPrimaryKeyRestrictions.getColumnDefs())));
+
+                if (!useFiltering)
+                    throw invalidRequest(REQUIRES_ALLOW_FILTERING_MESSAGE);
+            }
             usesSecondaryIndexing = true;
             indexRestrictions.add(nonPrimaryKeyRestrictions);
         }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 848b3a6..291e3e4 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -604,7 +604,6 @@ public class SelectStatement implements CQLStatement
         SecondaryIndexManager secondaryIndexManager = cfs.indexManager;
 
         List<IndexExpression> expressions = 
restrictions.getIndexExpressions(secondaryIndexManager, options);
-
         secondaryIndexManager.validateIndexSearchersForQuery(expressions);
 
         return expressions;
@@ -853,7 +852,8 @@ public class SelectStatement implements CQLStatement
                                                  whereClause,
                                                  boundNames,
                                                  
selection.containsOnlyStaticColumns(),
-                                                 
selection.containsACollection());
+                                                 
selection.containsACollection(),
+                                                 parameters.allowFiltering);
             }
             catch (UnrecognizedEntityException e)
             {
@@ -1003,9 +1003,7 @@ public class SelectStatement implements CQLStatement
                 //  - Have more than one IndexExpression
                 //  - Have no index expression and the column filter is not 
the identity
                 checkFalse(restrictions.needFiltering(),
-                           "Cannot execute this query as it might involve data 
filtering and " +
-                           "thus may have unpredictable performance. If you 
want to execute " +
-                           "this query despite the performance 
unpredictability, use ALLOW FILTERING");
+                           
StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE);
             }
 
             // We don't internally support exclusive slice bounds on 
non-composite tables. To deal with it we do an

http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java 
b/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
index 6df8616..f7abc54 100644
--- a/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
+++ b/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
@@ -38,6 +38,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Joiner;
+
 import org.apache.cassandra.config.ColumnDefinition;
 import org.apache.cassandra.config.IndexType;
 import org.apache.cassandra.db.Cell;
@@ -49,6 +51,7 @@ import org.apache.cassandra.db.Row;
 import org.apache.cassandra.db.SystemKeyspace;
 import org.apache.cassandra.db.compaction.CompactionManager;
 import org.apache.cassandra.db.composites.CellName;
+import org.apache.cassandra.db.composites.CellNameType;
 import org.apache.cassandra.db.filter.ExtendedFilter;
 import org.apache.cassandra.exceptions.InvalidRequestException;
 import org.apache.cassandra.io.sstable.ReducingKeyIterator;
@@ -595,8 +598,15 @@ public class SecondaryIndexManager
             }
         }
 
-        if (!haveSupportedIndexLookup)
+        CellNameType comparator = baseCfs.metadata.comparator;
+        // For thrift static CFs we can use filtering if no indexes can be used
+        if (!haveSupportedIndexLookup && (comparator.isDense() ||  
comparator.isCompound()))
         {
+            if (expressionsByIndexType.isEmpty())
+                throw new InvalidRequestException(
+                    String.format("Predicates on non-primary-key columns (%s) 
are not yet supported for non secondary index queries",
+                                  Joiner.on(", 
").join(getColumnNames(clause))));
+
             // build the error message
             int i = 0;
             StringBuilder sb = new StringBuilder("No secondary indexes on the 
restricted columns support the provided operators: ");
@@ -607,15 +617,7 @@ public class SecondaryIndexManager
                     if (i++ > 0)
                         sb.append(", ");
                     sb.append("'");
-                    String columnName;
-                    try
-                    {
-                        columnName = ByteBufferUtil.string(expression.column);
-                    }
-                    catch (CharacterCodingException ex)
-                    {
-                        columnName = "<unprintable>";
-                    }
+                    String columnName = getColumnName(expression);
                     sb.append(columnName).append(" 
").append(expression.operator).append(" <value>").append("'");
                 }
             }
@@ -624,6 +626,27 @@ public class SecondaryIndexManager
         }
     }
 
+    private static String getColumnName(IndexExpression expression)
+    {
+        try
+        {
+            return ByteBufferUtil.string(expression.column);
+        }
+        catch (CharacterCodingException ex)
+        {
+            return "<unprintable>";
+        }
+    }
+
+    private static Set<String> getColumnNames(List<IndexExpression> 
expressions)
+    {
+        Set<String> columnNames = new HashSet<>();
+        for (IndexExpression expression : expressions)
+            columnNames.add(getColumnName(expression));
+
+        return columnNames;
+    }
+
     /**
      * Performs a search across a number of column indexes
      *

http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/test/unit/org/apache/cassandra/cql3/validation/entities/FrozenCollectionsTest.java
----------------------------------------------------------------------
diff --git 
a/test/unit/org/apache/cassandra/cql3/validation/entities/FrozenCollectionsTest.java
 
b/test/unit/org/apache/cassandra/cql3/validation/entities/FrozenCollectionsTest.java
index 857139d..b590843 100644
--- 
a/test/unit/org/apache/cassandra/cql3/validation/entities/FrozenCollectionsTest.java
+++ 
b/test/unit/org/apache/cassandra/cql3/validation/entities/FrozenCollectionsTest.java
@@ -631,10 +631,10 @@ public class FrozenCollectionsTest extends CQLTester
         assertInvalidMessage("Cannot restrict clustering columns by a CONTAINS 
relation without a secondary index",
                              "SELECT * FROM %s WHERE b CONTAINS ? ALLOW 
FILTERING", 1);
 
-        assertInvalidMessage("No secondary indexes on the restricted columns 
support the provided operator",
+        assertInvalidMessage("Predicates on non-primary-key columns (d) are 
not yet supported for non secondary index queries",
                              "SELECT * FROM %s WHERE d CONTAINS KEY ?", 1);
 
-        assertInvalidMessage("No secondary indexes on the restricted columns 
support the provided operator",
+        assertInvalidMessage("Predicates on non-primary-key columns (d) are 
not yet supported for non secondary index queries",
                              "SELECT * FROM %s WHERE d CONTAINS KEY ? ALLOW 
FILTERING", 1);
 
         assertInvalidMessage("Cannot restrict clustering columns by a CONTAINS 
relation without a secondary index",

http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
----------------------------------------------------------------------
diff --git 
a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
 
b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
index b8f6b9f..365abe0 100644
--- 
a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
+++ 
b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
@@ -109,7 +109,7 @@ public class SecondaryIndexTest extends CQLTester
             execute("DROP INDEX " + indexName);
         }
 
-        assertInvalidMessage("No secondary indexes on the restricted columns 
support the provided operators",
+        assertInvalidMessage("Predicates on non-primary-key columns (b) are 
not yet supported for non secondary index queries",
                              "SELECT * FROM %s where b = ?", 1);
         dropIndex("DROP INDEX IF EXISTS " + indexName);
         assertInvalidMessage("Index '" + 
removeQuotes(indexName.toLowerCase(Locale.US)) + "' could not be found", "DROP 
INDEX " + indexName);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/test/unit/org/apache/cassandra/cql3/validation/entities/UFAuthTest.java
----------------------------------------------------------------------
diff --git 
a/test/unit/org/apache/cassandra/cql3/validation/entities/UFAuthTest.java 
b/test/unit/org/apache/cassandra/cql3/validation/entities/UFAuthTest.java
index 498f0dd..b2b9946 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/UFAuthTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/UFAuthTest.java
@@ -261,17 +261,6 @@ public class UFAuthTest extends CQLTester
     }
 
     @Test
-    public void functionInStaticColumnRestrictionInSelect() throws Throwable
-    {
-        setupTable("CREATE TABLE %s (k int, s int STATIC, v1 int, v2 int, 
PRIMARY KEY(k, v1))");
-        String functionName = createSimpleFunction();
-        String cql = String.format("SELECT k FROM %s WHERE k = 0 AND s = %s",
-                                   KEYSPACE + "." + currentTable(),
-                                   functionCall(functionName));
-        assertPermissionsOnFunction(cql, functionName);
-    }
-
-    @Test
     public void functionInRegularCondition() throws Throwable
     {
         String functionName = createSimpleFunction();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/test/unit/org/apache/cassandra/cql3/validation/entities/UFIdentificationTest.java
----------------------------------------------------------------------
diff --git 
a/test/unit/org/apache/cassandra/cql3/validation/entities/UFIdentificationTest.java
 
b/test/unit/org/apache/cassandra/cql3/validation/entities/UFIdentificationTest.java
index 28b8afc..ecc9d47 100644
--- 
a/test/unit/org/apache/cassandra/cql3/validation/entities/UFIdentificationTest.java
+++ 
b/test/unit/org/apache/cassandra/cql3/validation/entities/UFIdentificationTest.java
@@ -200,18 +200,16 @@ public class UFIdentificationTest extends CQLTester
     public void testSelectStatementSimpleRestrictions() throws Throwable
     {
         assertFunctions(cql("SELECT i_val FROM %s WHERE key=%s", 
functionCall(iFunc, "1")), iFunc);
-        assertFunctions(cql("SELECT i_val FROM %s WHERE key=0 AND t_sc=%s", 
functionCall(tFunc, "'foo'")), tFunc);
         assertFunctions(cql("SELECT i_val FROM %s WHERE key=0 AND i_cc=%s AND 
t_cc='foo'", functionCall(iFunc, "1")), iFunc);
         assertFunctions(cql("SELECT i_val FROM %s WHERE key=0 AND i_cc=0 AND 
t_cc=%s", functionCall(tFunc, "'foo'")), tFunc);
 
         String iFunc2 = createEchoFunction("int");
         String tFunc2 = createEchoFunction("text");
-        assertFunctions(cql("SELECT i_val FROM %s WHERE key=%s AND t_sc=%s AND 
i_cc=%s AND t_cc=%s",
+        assertFunctions(cql("SELECT i_val FROM %s WHERE key=%s AND i_cc=%s AND 
t_cc=%s",
                             functionCall(iFunc, "1"),
-                            functionCall(tFunc, "'foo'"),
                             functionCall(iFunc2, "1"),
                             functionCall(tFunc2, "'foo'")),
-                        iFunc, tFunc, iFunc2, tFunc2);
+                        iFunc, iFunc2, tFunc2);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/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 b8a1d50..3b367f3 100644
--- 
a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
+++ 
b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.cql3.validation.operations;
 import org.junit.Test;
 
 import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.cql3.restrictions.StatementRestrictions;
 
 public class SelectMultiColumnRelationTest extends CQLTester
 {
@@ -821,7 +822,7 @@ public class SelectMultiColumnRelationTest extends CQLTester
                    row(0, 1, 1, 0, 1),
                    row(0, 1, 1, 1, 2));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE (b, c) = (?, ?)", 1, 1);
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) = (?, ?)", 
0, 1, 1),
                    row(0, 1, 1, 0, 1),
@@ -832,41 +833,41 @@ public class SelectMultiColumnRelationTest extends 
CQLTester
 
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b, c) = (?, ?) 
AND e = ?", 0, 1, 1, 2),
                    row(0, 1, 1, 1, 2));
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE (b, c) = (?, ?) AND e = 
?", 1, 1, 2);
         assertRows(execute("SELECT * FROM %s WHERE (b, c) = (?, ?) AND e = ? 
ALLOW FILTERING", 1, 1, 2),
                    row(0, 1, 1, 1, 2));
 
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND (b) IN ((?)) AND 
e = ? ALLOW FILTERING", 0, 1, 2),
                    row(0, 1, 1, 1, 2));
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE (b) IN ((?)) AND e = ?", 
1, 2);
         assertRows(execute("SELECT * FROM %s WHERE (b) IN ((?)) AND e = ? 
ALLOW FILTERING", 1, 2),
                    row(0, 1, 1, 1, 2));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE (b) IN ((?), (?)) AND e = 
?", 0, 1, 2);
         assertRows(execute("SELECT * FROM %s WHERE (b) IN ((?), (?)) AND e = ? 
ALLOW FILTERING", 0, 1, 2),
                    row(0, 0, 1, 1, 2),
                    row(0, 1, 1, 1, 2));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE (b, c) IN ((?, ?)) AND e 
= ?", 0, 1, 2);
         assertRows(execute("SELECT * FROM %s WHERE (b, c) IN ((?, ?)) AND e = 
? ALLOW FILTERING", 0, 1, 2),
                    row(0, 0, 1, 1, 2));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE (b, c) IN ((?, ?), (?, 
?)) AND e = ?", 0, 1, 1, 1, 2);
         assertRows(execute("SELECT * FROM %s WHERE (b, c) IN ((?, ?), (?, ?)) 
AND e = ? ALLOW FILTERING", 0, 1, 1, 1, 2),
                    row(0, 0, 1, 1, 2),
                    row(0, 1, 1, 1, 2));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE (b) >= (?) AND e = ?", 1, 
2);
         assertRows(execute("SELECT * FROM %s WHERE (b) >= (?) AND e = ? ALLOW 
FILTERING", 1, 2),
                    row(0, 1, 1, 1, 2));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE (b, c) >= (?, ?) AND e = 
?", 1, 1, 2);
         assertRows(execute("SELECT * FROM %s WHERE (b, c) >= (?, ?) AND e = ? 
ALLOW FILTERING", 1, 1, 2),
                    row(0, 1, 1, 1, 2));
@@ -890,14 +891,14 @@ public class SelectMultiColumnRelationTest extends 
CQLTester
 
         execute("INSERT INTO %s (a, b, c, d, e, f) VALUES (?, ?, ?, ?, ?, ?)", 
0, 0, 2, 0, 0, 5);
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE a = ? AND (c) = (?)");
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND (c) = (?) ALLOW 
FILTERING", 0, 1),
                    row(0, 0, 1, 0, 0, 3),
                    row(0, 0, 1, 1, 0, 4),
                    row(0, 0, 1, 1, 1, 5));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE a = ? AND (c, d) = (?, 
?)", 0, 1, 1);
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND (c, d) = (?, ?) 
ALLOW FILTERING", 0, 1, 1),
                    row(0, 0, 1, 1, 0, 4),
@@ -911,12 +912,12 @@ public class SelectMultiColumnRelationTest extends 
CQLTester
 
         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("Cannot execute this query as it might involve 
data filtering",
+        
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),
                    row(0, 0, 1, 1, 1, 5));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE a = ? AND (c) IN ((?), 
(?)) AND f = ?", 0, 1, 2, 5);
 
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND b = ? AND (c) IN 
((?), (?)) AND f = ?", 0, 0, 1, 2, 5),
@@ -929,12 +930,12 @@ public class SelectMultiColumnRelationTest extends 
CQLTester
 
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND b = ? AND (c, d) 
IN ((?, ?)) AND f = ?", 0, 0, 1, 0, 3),
                    row(0, 0, 1, 0, 0, 3));
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE a = ? AND (c, d) IN ((?, 
?)) AND f = ?", 0, 1, 0, 3);
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND (c, d) IN ((?, 
?)) AND f = ? ALLOW FILTERING", 0, 1, 0, 3),
                    row(0, 0, 1, 0, 0, 3));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE a = ? AND (c) >= (?) AND 
f = ?", 0, 1, 5);
 
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND b = ? AND (c) >= 
(?) AND f = ?", 0, 0, 1, 5),
@@ -948,7 +949,7 @@ public class SelectMultiColumnRelationTest extends CQLTester
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND b = ? AND (c, d) 
>= (?, ?) AND f = ?", 0, 0, 1, 1, 5),
                    row(0, 0, 1, 1, 1, 5),
                    row(0, 0, 2, 0, 0, 5));
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE a = ? AND (c, d) >= (?, 
?) AND f = ?", 0, 1, 1, 5);
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND (c, d) >= (?, ?) 
AND f = ? ALLOW FILTERING", 0, 1, 1, 5),
                    row(0, 0, 1, 1, 1, 5),

http://git-wip-us.apache.org/repos/asf/cassandra/blob/90fd8dee/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 31a84e4..08bf0db 100644
--- 
a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
+++ 
b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
@@ -17,14 +17,14 @@
  */
 package org.apache.cassandra.cql3.validation.operations;
 
-import java.util.Arrays;
-
-import org.junit.Test;
-
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.cql3.restrictions.StatementRestrictions;
+
+import org.junit.Test;
 
 public class SelectSingleColumnRelationTest extends CQLTester
 {
@@ -263,9 +263,9 @@ public class SelectSingleColumnRelationTest extends 
CQLTester
         assertRows(execute("SELECT * FROM %s WHERE k = ? AND c = ? ALLOW 
FILTERING", 1, 2), row(1, 2, 1));
 
         // Require filtering, allowed only with ALLOW FILTERING
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE c = ?", 2);
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE c > ? AND c <= ?", 2, 4);
 
         assertRows(execute("SELECT * FROM %s WHERE c = ? ALLOW FILTERING", 2),
@@ -373,7 +373,7 @@ public class SelectSingleColumnRelationTest extends 
CQLTester
         assertEmpty(execute("SELECT content FROM %s WHERE time1 = 1 AND time2 
= 1 AND author='foo' ALLOW FILTERING"));
         assertEmpty(execute("SELECT content FROM %s WHERE time1 = 1 AND time2 
> 0 AND author='foo' ALLOW FILTERING"));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT content FROM %s WHERE time2 >= 0 AND 
author='foo'");
     }
 
@@ -389,7 +389,7 @@ public class SelectSingleColumnRelationTest extends 
CQLTester
         execute(q, 2, 2, 0);
         execute(q, 3, 3, 0);
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE setid = 0 AND row < 1;");
         assertRows(execute("SELECT * FROM %s WHERE setid = 0 AND row < 1 ALLOW 
FILTERING;"), row(0, 0, 0));
     }
@@ -458,14 +458,14 @@ public class SelectSingleColumnRelationTest extends 
CQLTester
 
         execute("INSERT INTO %s (a, b, c, d, e, f) VALUES (?, ?, ?, ?, ?, ?)", 
0, 0, 2, 0, 0, 5);
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE a = ? AND c = ?", 0, 1);
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND c = ? ALLOW 
FILTERING", 0, 1),
                    row(0, 0, 1, 0, 0, 3),
                    row(0, 0, 1, 1, 0, 4),
                    row(0, 0, 1, 1, 1, 5));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE a = ? AND c = ? AND d = 
?", 0, 1, 1);
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND c = ? AND d = ? 
ALLOW FILTERING", 0, 1, 1),
                    row(0, 0, 1, 1, 0, 4),
@@ -477,18 +477,18 @@ public class SelectSingleColumnRelationTest extends 
CQLTester
         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("Cannot execute this query as it might involve 
data filtering",
+        
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),
                    row(0, 0, 1, 1, 1, 5));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE a = ? AND c IN (?, ?) AND 
f = ?", 0, 1, 2, 5);
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND c IN (?, ?) AND f 
= ? ALLOW FILTERING", 0, 1, 2, 5),
                    row(0, 0, 1, 1, 1, 5),
                    row(0, 0, 2, 0, 0, 5));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
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),
                    row(0, 0, 1, 0, 0, 3));
@@ -496,7 +496,7 @@ public class SelectSingleColumnRelationTest extends 
CQLTester
         assertInvalidMessage("Partition key parts: b must be restricted as 
other parts are",
                              "SELECT * FROM %s WHERE a = ? AND c >= ? ALLOW 
FILTERING", 0, 1);
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE a = ? AND c >= ? AND f = 
?", 0, 1, 5);
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND b = ? AND c >= ? 
AND f = ?", 0, 0, 1, 5),
                    row(0, 0, 1, 1, 1, 5),
@@ -506,7 +506,7 @@ public class SelectSingleColumnRelationTest extends 
CQLTester
                    row(0, 0, 1, 1, 1, 5),
                    row(0, 0, 2, 0, 0, 5));
 
-        assertInvalidMessage("Cannot execute this query as it might involve 
data filtering",
+        
assertInvalidMessage(StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              "SELECT * FROM %s WHERE a = ? AND c = ? AND d >= 
? AND f = ?", 0, 1, 1, 5);
 
         assertRows(execute("SELECT * FROM %s WHERE a = ? AND b = ? AND c = ? 
AND d >= ? AND f = ?", 0, 0, 1, 1, 5),
@@ -556,7 +556,7 @@ public class SelectSingleColumnRelationTest extends 
CQLTester
         assertInvalidMessage("Invalid unset value for column i", "SELECT * 
from %s WHERE k = 1 AND i IN(?,?)", 1, unset());
         assertInvalidMessage("Invalid unset value for column i", "SELECT * 
from %s WHERE i = ? ALLOW FILTERING", unset());
         // indexed column
-        assertInvalidMessage("Unsupported unset value for indexed column s", 
"SELECT * from %s WHERE s = ?", unset());
+        assertInvalidMessage("Unsupported unset value for column s", "SELECT * 
from %s WHERE s = ?", unset());
         // range
         assertInvalidMessage("Invalid unset value for column i", "SELECT * 
from %s WHERE k = 1 AND i > ?", unset());
     }
@@ -605,4 +605,4 @@ public class SelectSingleColumnRelationTest extends 
CQLTester
         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");
     }
-}
+}
\ No newline at end of file

Reply via email to