Cassandra 1.2 insert / update blob column type using Python and cql library

Introduction

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

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

Problem:

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

 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) 

Question:

Is there a way to execute this request without using the base 16 encoding (string) of the object? The reason for this is to reduce the overhead of sending the base coded string 16 over the wire instead of simple bytes.

Thanks in advance!

+6
source share
1 answer

Base64 or HEX?

If your question is not encoded in base64, yes you can, however you must provide your data in CQL in HEX format.

If your question does not apply to HEX, No, that is not possible.

Like a blob defined in CQL Documentation

The blob constant is a hexadecimal number defined by 0xX +, where hex is a hexadecimal character, for example. [0-9a-FA-F]. For example, 0xcafe.

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

+1
source

Source: https://habr.com/ru/post/945964/


All Articles