【问题标题】:AWS Cassandra nodejs - strange resultsAWS Cassandra nodejs - 奇怪的结果
【发布时间】:2021-01-11 23:55:36
【问题描述】:

我希望在 nodejs 中使用 cassandra-driver 来使用 cassandra。

当我执行这样的简单查询时:

  const results = await chatDbClient.execute('SELECT * FROM chat_db.messages LIMIT 5');
  return results.rows;

我收到以下结果:

Row from Keyspaces Row {
  user_from: [Long],
  user_to: [Long],
  message_id: [TimeUuid],
  body: 'c'
}
[
  Row {
    user_from: Long { low: 1, high: 0, unsigned: false },
    user_to: Long { low: 2, high: 0, unsigned: false },
    message_id: TimeUuid {
      buffer: <Buffer f0 c2 49 b1 fd a4 11 ea 8b 02 85 9f 38 c2 63 74>
    },
    body: 'c'
  },
  Row {
    user_from: Long { low: 1, high: 0, unsigned: false },
    user_to: Long { low: 2, high: 0, unsigned: false },
    message_id: TimeUuid {
      buffer: <Buffer f0 c2 22 a3 fd a4 11 ea bc 5e cb 7d 37 47 a0 82>
    },
    body: 'f'
  },
  Row {
    user_from: Long { low: 1, high: 0, unsigned: false },
    user_to: Long { low: 2, high: 0, unsigned: false },
    message_id: TimeUuid {
      buffer: <Buffer f0 c2 22 a2 fd a4 11 ea bc 5e cb 7d 37 47 a0 82>
    },
    body: 'e'
  },
  Row {
    user_from: Long { low: 1, high: 0, unsigned: false },
    user_to: Long { low: 2, high: 0, unsigned: false },
    message_id: TimeUuid {
      buffer: <Buffer f0 c1 fb 95 fd a4 11 ea a3 0f 3b e9 2e a5 73 87>
    },
    body: 'd'
  },
  Row {
    user_from: Long { low: 1, high: 0, unsigned: false },
    user_to: Long { low: 2, high: 0, unsigned: false },
    message_id: TimeUuid {
      buffer: <Buffer f0 c1 fb 94 fd a4 11 ea a3 0f 3b e9 2e a5 73 87>
    },
    body: 'm'
  }
]

但如果我出于测试目的直接从 aws 仪表板执行查询,我会收到:

为什么在我的应用中结果格式如此奇怪?

提前发送

【问题讨论】:

    标签: node.js amazon-web-services cassandra cql


    【解决方案1】:

    问题解决了,读取数据就够用了:toString()

    results.rows[i].user_to.toString()

    【讨论】:

      【解决方案2】:

      在您的应用中尝试以下操作

      console.log(result.rows[0].timeid instanceof TimeUuid);
      

      【讨论】:

      • 如果我从 cassandra 驱动程序导入 TimeUuid 的实例,结果是:true
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-28
      • 2012-12-16
      • 2012-12-06
      • 2016-08-24
      • 2018-01-24
      • 2021-03-01
      相关资源
      最近更新 更多