Huilang,

Since there hasn't been another reply yet, I'll throw out an idea that worked 
for us as part of a test, though it does not seem exactly like a "preferred" 
way since it crosses code-bases.  We built the type using  straight java type, 
then used the Datastax v2 driver's DataType class serializer.


Concretely, it would look like the following (adapting your code):

Column column = new Column();
            
column.name<http://column.name>=columnSerializer.toByteBuffer(colname); // the 
column name of the map type, it works with other kinds of data type

            ?column.value = DataType.map(DataType.ascii, 
DataType.decimal).serialize(yourMapGoesHere);
            column.timestamp = new Date().getTime();

...




________________________________
From: Huiliang Zhang <zhl...@gmail.com>
Sent: Friday, June 20, 2014 10:10 PM
To: user@cassandra.apache.org
Subject: Use Cassnadra thrift API with collection type

Hi,

I have a problem when insert data of the map type into a cassandra table. I 
tried all kinds of MapSerializer to serialize the Map data and did not succeed.

My code is like this:
            Column column = new Column();
            
column.name<http://column.name>=columnSerializer.toByteBuffer(colname); // the 
column name of the map type, it works with other kinds of data type
            column.value = MapSerializer.getInstance(AsciiSerializer.instance, 
DecimalSerializer.instance).serialize(someMapData);
            column.timestamp = new Date().getTime();

            Mutation mutation = new Mutation();
            mutation.column_or_supercolumn = new ColumnOrSuperColumn();
            mutation.column_or_supercolumn.column = column;
            mutationList.add(mutation);

The data was input into the cassandra DB however it cannot be retrieved by CQL3 
with the following error:
ERROR 14:32:48,192 Exception in thread Thread[Thrift:4,5,main]
java.lang.AssertionError
    at 
org.apache.cassandra.cql3.statements.ColumnGroupMap.getCollection(ColumnGroupMap.java:88)
    at 
org.apache.cassandra.cql3.statements.SelectStatement.getCollectionValue(SelectStatement.java:1185)
    at 
org.apache.cassandra.cql3.statements.SelectStatement.handleGroup(SelectStatement.java:1169)
    at 
org.apache.cassandra.cql3.statements.SelectStatement.processColumnFamily(SelectStatement.java:1076)
...

So the question is how to write map data into cassandra by thrift API. 
Appreciated for any help.

Thanks,
Huiliang



Reply via email to