3

I am retrieving data from Cassandra timeuuid column using NodeJS Cassandra driver. Now the data retrieved as buffer type instead of string type. I need the data as string type

Brad Schoening
  • 1,281
  • 6
  • 22
Prorammer81
  • 198
  • 1
  • 1
  • 15
  • 1
    Show us what you already tried. Maybe we can help. – Gepser Hoil Sep 01 '15 at 13:26
  • Previously "select PostedDate from facehq.timeline" returns the value "posteddate":"f6ca25d0-ffa4-11e4-830a-b395dbb548cd" now it is returning value "posteddate":{"buffer":[122,60,208,167,80,165,17,229,135,100,140,199,127,17,202,49]} – Prorammer81 Sep 01 '15 at 13:46

1 Answers1

2

While it's still difficult to understand what you're expecting to see, this will return your PostedDate in a more-readable format:

SELECT DateOf(PostedDate) FROM facehq.timeline;

Also, as your data grows in size, unbound queries will become problematic and slow. So make sure you qualify queries like this with a WHERE clause whenever possible.

i need result like "posteddate":"f6ca25d0-ffa4-11e4-830a-b395dbb548cd".

It sounds to me like your issue is in your node.js code. How are you executing your query? The Node.js driver documentation on the GitHub project page has an example that may help:

client.stream('SELECT time, val FROM temperature WHERE station_id=', ['abc'])
  .on('readable', function () {
    //readable is emitted as soon a row is received and parsed
    var row;
    while (row = this.read()) {
      console.log('time %s and value %s', row.time, row.val);
    }
  })
  .on('end', function () {
    //stream ended, there aren't any more rows
  })
  .on('error', function (err) {
    //Something went wrong: err is a response error from Cassandra
  });

The DataStax documentation also has a specific example for working with timeUUIDs:

client.execute('SELECT id, timeid FROM sensor', function (err, result) {
    assert.ifError(err);
    console.log(result.rows[0].timeid instanceof TimeUuid); // true
    console.log(result.rows[0].timeid instanceof Uuid); // true, it inherits from Uuid
    console.log(result.rows[0].timeid.toString());      // <- xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    console.log(result.rows[0].timeid.getDate());       // <- Date stored in the identifier
});
Aaron
  • 55,518
  • 11
  • 116
  • 132
  • For the "select PostedDate from facehq.timeline" i need result like "posteddate":"f6ca25d0-ffa4-11e4-830a-b395dbb548cd". Now the result is "posteddate":{"buffer":[122,60,208,167,80,165,17,229,135,100,140,199,127,17,202,‌​49]} – Prorammer81 Sep 01 '15 at 14:12
  • @Prorammer81 [When using `console.log`, the object is inspected, so it shows the attributes of the object](https://nodejs.org/api/console.html#console_console_log_data) Make sure to update to the latest version, in latest version of the driver, each type has `inspect()` method implemented, printing a nice "TimeUuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" and [toJSON](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior) method. Anyhow, `toString()` is what you are looking for, the string representation of a TimeUuid. – jorgebg Sep 02 '15 at 07:40