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

标签 java cassandra bulkloader

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/

相关文章:

ubuntu - 在 Ubuntu 中安装 cassandra 时出错

python - 属性错误 : 'module' object has no attribute 'strptime' -- Possible Bug?

java - 在 Ant 上为 Django 设置 Cassandra 失败 : Unable to find a javac compiler;

google-app-engine - App Engine 批量加载程序下载警告 "No descending index on __key__, performing serial download"

java - 从 GAE 批量下载日志

java - ibatis域类应该用作javabean吗?

java - Java 中的按值传递(队列)给出了意外的输出

java - Apache Lucene createFullTextQuery 返回匹配的空对象

java - Eclipse .classpath/.project 文件中有什么?

maven - java.lang.NoClassDefFoundError : com/google/common/util/concurrent/FutureFallback