Fetching columns for a row preserving data types.

17 views
Skip to first unread message

Vamshi

unread,
Feb 12, 2013, 12:51:49 AM2/12/13
to hector...@googlegroups.com

Hi,

 When I fetch columns using SliceQuery, it returns me all the columns with the same datatype. Is there any way that QueryResult have object as the datatype of column values.
I can use instance of operator and then typecast it to any datatype.

Code snippet:

        SliceQuery<String,String,ByteBuffer> query = HFactory.createSliceQuery(getConnection().getKeyspace(),StringSerializer.get(),StringSerializer.get(),ByteBufferSerializer.get());
        query.setColumnFamily(columnFamily).setKey(key).setRange("","",false,100);
        QueryResult<ColumnSlice<String, ByteBuffer>> colResult = query.execute();


In the above code snippet, I am getting ByteBuffer of all the values. Can I get Object in place of it?

Regards,
Vamshi

Shane Perry

unread,
Feb 12, 2013, 11:06:19 AM2/12/13
to hector...@googlegroups.com
Convert the ByteBuffer using the appropriate serializer. For example,
to convert the ByteBuffer to a String use:

ByteBuffer buffer = column.getValue();
String value = StringSerializer.get().fromByteBuffer(buffer);
> --
> You received this message because you are subscribed to the Google Groups
> "hector-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to hector-users...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Vamshi

unread,
Feb 13, 2013, 7:56:25 AM2/13/13
to hector...@googlegroups.com
Thanks a lot. Helped solve my issue.

Ashu

unread,
May 9, 2013, 3:31:05 AM5/9/13
to hector...@googlegroups.com
Hi Vamshi

Can you paste your final code here? Actually I am facing same problem and the
thing is I dont know the data type of column values in advance. So we have to
dynamically find that out and then use frombytebuffer accordingle. Can you
provide some help?

Reply all
Reply to author
Forward
0 new messages