gpt4 book ai didi

java - cassandra 中的批量加载器 : String as row keys in cassandra

转载 作者:行者123 更新时间:2023-12-01 04:17:19 26 4
gpt4 key购买 nike

code 的帮助下,我已经使用 key_validation_class=LexicalUUIDType 为新行完成了批量加载。但我已经更改了 key_validation_class=AsciiTypekey_validation_class=UTF8Type 以使字符串作为行键

  create column family Users1
with key_validation_class=AsciiType
and comparator=AsciiType
AND column_metadata = [
{column_name: timestamp1, validation_class: AsciiType}
{column_name: symbol, validation_class: AsciiType}
{column_name: Bid_Price, validation_class:AsciiType}
{column_name: Ask_Price, validation_class:AsciiType}
];

我已经尝试了所有可能的代码更改,以使行键成为字符串类型,但出现错误,甚至没有 usersWriter.newRow 无法写入 sstable

  while ((line = reader.readLine()) != null)
{
if (entry.parse(line, lineNumber))
{
//usersWriter.newRow(uuid);
usersWriter.newRow(String.valueOf(lineNumber));
usersWriter.addColumn(bytes("symbol"), bytes(entry.symbol), timestamp);
usersWriter.addColumn(bytes("timestamp1"), bytes(entry.timestamp1), timestamp);
usersWriter.addColumn(bytes("Bid_Price"), bytes(entry.Bid_Price), timestamp);
usersWriter.addColumn(bytes("Ask_Price"), bytes(entry.Ask_Price), timestamp);
}
lineNumber++;
}

如预期出现错误,它只使用ByteBuffer

 usersWriter.newRow(String.valueOf(lineNumber));
^
required: ByteBuffer
found: String
reason: actual argument String cannot be converted to ByteBuffer by method invocation conversion

任何帮助将字符串作为上述列族定义的 sstable 中的行键。谢谢。

最佳答案

来自Using the Cassandra Bulk Loader :

The methods of the simple writer expect ByteBuffers for the row key, column name and column value. Converting data to bytes is your responsibility; this is the raison d’être of the bytes() method.

所以你应该编写如下代码:

usersWriter.newRow(bytes(String.valueOf(lineNumber)));

关于java - cassandra 中的批量加载器 : String as row keys in cassandra,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19313392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com