cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1147937 - in /cassandra/drivers/py: cql/decoders.py test/test_query_preparation.py
Date Mon, 18 Jul 2011 15:48:02 GMT
Author: jbellis
Date: Mon Jul 18 15:48:00 2011
New Revision: 1147937

URL: http://svn.apache.org/viewvc?rev=1147937&view=rev
Log:
improve decode efficiency and fix tests
patch by thobbs; reviewed by jbellis for CASSANDRA-2913

Modified:
    cassandra/drivers/py/cql/decoders.py
    cassandra/drivers/py/test/test_query_preparation.py

Modified: cassandra/drivers/py/cql/decoders.py
URL: http://svn.apache.org/viewvc/cassandra/drivers/py/cql/decoders.py?rev=1147937&r1=1147936&r2=1147937&view=diff
==============================================================================
--- cassandra/drivers/py/cql/decoders.py (original)
+++ cassandra/drivers/py/cql/decoders.py Mon Jul 18 15:48:00 2011
@@ -32,21 +32,7 @@ class SchemaDecoder(object):
 
     def __comparator_for(self, keyspace, column_family):
         cfam = self.__get_column_family_def(keyspace, column_family)
-        if "comparator" in cfam:
-            return cfam["comparator"]
-        return None
-
-    def __validator_for(self, keyspace, column_family, name):
-        cfam = self.__get_column_family_def(keyspace, column_family)
-        if name in cfam["columns"]:
-            return cfam["columns"][name]
-        return cfam["default_validation_class"]
-
-    def __keytype_for(self, keyspace, column_family):
-        cfam = self.__get_column_family_def(keyspace, column_family)
-        if "key_validation_class" in cfam:
-            return cfam["key_validation_class"]
-        return None
+        return cfam.get("comparator", None)
 
     def decode_description(self, keyspace, column_family, row):
         description = []
@@ -60,16 +46,23 @@ class SchemaDecoder(object):
         return description
 
     def decode_row(self, keyspace, column_family, row):
-        comparator = self.__comparator_for(keyspace, column_family)
-        unmarshal = unmarshallers.get(comparator, unmarshal_noop)
+        cfdef = self.__get_column_family_def(keyspace, column_family)
+        key_alias = cfdef['key_alias']
+        validators = cfdef['columns']
+        default_validator = cfdef['default_validation_class']
+        key_validator = cfdef.get("key_validation_class", None)
+
         values = []
         for column in row.columns:
+            name = column.name
             if column.value is None:
                 values.append(None)
                 continue
-            if column.name == self.__get_column_family_def(keyspace, column_family)['key_alias']:
-                validator = self.__keytype_for(keyspace, column_family)
+
+            if name == key_alias:
+                validator = key_validator
             else:
-                validator = self.__validator_for(keyspace, column_family, column.name)
+                validator = validators.get(name, default_validator)
             values.append(unmarshallers.get(validator, unmarshal_noop)(column.value))
+
         return values

Modified: cassandra/drivers/py/test/test_query_preparation.py
URL: http://svn.apache.org/viewvc/cassandra/drivers/py/test/test_query_preparation.py?rev=1147937&r1=1147936&r2=1147937&view=diff
==============================================================================
--- cassandra/drivers/py/test/test_query_preparation.py (original)
+++ cassandra/drivers/py/test/test_query_preparation.py Mon Jul 18 15:48:00 2011
@@ -54,12 +54,12 @@ class TestPrepare(unittest.TestCase):
     def test_prepares(self):
         "test prepared queries against known standards"
         for (i, test) in enumerate(TESTS):
-            a = prepare(test, **ARGUMENTS[i])
+            a = prepare(test, ARGUMENTS[i])
             b = STANDARDS[i]
             assert a == b, "\n%s !=\n%s" % (a, b)
 
     def test_bad(self):
         "ensure bad calls raise exceptions"
-        self.assertRaises(KeyError, prepare, ":a :b", a=1)
-        self.assertRaises(cql.ProgrammingError, prepare, ":a :b", a=1, b=2, c=3)
-        self.assertRaises(cql.ProgrammingError, prepare, "none", a=1)
+        self.assertRaises(KeyError, prepare, ":a :b", {'a': 1})
+        self.assertRaises(cql.ProgrammingError, prepare, ":a :b", {'a': 1, 'b': 2, 'c': 3})
+        self.assertRaises(cql.ProgrammingError, prepare, "none", {'a': 1})



Mime
View raw message