1

在此代码的帮助下,我已经使用 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 中的行键。谢谢。

4

1 回答 1

0

使用 Cassandra Bulk Loader开始:

简单编写器的方法期望 ByteBuffers 用于行键、列名和列值。将数据转换为字节是您的责任;这是 bytes() 方法存在的理由

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

usersWriter.newRow(bytes(String.valueOf(lineNumber)));
于 2013-10-11T11:45:26.097 回答