【问题标题】:cassandra timeuuid columns showing buffer type data insted of stringcassandra timeuuid 列显示字符串插入的缓冲区类型数据
【发布时间】:2015-11-26 18:05:57
【问题描述】:

我正在使用 NodeJS Cassandra 驱动程序从 Cassandra timeuuid 列中检索数据。现在以缓冲区类型而不是字符串类型检索的数据。我需要字符串类型的数据

【问题讨论】:

  • 向我们展示您已经尝试过的内容。也许我们可以提供帮助。
  • 以前“从 facehq.timeline 中选择 PostedDate”返回值“posteddate”:“f6ca25d0-ffa4-11e4-830a-b395dbb548cd”现在返回值“posteddate”:{“buffer”:[ 122,60,208,167,80,165,17,229,135,100,140,​​199,127,17,202,49]}

标签: node.js cassandra cql timeuuid


【解决方案1】:

虽然仍然难以理解您希望看到的内容,但这将以更易读的格式返回您的 PostedDate

SELECT DateOf(PostedDate) FROM facehq.timeline;

此外,随着数据规模的增长,未绑定的查询将变得有问题且速度缓慢。因此,请确保尽可能使用 WHERE 子句对此类查询进行限定。

我需要像“posteddate”这样的结果:“f6ca25d0-ffa4-11e4-830a-b395dbb548cd”。

在我看来,您的问题出在您的 node.js 代码中。你是如何执行你的查询的? Node.js driver documentation on the GitHub project page 有一个示例可能会有所帮助:

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
  });

DataStax 文档也有一个针对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
});

【讨论】:

  • 对于“从 facehq.timeline 中选择 PostedDate”,我需要像“posteddate”这样的结果:“f6ca25d0-ffa4-11e4-830a-b395dbb548cd”。现在结果是 "posteddate":{"buffer":[122,60,208,167,80,165,17,229,135,100,140,​​199,127,17,202,‌​49]}
  • @Prorammer81 When using console.log, the object is inspected, so it shows the attributes of the object 确保更新到最新版本,在最新版本的驱动程序中,每种类型都有inspect()方法实现,打印一个漂亮的“TimeUuid:xxxxxxxx-xxxx-xxxx- xxxx-xxxxxxxxxxxx" 和toJSON 方法。无论如何,toString() 是您正在寻找的,TimeUuid 的字符串表示形式。
猜你喜欢
  • 1970-01-01
  • 2022-11-12
  • 2014-11-07
  • 2014-06-05
  • 1970-01-01
  • 2015-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多