Re: Use Cassnadra thrift API with collection type

2014-06-24 Thread Huiliang Zhang
Yes, I realized the way to use CQL.

I checked the way how map data is represented by using cassandra-cli. For
each element in the map, it use the key as part of the column name and
value as the column value. I just cannot insert this by using thrift API
because I already defined a CompositeType column comparator. Is it a way to
run a second program to insert map data with a different comparator?

Thanks.


On Mon, Jun 23, 2014 at 10:21 AM, Sylvain Lebresne sylv...@datastax.com
wrote:

 On Mon, Jun 23, 2014 at 6:19 PM, James Campbell 
 ja...@breachintelligence.com wrote:

  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=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();

 ...


 This is exactly equivalent to what Huiliang posted and will thus not work
 any better.

 Collections are internally not store as one thrift column per
 collection. Each element of the collection is a separate thrift column
 and the exact encoding depends on the collection. The fact is, updating CQL
 collection from thrift is technically possible but it is not recommended in
 any way. I strongly advise you to stick to CQL if you want to use CQL
 collections.

  --
 Sylvain



  --
 *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=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







RE: Use Cassnadra thrift API with collection type

2014-06-23 Thread James Campbell
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.namehttp://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.namehttp://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





Re: Use Cassnadra thrift API with collection type

2014-06-23 Thread Sylvain Lebresne
On Mon, Jun 23, 2014 at 6:19 PM, James Campbell 
ja...@breachintelligence.com wrote:

  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=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();

 ...


This is exactly equivalent to what Huiliang posted and will thus not work
any better.

Collections are internally not store as one thrift column per collection.
Each element of the collection is a separate thrift column and the exact
encoding depends on the collection. The fact is, updating CQL collection
from thrift is technically possible but it is not recommended in any way. I
strongly advise you to stick to CQL if you want to use CQL collections.

 --
Sylvain



  --
 *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=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