代码之家  ›  专栏  ›  技术社区  ›  Prorammer81

cassandra timeuuid列显示缓冲区类型数据而不是字符串

  •  3
  • Prorammer81  · 技术社区  · 9 年前

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

    1 回复  |  直到 8 年前
        1
  •  2
  •   Aaron    9 年前

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

    SELECT DateOf(PostedDate) FROM facehq.timeline;
    

    此外,随着数据大小的增长,未绑定查询将变得有问题且速度缓慢。因此,确保尽可能使用WHERE子句限定这样的查询。

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

    在我看来,你的问题就在你的节点上。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
      });
    

    DataTax文档还提供了一个特定的示例 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
    });