cassandra-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tyler Hobbs <ty...@datastax.com>
Subject Re: ISSUE: Cassandra Custom Secondary Index reading CQLType collection values
Date Wed, 27 Aug 2014 18:04:13 GMT
Maps (and other collections) are stored in multiple cells, one cell per
item.  To get the map keys, use cell.name().collectionElement() and
deserialize with the type for the keys (UTF8Type.instance).  For values,
use cell.value() and use the value type (also UTF8Type.instance, here).


On Wed, Aug 27, 2014 at 12:54 PM, Arindam Bose <arindambose78@gmail.com>
wrote:

> Added few more information:
>
> I need some help in reading CQL3 Collection type values while getting a
> callback to the Custom Secondary Index (cassandra 2.1.0).
>
> Column Family:
>
> CREATE TABLE IF NOT EXISTS test1(
> id text,
> mymap map<text,text>,
> PRIMARY KEY(id)
> )
>
> Added value:
>
> Insert into test(id, mymap) values ('1', {'1':'value1'});
>
> Then in my custom class I am trying to read mymap Cell.value() and
> deserialize the ByteBuffervalue to get the full map content as below:
>
> To get the row data based on a rowKey in callback:
>
> DecoratedKey dkey = StorageService.getPartitioner().decorateKey(rowKey);
> QueryFilter qf =  QueryFilter.getIdentityFilter(dkey,
>                   baseCfs.metadata.cfName,
>                   Calendar.getInstance().getTimeInMillis());
> ColumnFamily cf = baseCfs.getColumnFamily(qf);
>
> for (Cell cell : cf)
> {
>     if( cell name is "mymap" )
>     {
>         LOGGER.debug("for column mymap");
>
>         Map<String, String> mymap= MapType.getInstance(UTF8Type.instance,
>          UTF8Type.instance).compose(cell.value().duplicate());
>         for(String key: mymap.keySet())
>         {
>             LOGGER.debug("mymapkey [{}]: [{}]", key, mymap.get(key));
>         }
>     }
> }
>
> But I am not getting the values in the persisted in the Map. It says *"Not
> enough bytes to read a map"*
>
> Is there anyone who can help?
>
>
>
> Regards,
> Arindam Bose
>
>
>
> On Wed, Aug 27, 2014 at 11:21 AM, Arindam Bose <arindambose78@gmail.com>
> wrote:
>
> > Hello,
> >
> > I need some help in reading CQL3 Collection type values while getting a
> > callback to the Custom Secondary Index.
> >
> > Column Family:
> >
> > CREATE TABLE IF NOT EXISTS test1(
> > id text,
> > mymap map<text,text>,
> > PRIMARY KEY(id)
> > )
> >
> > Added value:
> >
> > Insert into test(id, mymap) values ('1', {'1':'value1'});
> >
> > Then in my custom class I am trying to read mymap Cell.value() and
> > deserialize the ByteBuffervalue to get the full map content.
> >
> > But I am not getting the values as persisted in the mymap Column within
> > Cassandra.
> >
> > Is there anyone who can help?
> >
> >
> > Regards,
> > Arindam Bose
> >
>



-- 
Tyler Hobbs
DataStax <http://datastax.com/>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message