Astyanax. How to read SET and MAP Datatypes in cassandra

I am trying to read a column of type Set from cassandra using the following astyanax code.

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

I found similar code in Astyanax documentation as well

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

but i get an error

 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) 

Definition of my table

 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 

I can easily select a query in cqlsh. so i don't think there is any kind of problem with db.

Edit :: I also tried

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

But it throws the same error that there are unexpected extraneous bytes.

Edit2 :: I also tried

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

This does not cause an error, and I see the data ... but it looks like gibberish.

enter image description here

Edit3 :: I also tried

 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}") 

But then again the same problem org.apache.cassandra.serializers.MarshalException: Unexpected extraneous bytes after set value

Defining my cassandra table

 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'; 
+5
source share

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


All Articles