cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1082387 - in /cassandra/branches/cassandra-0.7: src/java/org/apache/cassandra/thrift/ThriftValidation.java test/system/__init__.py test/system/test_thrift_server.py
Date Thu, 17 Mar 2011 02:55:27 GMT
Author: jbellis
Date: Thu Mar 17 02:55:26 2011
New Revision: 1082387

URL: http://svn.apache.org/viewvc?rev=1082387&view=rev
Log:
validate index predicates
patch by Aaron Morton; reviewed by jbellis for CASSANDRA-2328

Modified:
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/thrift/ThriftValidation.java
    cassandra/branches/cassandra-0.7/test/system/__init__.py
    cassandra/branches/cassandra-0.7/test/system/test_thrift_server.py

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/thrift/ThriftValidation.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/thrift/ThriftValidation.java?rev=1082387&r1=1082386&r2=1082387&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/thrift/ThriftValidation.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/thrift/ThriftValidation.java
Thu Mar 17 02:55:26 2011
@@ -394,12 +394,41 @@ public class ThriftValidation
         if (index_clause.expressions.isEmpty())
             throw new InvalidRequestException("index clause list may not be empty");
         Set<ByteBuffer> indexedColumns = Table.open(keyspace).getColumnFamilyStore(columnFamily).getIndexedColumns();
+        AbstractType nameValidator =  ColumnFamily.getComparatorFor(keyspace, columnFamily,
null);
+
+        boolean isIndexed = false;
         for (IndexExpression expression : index_clause.expressions)
         {
-            if (expression.op.equals(IndexOperator.EQ) && indexedColumns.contains(expression.column_name))
-                return;
+            try
+            {
+                nameValidator.validate(expression.column_name);
+            }
+            catch (MarshalException me)
+            {
+                throw new InvalidRequestException(String.format("[%s]=[%s] failed name validation
(%s)",
+                                                                ByteBufferUtil.bytesToHex(expression.column_name),
+                                                                ByteBufferUtil.bytesToHex(expression.value),
+                                                                me.getMessage()));
+            }
+
+            AbstractType valueValidator = DatabaseDescriptor.getValueValidator(keyspace,
columnFamily, expression.column_name);
+            try
+            {
+                valueValidator.validate(expression.value);
+            }
+            catch (MarshalException me)
+            {
+                throw new InvalidRequestException(String.format("[%s]=[%s] failed value validation
(%s)",
+                                                                ByteBufferUtil.bytesToHex(expression.column_name),
+                                                                ByteBufferUtil.bytesToHex(expression.value),
+                                                                me.getMessage()));
+            }
+
+            isIndexed |= expression.op.equals(IndexOperator.EQ) && indexedColumns.contains(expression.column_name);
         }
-        throw new InvalidRequestException("No indexed columns present in index clause with
operator EQ");
+
+        if (!isIndexed)
+            throw new InvalidRequestException("No indexed columns present in index clause
with operator EQ");
     }
 
     public static void validateCfDef(CfDef cf_def) throws InvalidRequestException

Modified: cassandra/branches/cassandra-0.7/test/system/__init__.py
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/system/__init__.py?rev=1082387&r1=1082386&r2=1082387&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/system/__init__.py (original)
+++ cassandra/branches/cassandra-0.7/test/system/__init__.py Thu Mar 17 02:55:26 2011
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import os, sys, time, signal, httplib, errno
+import os, sys, time, signal, httplib, errno, uuid
 
 __all__ = ['root', 'thrift_client']
 
@@ -171,6 +171,8 @@ class ThriftTester(BaseTester):
             Cassandra.CfDef('Keyspace1', 'Super3', column_type='Super', subcomparator_type='LongType'),

             Cassandra.CfDef('Keyspace1', 'Super4', column_type='Super', subcomparator_type='UTF8Type'),
             Cassandra.CfDef('Keyspace1', 'Indexed1', column_metadata=[Cassandra.ColumnDef('birthdate',
'LongType', Cassandra.IndexType.KEYS, 'birthdate')]),
+            Cassandra.CfDef('Keyspace1', 'Indexed2', comparator_type='TimeUUIDType', column_metadata=[Cassandra.ColumnDef(uuid.UUID('00000000-0000-1000-0000-000000000000').bytes,
'LongType', Cassandra.IndexType.KEYS, 'birthdate')]),
+
         ])
 
         keyspace2 = Cassandra.KsDef('Keyspace2', 'org.apache.cassandra.locator.SimpleStrategy',
None, 1,

Modified: cassandra/branches/cassandra-0.7/test/system/test_thrift_server.py
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/system/test_thrift_server.py?rev=1082387&r1=1082386&r2=1082387&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/system/test_thrift_server.py (original)
+++ cassandra/branches/cassandra-0.7/test/system/test_thrift_server.py Thu Mar 17 02:55:26
2011
@@ -17,7 +17,7 @@
 # to run a single test, run from trunk/:
 # PYTHONPATH=test nosetests --tests=system.test_thrift_server:TestMutations.test_empty_range
 
-import os, sys, time, struct
+import os, sys, time, struct, uuid
 
 from __init__ import root, ThriftTester
 from __init__ import thrift_client as client
@@ -1122,7 +1122,10 @@ class TestMutations(ThriftTester):
 
         ks1 = client.describe_keyspace("Keyspace1")
         assert ks1.replication_factor == 1
-        cf0 = ks1.cf_defs[0]
+        for cf in ks1.cf_defs:
+            if cf.name == "Standard1":
+                cf0 = cf
+                break;
         assert cf0.comparator_type == "org.apache.cassandra.db.marshal.BytesType"
 
     def test_describe(self):
@@ -1515,6 +1518,15 @@ class TestMutations(ThriftTester):
         assert result[0].key == 'key3'
         assert len(result[0].columns) == 2, result[0].columns
         
+        cp = ColumnParent('Indexed2')
+        # name must be valid (TimeUUID)
+        clause = IndexClause([IndexExpression('foo', IndexOperator.EQ, uuid.UUID('00000000-0000-1000-0000-000000000000').bytes)],
'')
+        _expect_exception(lambda: client.get_indexed_slices(cp, clause, sp, ConsistencyLevel.ONE),
InvalidRequestException)
+        
+        # value must be valid (TimeUUID)
+        clause = IndexClause([IndexExpression(uuid.UUID('00000000-0000-1000-0000-000000000000').bytes,
IndexOperator.EQ, "foo")], '')
+        _expect_exception(lambda: client.get_indexed_slices(cp, clause, sp, ConsistencyLevel.ONE),
InvalidRequestException)
+        
     def test_index_scan_expiring(self):
         """ Test that column ttled expires from KEYS index"""
         _set_keyspace('Keyspace1')



Mime
View raw message