Astyanax。如何在cassandra中读取SET和MAP数据类型

时间:2016-11-06 16:28:14

标签: cassandra astyanax

我正在尝试使用以下astyanax代码从cassandra中读取Set类型的列。

val genres = col.getColumnByName("genres")
val genValue = genres.getValue(new SetSerializer[String](UTF8Type.instance))

我在Astyanax文档中也发现了类似的代码

https://github.com/Netflix/astyanax/wiki/Collections

但我收到错误

org.apache.cassandra.serializers.MarshalException: Unexpected extraneous bytes after set value
    at org.apache.cassandra.serializers.SetSerializer.deserialize(SetSerializer.java:64)
    at org.apache.cassandra.serializers.SetSerializer.deserialize(SetSerializer.java:27)
    at org.apache.cassandra.db.marshal.AbstractType.compose(AbstractType.java:142)
    at com.netflix.astyanax.serializers.SetSerializer.fromByteBuffer(SetSerializer.java:32)

我的表定义是

CREATE TABLE movielens_small.movies (
    id uuid PRIMARY KEY,
    avg_rating float,
    genres set<text>,
    name text,
    release_date date,
    url text,
    video_release_date date
) WITH bloom_filter_fp_chance = 0.01

我可以轻松地在cqlsh中选择一个查询。所以我不认为db有问题。

编辑::我也试过

val myset = ListType.getInstance(UTF8Type.instance)
val genValue = myset.compose(genres.getByteBufferValue) 

但它会抛出与意外无关的字节相同的错误。

Edit2 ::我也试过

val genValue = new String(genres.getByteBufferValue.array(), "UTF-8")

这不会引发错误,我可以看到数据......但它就像乱码。

enter image description here

Edit3 ::我也试过

val setSer = new SetSerializer[String](UTF8Type.instance)
val buf = genres.getByteBufferValue
val genValue = setSer.fromByteBuffer(buf)
println(s"${name.getStringValue} rating: ${avgRating.getFloatValue} genres: ${genValue}")

但同样是org.apache.cassandra.serializers.MarshalException: Unexpected extraneous bytes after set value

的问题

我的cassandra表定义是

CREATE TABLE movielens_small.movies (
    id uuid PRIMARY KEY,
    avg_rating float,
    genres set<text>,
    name text,
    release_date date,
    url text,
    video_release_date date
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

0 个答案:

没有答案