Cassandra 1.2 inserting/updating a blob column type using Python and the cql library

北慕城南 提交于 2019-12-08 21:48:09

问题


Intro

I have a blob column on a Cassandra 1.2 column family, the table is defined as follows:

CREATE TABLE objects (
   id        text,
   obj       blob,
   PRIMARY KEY (id)
);

The problem:

The problem is that when I need to insert/update the blob column from Python using the cql library, I need to base 16 encode the contents of the column like this:

import cPickle
import cql
...
def save_object(connection, obj):
    object['id']  = obj['id']
    object['obj'] = cPickle.dumps(obj).encode("hex")
    cql_statement = "INSERT INTO objects (id, obj) values (:id, :obj)"
    cursor = connection.cursor()
    cursor.execute(cql_statement, object)

The question:

Is there a way of executing this query without using the base 16 encoding(string) of the object? The reason for this is to reduce the overhead of sending a base 16 encoded string over the wire instead of plain bytes.

Thank in advance!


回答1:


Base64 or HEX?

if your question is not encoding into base64 yes you can, however you must provide your data into CQL in HEX format.

If your question is not coverting into HEX, No it is not possible.

As blob defined in CQL documentation

A blob constant is an hexadecimal number defined by 0xX+ where hex is an hexadecimal character, e.g. [0-9a-fA-F]. For example, 0xcafe.

So this clearly means that you need to send your data in HEX format.



来源:https://stackoverflow.com/questions/16780251/cassandra-1-2-inserting-updating-a-blob-column-type-using-python-and-the-cql-lib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!