0

I have a column-family/table in cassandra-3.0.6 which has a column named "value" which is defined as a blob data type.

CQLSH query select * from table limit 2; returns me:

id | name | value

id_001 | john | 0x010000000000000000

id_002 | terry | 0x044097a80000000000

If I read this value using cqlengine(Datastax Python Driver), I get the output something like:

{'id':'id_001', 'name':'john', 'value': '\x01\x00\x00\x00\x00\x00\x00\x00\x00'}

{'id':'id_002', 'name':'terry', 'value': '\x04@\x97\xa8\x00\x00\x00\x00\x00'}

Ideally the values in the "value" field are 0 and 1514 for row1 and row2 resp.

However, I am not sure how I can convert the "value" field values extracted using cqlengine to 0 and 1514. I tried few methods like ord(), decode(), etc but nothing worked. :(

Questions:

  1. What is this format? '\x01\x00\x00\x00\x00\x00\x00\x00\x00' or '\x04@\x97\xa8\x00\x00\x00\x00\x00'?
  2. How I can convert these arbitrary values to 0 and 1514?

NOTE: I am using python 2.7.9 on Linux

Any help or pointers would be useful.

Thanks,

Community
  • 1
  • 1

1 Answers1

0
  1. Blob will be converted to a byte array in Python if you read it directly. That looks like a byte array containing the Hex value of the blob.

  2. One way is to explicitly do the conversion in your query.

    select id, name, blobasint(value) from table limit 3

    There should be a conversion method with the Python driver as well.

Alec Collier
  • 1,483
  • 8
  • 9