Question

I have done with bulk loader with key_validation_class=LexicalUUIDType for new row with the help of this code but i have changed my key_validation_class=AsciiType or key_validation_class=UTF8Type in order to make string as row keys

  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}
  ];

i have tried all possible changes to code in order to make row keys as string type but getting an error or even without usersWriter.newRow not able to write into 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++;
    }

getting an error as expected it is only taking ByteBuffer

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

Any help to make string as row keys in sstable for the above column family definition.thanks.

Was it helpful?

Solution

From 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.

So you should write the code as follow:

usersWriter.newRow(bytes(String.valueOf(lineNumber)));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top