incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ashish sanadhya <sanadhyaa...@gmail.com>
Subject Bulk Loader in Cassandra :NullPointerException-sstable.AbstractSSTableSimpleWriter.addColumn
Date Tue, 08 Oct 2013 11:01:13 GMT
I have created my key and column in cassandra like this

     CREATE KEYSPACE demou
     with placement_strategy = 'org.apache.cassandra.locator.
SimpleStrategy'
     and strategy_options = [{replication_factor:1}];
     CREATE COLUMN FAMILY users1
     WITH comparator = UTF8Type
     AND key_validation_class=UTF8Type
     AND column_metadata = [
     {column_name: symbol, validation_class: UTF8Type}
     {column_name: timestamp1, validation_class: UTF8Type}
     {column_name: Bid_Price, validation_class: UTF8Type}
     {column_name: Ask_Price, validation_class: UTF8Type}
     ];

for creating SStable and loading a data from CSV i reffered this two
links[1][1][2][2] and my DataImportExample file look like this,its compiled
successfully but getting anexception at run time

      import java.nio.ByteBuffer;
      import java.io.*;
      import java.util.UUID;
      import org.apache.cassandra.db.marshal.*;
      import org.apache.cassandra.io.sstable.SSTableSimpleUnsortedWriter;
      import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
      import static org.apache.cassandra.utils.UUIDGen.decompose;
      import org.apache.cassandra.dht.IPartitioner;
      import org.apache.cassandra.dht.RandomPartitioner;

      public class DataImportExample
      {
      static String filename;
      public static void main(String[] args) throws IOException
       {
        /*if (args.length == 0)
        {
            System.out.println("Expecting <csv_file> as argument");
            System.exit(1);
        }*/
        filename = "/home/ashish/USDJPY-2009-05.csv";
        BufferedReader reader = new BufferedReader(new
FileReader(filename));

        String keyspace = "Demou";
        File directory = new File(keyspace);
        if (!directory.exists())
            directory.mkdir();

      IPartitioner partitioner = new RandomPartitioner();

        SSTableSimpleUnsortedWriter usersWriter = new
SSTableSimpleUnsortedWriter(directory,partitioner,keyspace,"Users1",AsciiType.instance,null,64);

        String line;
        int lineNumber = 1;
        CsvEntry entry = new CsvEntry();
        // There is no reason not to use the same timestamp for every
column in that example.
        long timestamp = System.currentTimeMillis() * 1000;
        while ((line = reader.readLine()) != null)
        {
            if (entry.parse(line, lineNumber))
            {
                //usersWriter.newRow(symbol);<-NOT CLEAR ABOUT THIS STEP
                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++;
        }
        // Don't forget to close!
        usersWriter.close();
        System.exit(0);
    }

    static class CsvEntry
    {
        String symbol;
        String timestamp1;
        String Bid_Price;
        String Ask_Price;

        boolean parse(String line, int lineNumber)
        {
            // Ghetto csv parsing
            String[] columns = line.split(",");
            if (columns.length != 4)
            {
                System.out.println(String.format("Invalid input '%s' at
line %d of %s", line, lineNumber, filename));
                return false;
            }
            try
            {
                symbol = columns[0].trim();
                timestamp1 = columns[1].trim();
                Bid_Price= columns[2].trim();
                Ask_Price = columns[3].trim();

                return true;
            }
            catch (NumberFormatException e)
            {
                System.out.println(String.format("Invalid number in input
'%s' at line %d of %s", line, lineNumber, filename));
                 return false;
             }
          }
       }
     }
`
I am confused at step **usersWriter.newRow(symbol);** because i didnot
create any UUId so Is this step is right or am i getting an error just
because of this ,any help in this dircetion thank you,here is what i got
after running it.

      java -ea -cp $CLASSPATH -Xmx256M
-Dlog4j.configuration=log4j-  tools.properties         DataImportExample
"$@"
      Exception in thread "main" java.lang.NullPointerException

atorg.apache.cassandra.io.sstable.AbstractSSTableSimpleWriter.addColumn(AbstractSSTableSimpleWriter.java:114)
    at
org.apache.cassandra.io.sstable.AbstractSSTableSimpleWriter.addColumn(AbstractSSTableSimpleWriter.java:132)
    at DataImportExample.main(DataImportExample.java:53)


  [1]: http://www.datastax.com/dev/blog/bulk-loading
  [2]:
http://amilaparanawithana.blogspot.in/2012/06/bulk-loading-external-data-to-cassandra.html

Mime
View raw message