Not able to convert cassandra blob/bytes string to integer
<p>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.</p>

<p>CQLSH query <code>select * from table limit 2;</code> returns me:</p>

<blockquote>
  <p>id   | name  | value</p>
  
  <p>id_001 | john  | 0x010000000000000000</p>
  
  <p>id_002 | terry | 0x044097a80000000000</p>
</blockquote>

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

<blockquote>
  <p>{'id':'id_001', 'name':'john', 'value': '\x01\x00\x00\x00\x00\x00\x00\x00\x00'}</p>
  
  <p>{'id':'id_002', 'name':'terry', 'value': '\x04@\x97\xa8\x00\x00\x00\x00\x00'}</p>
</blockquote>

<p>Ideally the values in the "value" field are <code>0</code> and <code>1514</code> for <code>row1</code> and <code>row2</code> resp.  </p>

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

<p><strong>Questions:</strong></p>

<ol>
<li>What is this format?
<code>'\x01\x00\x00\x00\x00\x00\x00\x00\x00'</code> or
<code>'\x04@\x97\xa8\x00\x00\x00\x00\x00'</code>?</li>
<li>How I can convert these arbitrary values to <code>0</code> and <code>1514</code>?</li>
</ol>

<p>NOTE: I am using python 2.7.9 on Linux</p>

<p>Any help or pointers would be useful.</p>

<p>Thanks,</p>

<ol>
<li><p>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.</p></li>
<li><p>One way is to explicitly do the conversion in your query.</p>

<p><code>select id, name, blobasint(value) from table limit 3</code></p>

<p>There should be a conversion method with the Python driver as well. </p></li>
</ol>

python cassandra cqlsh cqlengine