Nodejs cassandra datatype issue

I am using the node-cassandra-cql driver ( https://github.com/jorgebay/node-cassandra-cql ) to fetch a sample on the cassandra column family.

My cf has three columns with datatypes like this:

1 - value -> text
2 - date  -> timestamp
3 - hits  -> counter

      

Using nodeJS to extract strings, I am doing:

client.execute('SELECT date,value,hits FROM cf LIMIT 100', [],
      function(err, result) {
        if(err){
            var error = {error:true,message:err};
            res.send(error);
        }
        else{
            var trends = {};
            for(var i=0;i<result.rows.length;i++){
                var row      = result.rows[i];
                console.log(row.date);
                console.log(row.hits);
            }
        }
        }
);

      

The console log gives me:

{
    "low": 1342763392,
    "high": 323,
    "unsigned": false
}
{
    "low": 1,
    "high": 0,
    "unsigned": false
}

      

What do I need to do to get the correct value?

Thank!

+3


source to share


2 answers


The Cassandra counter column value is a 64-bit signed integer (bigints), represented as Google Closure Long in the Node.js driver .

To get the string representation of the bigint decimal value, you can use the #toString () method.



//"1", "2", ...
row.hits.toString();

      

+4


source


Jorgebg's answer to this question also applies when doing COUNT (*).

For example: SELECT COUNT (*) FROM my_table;



In this case, to retrieve the value I used: result.rows [0] .count.toString ();

0


source







All Articles