1

I am using helenus in my node-js project to get/set values in cassandra. I have a MapType field inside my Table, but when I retrieve the value from the table, I get an empty key-value set.

Below is the schema for my table

CREATE TABLE datapoints (
  id uuid PRIMARY KEY,
  created_at timestamp,
  properties map<text,text>
);

I have inserted the values from cql using the query below

INSERT INTO datapoints (id, properties) VALUES (24053e20-63e9-11e3-8d81-0002a5d5c51b, { 'fruit' : 'apple', 'band' : 'Beatles' });

Below is my nodejs code:

var helenus = require('/usr/local/lib/node_modules/helenus')
var pool = new helenus.ConnectionPool({
    hosts      : ['localhost:9160'],
    keyspace   : 'mykeyspace',
    timeout    : 3000
  });
pool.connect(function(err, keyspace){
  if(err){
    console.log("connect me error")
    throw(err);
  } else {
    pool.cql("SELECT * FROM datapoints", [], function(err,results){
      console.log("results", results)
      results.forEach(function(row){
        props = row.get('properties').value;
        var id = row.get('id').value;
        console.log("properties", props);
        console.log("id", id);
      });
    })
  }
});

The line console.log("properties", props); returns me a function, and when I call that function, I get an empty key value set. Please help.

Rohit
  • 5,631
  • 4
  • 31
  • 59
  • The function that I get for the `maptype` field, requires an argument to be passed. I am confused over what this argument must be. I have tried to pass the column_name `properties` in this case, but still it returns me an empty key value. – Rohit Dec 14 '13 at 06:51
  • It looks like [helenus doesn't play nice with map data types](https://github.com/simplereach/helenus/issues/113). You can try with [node-cassandra-cql](https://github.com/jorgebay/node-cassandra-cql), it decodes map values into JavaScript Objects. Applied to your case, you would get something like `properties.fruit` `//apple` DISCLAIMER: I'm a developer on the node-cassandra-cql driver – jorgebg Dec 14 '13 at 20:54
  • helenus does play nice with all data types when using CQL but not with Thrift as it is impossible to tell what the column type is as it is not passed over the thrift protocol. There was simple issue with decoding the values that I have fixed in the latest version. – Russ Bradberry Dec 15 '13 at 18:52

1 Answers1

1

It seems there was an issue with the deserialization of the collection types. The pull request that was made in the past broke the deserialization. I just pushed a fix to version 0.6.8 that should take care of this.

Russ Bradberry
  • 10,705
  • 17
  • 69
  • 85
  • Thanks @Russ, this worked for me. When can we expect the support for collection types via thrift ? – Rohit Dec 16 '13 at 05:51
  • The Thrift interface can not support collection types because the meta-data for non `COMPACT STORAGE` column families is not exposed to the Thrift interface. If you want to use collection types you have to use CQL. – Russ Bradberry Dec 16 '13 at 15:28