我需要在我的所有列中的Cassandra列族中存储二进制字节数据 . 下面是我将获得二进制字节数据的代码 . 我的rowKey将是String,但我的所有列都必须存储二进制blob数据 .
GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(schema);
ByteArrayOutputStream os = new ByteArrayOutputStream();
Encoder e = EncoderFactory.get().binaryEncoder(os, null);
writer.write(record, e);
e.flush();
byte[] byteData = os.toByteArray();
os.close();
// write byteData in Cassandra.
我不确定在上述用例中创建Cassandra列族的正确方法是什么?下面是我已经创建的列族,但我不确定这是否是针对上述用例的正确方法?
create column family TESTING
with key_validation_class = 'UTF8Type'
and comparator = 'UTF8Type'
and default_validation_class = 'UTF8Type'
and gc_grace = 86400
and column_metadata = [ {column_name : 'lmd', validation_class : DateType}];
Update:-
我将使用Astyanax客户端从Cassandra检索数据 . 我的用例很简单 .
我上面的Cassandra Column Family中的所有列都只存储二进制blob数据 .
这个专栏系列怎么样?看起来不错吗?
create column family TESTING
with key_validation_class = 'UTF8Type'
and comparator = 'TimeUUIDType'
and default_validation_class = 'ByteType'
and gc_grace = 86400
and column_metadata = [ {column_name : 'lmd', validation_class : DateType}];
当我尝试创建上面的列族时,我得到了这个例外 -
[default@profileks] create column family TESTING
... with key_validation_class = 'UTF8Type'
... and comparator = 'TimeUUIDType'
... and default_validation_class = 'ByteType'
... and gc_grace = 86400
... and column_metadata = [ {column_name : 'lmd', validation_class : DateType}];
java.lang.RuntimeException: org.apache.cassandra.db.marshal.MarshalException: Unknown timeuuid representation: lmd
我将userId存储为rowKey,然后是我的column-name,它将存储binary-blobs数据,最后将lmd存储为DateType列 .
2 回答
@Trekkie
如果您正在使用Thrift客户端:
由于您未指定要如何访问数据,因此可以使用 TimeUUIDType 进行列的自然排序
如果您使用的是CQL3:
@Trekkie
我现在明白你的要求了:
row key = text
列名=存储的字节
value = none
在开始时,我假设您将二进制数据存储在 value 列中,而不是列 name 中 .
如果以列名存储数据,请务必小心,因为您不能在列名中存储超过64K的数据 . 你确定你的blob永远不会超过64K吗?
http://wiki.apache.org/cassandra/FAQ#max_key_size