ISSUE: Cassandra Custom Secondary Index reading CQLType collection values

2014-08-27 Thread Arindam Bose
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,
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


Re: ISSUE: Cassandra Custom Secondary Index reading CQLType collection values

2014-08-27 Thread Arindam Bose
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,
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 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 
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,
> 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
>


Re: ISSUE: Cassandra Custom Secondary Index reading CQLType collection values

2014-08-27 Thread Tyler Hobbs
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 
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,
> 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 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 
> 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,
> > 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 


Re: ISSUE: Cassandra Custom Secondary Index reading CQLType collection values

2014-08-27 Thread Arindam Bose
Thanks Tyler.

I am able to get the key and value, but it is only for that cell. I tried
my best but could not reference to the other cells for that Map?

For now I have added 2 rows effectively for that Map

mymap: {"1":"value1,"2":"value2"}

Also, the code as below, is returning me a list of cells but there is only
1 cell matching the name "mymap". What is the missing piece in here?

DecoratedKey dkey = StorageService.getPartitioner().decorateKey(rowKey);
QueryFilter qf =  QueryFilter.getIdentityFilter(dkey,
  baseCfs.metadata.cfName,
  Calendar.getInstance().getTimeInMillis());
ColumnFamily cf = baseCfs.getColumnFamily(qf);




Regards,
Arindam Bose
+1 469-231-3862


On Wed, Aug 27, 2014 at 1:04 PM, Tyler Hobbs  wrote:

> 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 
> 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,
> > 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 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 
> > 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,
> > > 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 
>


Re: ISSUE: Cassandra Custom Secondary Index reading CQLType collection values

2014-08-27 Thread Tyler Hobbs
On Wed, Aug 27, 2014 at 3:28 PM, Arindam Bose 
wrote:

>
> Also, the code as below, is returning me a list of cells but there is only
> 1 cell matching the name "mymap". What is the missing piece in here?


The cell names are composites.  They look like (clustering_column_1,
clustering_column_2, ..., clustering_column_n, "mymap", map_key).  To make
that work with your current code, you would do something like see if
cell.name().cql3ColumnName(baseCfs.metadata).toString().equals("mymap") is
true.

However, it would be more efficient to just limit your slice to that
collection.

-- 
Tyler Hobbs
DataStax