Return-Path: X-Original-To: apmail-cassandra-user-archive@www.apache.org Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B4159104A4 for ; Tue, 8 Oct 2013 11:01:43 +0000 (UTC) Received: (qmail 44731 invoked by uid 500); 8 Oct 2013 11:01:41 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 44166 invoked by uid 500); 8 Oct 2013 11:01:39 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 44157 invoked by uid 99); 8 Oct 2013 11:01:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Oct 2013 11:01:39 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sanadhyaashu@gmail.com designates 209.85.223.172 as permitted sender) Received: from [209.85.223.172] (HELO mail-ie0-f172.google.com) (209.85.223.172) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Oct 2013 11:01:34 +0000 Received: by mail-ie0-f172.google.com with SMTP id x13so19285709ief.17 for ; Tue, 08 Oct 2013 04:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=wHfw3wIJk73Za1FJ8RfXzQTfVbUNE4X8LbCYNe503bk=; b=qpCueCHGQiw7e7PKfdcMZ+y4fE7ZaC51K6VwLHRVsAlbhgKBf1Yds+3CWGoG3Ep3Ep EEksjG+UX8u/dG7SZ8FuOnGYWWsy4mS/Ak0dtqfRGPi5ZHKhZypG2yy2ychAnwVd3LW+ /ndF8a/GiB9x5t3bGY0l+DHFUAcTtJuUuf6XiXt5BHi+7T2hvuGKGGuEj64pTt957aC1 JAkWgnZeSmemxVNXLyi7zKqFAvSz6f/d3jBRmyalj9I/7P0Lz+ivkAUoDNrfZHGA4zWe ndZb9SGU/o6/U5X7XosUBmxO7IfpMrd+3JLmUoSH1Q+WLYP+S/DkNSpHmYxSgKSha4yI i7Ow== MIME-Version: 1.0 X-Received: by 10.50.61.241 with SMTP id t17mr763765igr.28.1381230073467; Tue, 08 Oct 2013 04:01:13 -0700 (PDT) Received: by 10.64.93.3 with HTTP; Tue, 8 Oct 2013 04:01:13 -0700 (PDT) Date: Tue, 8 Oct 2013 16:31:13 +0530 Message-ID: Subject: Bulk Loader in Cassandra :NullPointerException-sstable.AbstractSSTableSimpleWriter.addColumn From: ashish sanadhya To: user@cassandra.apache.org Content-Type: multipart/alternative; boundary=047d7bdca968e1db9704e838af2c X-Virus-Checked: Checked by ClamAV on apache.org --047d7bdca968e1db9704e838af2c Content-Type: text/plain; charset=ISO-8859-1 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 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 --047d7bdca968e1db9704e838af2c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I have created my key and column in cassandra like this
=A0=A0=A0=A0 CREATE KEYSPACE demou
=A0=A0=A0=A0 with placement_stra= tegy =3D 'org.apache.cassandra.locator.
SimpleStrategy&= #39;
=A0=A0=A0=A0 and strategy_options =3D [{replication_factor:1}];
=A0=A0=A0=A0 CREATE COLUMN FAMILY users1
=A0=A0=A0=A0 WITH comparator = =3D UTF8Type
=A0=A0=A0=A0 AND key_validation_class=3DUTF8Type
=A0=A0= =A0=A0 AND column_metadata =3D [
=A0=A0=A0=A0 {column_name: symbol, vali= dation_class: UTF8Type}
=A0=A0=A0=A0 {column_name: timestamp1, validatio= n_class: UTF8Type}
=A0=A0=A0=A0 {column_name: Bid_Price, validation_class: UTF8Type}
=A0=A0= =A0=A0 {column_name: Ask_Price, validation_class: UTF8Type}
=A0=A0=A0=A0= ];

for creating SStable and loading a data from CSV i reffered this two=20 links[1][1][2][2] and my DataImportExample file look like this,its=20 compiled successfully but getting anexception at run time
=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0 import java.nio.ByteBuffer;
=A0=A0= =A0=A0=A0 import java.io.*;
=A0=A0=A0=A0=A0 import java.util.UUID;
= =A0=A0=A0=A0=A0 import org.apache.cassandra.db.marshal.*;
=A0=A0=A0=A0= =A0 import org.apache.cassandra.io.sstable.SSTableSimpleUnsortedWriter;
=A0=A0=A0=A0=A0 import static org.apache.cassandra.utils.ByteBufferUtil.byt= es;
=A0=A0=A0=A0=A0 import static org.apache.cassandra.utils.UUIDGen.dec= ompose;
=A0=A0=A0=A0=A0 import org.apache.cassandra.dht.IPartitioner;=A0=A0=A0=A0=A0 import org.apache.cassandra.dht.RandomPartitioner;

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

=A0=A0=A0=A0=A0=A0=A0 String keysp= ace =3D "Demou";
=A0=A0=A0=A0=A0=A0=A0 File directory =3D new File(keyspace);
=A0=A0=A0= =A0=A0=A0=A0 if (!directory.exists())
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = directory.mkdir();

=A0=A0=A0=A0=A0 IPartitioner partitioner =3D new = RandomPartitioner();

=A0=A0=A0=A0=A0=A0=A0 SSTableSimpleUnsortedWrit= er usersWriter =3D new SSTableSimpleUnsortedWriter(directory,partitioner,ke= yspace,"Users1",AsciiType.instance,null,64);

=A0=A0=A0=A0=A0=A0=A0 String line;
=A0=A0=A0=A0=A0=A0=A0 int lineNum= ber =3D 1;
=A0=A0=A0=A0=A0=A0=A0 CsvEntry entry =3D new CsvEntry();
= =A0=A0=A0=A0=A0=A0=A0 // There is no reason not to use the same timestamp f= or every column in that example.
=A0=A0=A0=A0=A0=A0=A0 long timestamp = =3D System.currentTimeMillis() * 1000;
=A0=A0=A0=A0=A0=A0=A0 while ((line =3D reader.readLine()) !=3D null)
=A0= =A0=A0=A0=A0=A0=A0 {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (entry.parse(l= ine, lineNumber))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 {=A0=A0
=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 //usersWriter.newRow(symbol);<-N= OT CLEAR ABOUT THIS STEP
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 u= sersWriter.addColumn(bytes("symbol"), bytes(entry.symbol), timest= amp);
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 usersWriter.addColumn(bytes(&= quot;timestamp1"), bytes(entry.timestamp1), timestamp);
=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 usersWriter.addColumn(bytes("Bid_= Price"), bytes(entry.Bid_Price), timestamp);
=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 usersWriter.addColumn(bytes("Ask_Price")= , bytes(entry.Ask_Price), timestamp);
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 li= neNumber++;
=A0=A0=A0=A0=A0=A0=A0 }
=A0=A0=A0=A0=A0=A0=A0 // Don'= t forget to close!
=A0=A0=A0=A0=A0=A0=A0 usersWriter.close();
=A0=A0= =A0=A0=A0=A0=A0 System.exit(0);
=A0=A0=A0 }

=A0=A0=A0 static clas= s CsvEntry
=A0=A0=A0 {
=A0=A0=A0=A0=A0=A0=A0 String symbol;
=A0=A0=A0=A0=A0=A0=A0 String timestamp1;
=A0=A0=A0=A0=A0=A0=A0 String Bi= d_Price;
=A0=A0=A0=A0=A0=A0=A0 String Ask_Price;

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

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

=A0=A0=A0=A0=A0 java -ea -cp $CLASSPATH -Xmx256M=A0=A0=A0=A0=A0=A0=A0= =A0 -Dlog4j.configuration=3Dlog4j-=A0 tools.properties=A0=A0=A0=A0=A0=A0=A0= =A0 DataImportExample "$@"
=A0=A0=A0=A0=A0 Exception in thread= "main" java.lang.NullPointerException
=A0=A0=A0 atorg.apache.= cassandra.io.sstable.AbstractSSTableSimpleWriter.addColumn(AbstractSSTableS= impleWriter.java:114)
=A0=A0=A0 at org.apache.cassandra.io.sstable.AbstractSSTableSimpleWriter.ad= dColumn(AbstractSSTableSimpleWriter.java:132)
=A0=A0=A0 at DataImportExa= mple.main(DataImportExample.java:53)


=A0 [1]: http://www.datast= ax.com/dev/blog/bulk-loading
=A0 [2]: http://amilaparanawi= thana.blogspot.in/2012/06/bulk-loading-external-data-to-cassandra.html<= /div>
--047d7bdca968e1db9704e838af2c--