我已经在这个代码的帮助下用key_validation_class=LexicalUUIDType完成了新行的批量加载器,但是我已经改变了我的key_validation_class=AsciiType或key_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++;
}
按预期收到错误,它只占用字节缓冲区
usersWriter.newRow(String.valueOf(lineNumber));
^
required: ByteBuffer
found: String
reason: actual argument String cannot be converted to ByteBuffer by method invocation conversion
任何帮助使字符串作为上述列系列定义的稳定版中的行键.谢谢。
来自使用 Cassandra Bulk Loader:
简单编写器的方法需要 ByteBuffers 作为行键, 列名和列值。将数据转换为字节是您 责任;这是 bytes(( 方法存在的理由。
所以你应该编写如下代码:
usersWriter.newRow(bytes(String.valueOf(lineNumber)));