Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Problem with composite key #179

anentropic opened this Issue · 5 comments

2 participants


I have a column family that looks something like:

  tstamp timestamp,
  uid text,
  advert_id text,
  PRIMARY KEY (tstamp, uid)

I'm not clear how to insert rows via pycassa. In CQL (cqlsh --cql3) the insert query doesn't look any different for having a composite key, and it works fine.

From the docs it sounds like I should do something like:

EVENTS.insert((1353429385881,'123'), {'tstamp':1353429385881,'uid':'456','advert_id':'111'})

(do I need to supply the values from the key fields as column values too, like above?).

But I get:

/usr/local/lib/python2.7/dist-packages/pycassa/marshal.pyc in _to_timestamp(v)
     72         # Ints and floats are valid timestamps too
     73         if type(v) not in _number_types:
---> 74             raise TypeError('DateType arguments must be a datetime or timestamp')
     76         converted = v * 1e3

TypeError: DateType arguments must be a datetime or timestamp

I put some debugging in and my v here is the tuple.

But if I try just the timestamp value by itself I get different error:

/usr/local/lib/python2.7/dist-packages/pycassa/ in pack_utf8(v, _)
    201         def pack_utf8(v, _=None):
    202             try:
--> 203                 return v.encode('utf-8')
    204             except UnicodeDecodeError:
    205                 # v is already utf-8 encoded

AttributeError: 'int' object has no attribute 'encode'

Am I doing this all wrong?


(Cassandra 1.1 and installed HEAD version of Pycassa from github, though same problem with 1.7.2 too)


Unfortunately, pycassa (and all other clients libraries based on the Thrift API) can't correctly determine the schema when you use compound primary keys with cql3; that's the main thing about cql3 that is incompatible with the legacy Thrift API.

For now, you'll either need to use cql3 only for this column family, or define it in a way that works with pycassa.

@thobbs thobbs closed this

@thobbs thanks for looking into it... for now I have ended up going the CQL 3 route via

Can you give more info about "define it in a way that works with pycassa"? Does that just mean "don't use a composite key"... or is there some way to make a composite key that pycassa can handle? Is there a way to tell pycassa about the schema of my composite key?


A cql3 compound primary key is actually a normal key and composite columns under the hood. So you would have a key that's LongType or DateType (I don't recall which format timestamp corresponds to) and a comparator that is CompositeType(UTF8Type, UTF8Type) (the first is for the uid, the second is for the advert_id).

For compatibility purposes, I believe you could set the ColumnFamily.column_name_class attribute to CompositeType(UTF8Type(), UTF8Type()) and the ColumnFamily.key_validation_class to DateType() and it should work, but I haven't tried this out, so I don't know for sure if there will be any issues.


thanks very much for the detailed info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.