Cassandra 1.2使用Python和cql库插入/更新blob列类型 [英] Cassandra 1.2 inserting/updating a blob column type using Python and the cql library

查看:951
本文介绍了Cassandra 1.2使用Python和cql库插入/更新blob列类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介

我在Cassandra 1.2栏族上有一个blob栏,表格定义如下:

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)
);

问题:

问题是,当我需要使用cql库从Python插入/更新blob列时,我需要基于16编码列的内容,如下所示:

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)

问题:

有没有办法执行这个查询而不使用base 16 encoding物体?这样做的原因是为了减少在线上发送基本16编码的字符串而不是明文字节的开销。

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.

提前感谢!

推荐答案

Base64或HEX?

Base64 or HEX?

如果你的问题不是编码到base64,您必须以HEX格式将您的数据提供给CQL。

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

如果您的问题不是覆盖到HEX,则不可能。

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

如在 CQL文档中定义的blob

As blob defined in CQL documentation


blob常数是由0xX +定义的十六进制数,其中hex是十六进制字符,例如[0-9a-fA-F]。例如,0xcafe。

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.

因此,这显然意味着您需要以HEX格式发送数据。

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

这篇关于Cassandra 1.2使用Python和cql库插入/更新blob列类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆