pythoncassandracql3cqlengine

How to query rows by blob primary key from Cassandra using Python's cqlengine


My Cassandra table looks like this:

uid                     | flwuid                     | tuuid
------------------------+----------------------------+--------------------------------------
0x50f893bf620d628f0500 | 0x527ce3c3c5ebc4dd7e8b4567 | 1e970c24-488d-11e3-b19a-7054d219d35c
0x505a31a507b8d04b0005 | 0x526a66cbc5ebc4d3708b456c | 6081f230-4797-11e3-b9af-7054d219d35c
0x505a31a507b845000005 | 0x527ce3c3c5ebc4dd7e8b4567 | 9da514bc-4878-11e3-bcb1-7054d219d35c
0x51ee6cef6cbf7679f7a0 | 0x524bfd0dc5ebc486738b4567 | 6bdf89c6-4b93-11e3-a8a0-7054d219d35c
0x51ee160a6cbf7679f7a0 | 0x526a7149c5ebc494708b456c | 8e8a1c4c-45fe-11e3-9b35-7054d219d35c

I have a cqlengine model:

class Followers(Model):
    uid = cqlengine.Bytes(primary_key=True)
    flwuid = cqlengine.Bytes(primary_key=True)
    tuuid = cqlengine.TimeUUID()

To get all rows with uid = 0x50f893bf620d628f0500 I am trying to do this:

Followers.objects(uid='0x50f893bf620d628f0500')

but getting an exception:

CQLEngineException: Bad Request: Invalid STRING constant (3078353066383933626636323064363238663035303030303061) for uid of type blob

How can specify correct blob value for cqlengine' query?

Cassandra 2.0.1, cqlengine 0.9.1.

Thanks in advance.


Solution

  • Look here and here.

    The reason is Cassandra 2.0 doesn't support writing or requesting blob value, represented as python string. You should use bytearray type instead.