pycassa/pycassa — pull request #183 by umairmufti (2013-01-08 16:30:50+00:00)
Title: Added support for DynamicCompositeType.

We needed to use DynamicCompositeTypes for our project so I went ahead and added support for it in Pycassa. I wanted to contribute back as a way to say thanks and in the hopes that some others may find it useful.

Usage is very similar to the way CompositeTypes work, except that every component is a 2-tuple (comparator type, value). The comparator type can either be a full CassandraType or an alias, if one was given when the column family was created.

In order to create a column family with aliases, simply create a DynamicCompositeType object with a dictionary of aliases and use that for the comparator.

Example:
comparator = DynamicCompositeType({'L': LongType(reversed=True), 'a': AsciiType()})
sys.create_column_family("Keyspace1", "CF1", comparator_type=comparator)

cf = ColumnFamily(pool, "CF1")
comp1 = ('L', 1234)
comp2 = ('a', "abc")
comp3 = ('UTF8Type', "look ma, no hands!")
cf.insert("key", {(comp1, comp2, comp3): "colval"})

Hope this helps!