NoSuchMethodError: writing spark-streaming data to cassandra
Hi, I am intending to save the streaming data from kafka into Cassandra, using spark-streaming: But there seems to be problem with line javaFunctions(data).writerBuilder("testkeyspace", "test_table", mapToRow(TestTable.class)).saveToCassandra(); I am getting NoSuchMethodError. The code, the error-log and POM.xml dependencies are listed below: Please help me find the reason as to why is this happening. public class SparkStream { static int key=0; public static void main(String args[]) throws Exception { if(args.length != 3) { System.out.println("SparkStream "); System.exit(1); } Logger.getLogger("org").setLevel(Level.OFF); Logger.getLogger("akka").setLevel(Level.OFF); Map topicMap = new HashMap(); String[] topic = args[2].split(","); for(String t: topic) { topicMap.put(t, new Integer(3)); } /* Connection to Spark */ SparkConf conf = new SparkConf(); JavaSparkContext sc = new JavaSparkContext("local[4]", "SparkStream",conf); JavaStreamingContext jssc = new JavaStreamingContext(sc, new Duration(3000)); /* Receive Kafka streaming inputs */ JavaPairReceiverInputDStream messages = KafkaUtils.createStream(jssc, args[0], args[1], topicMap ); /* Create DStream */ JavaDStream data = messages.map(new Function, TestTable >() { public TestTable call(Tuple2 message) { return new TestTable(new Integer(++key), message._2() ); } } ); /* Write to cassandra */ javaFunctions(data,TestTable.class).saveToCassandra("testkeyspace","test_table"); // data.print(); //creates console output stream. jssc.start(); jssc.awaitTermination(); } } class TestTable implements Serializable { Integer key; String value; public TestTable() {} public TestTable(Integer k, String v) { key=k; value=v; } public Integer getKey(){ return key; } public void setKey(Integer k){ key=k; } public String getValue(){ return value; } public void setValue(String v){ value=v; } public String toString(){ return MessageFormat.format("TestTable'{'key={0},value={1}'}'", key, value); } } The output log is: Exception in thread "main" java.lang.NoSuchMethodError: com.datastax.spark.connector.streaming.DStreamFunctions.(Lorg/apache/spark/streaming/dstream/DStream;Lscala/reflect/ClassTag;)V at com.datastax.spark.connector.DStreamJavaFunctions.(DStreamJavaFunctions.java:17) at com.datastax.spark.connector.CassandraJavaUtil.javaFunctions(CassandraJavaUtil.java:89) at com.spark.SparkStream.main(SparkStream.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.apache.spark.deploy.SparkSubmit$.launch(SparkSubmit.scala:331) at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:75) at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala) And the POM dependencies are: org.apache.spark spark-streaming-kafka_2.10 1.1.0 org.apache.spark spark-streaming_2.10 1.1.0 com.datastax.spark spark-cassandra-connector_2.10 1.1.0 com.datastax.spark spark-cassandra-connector-java_2.10 1.0.4 org.apache.spark spark-core_2.10 1.1.1 com.msiops.footing footing-tuple 0.2 com.datastax.cassandra cassandra-driver-core 1.0.8 Thanks, Aiman This message is for the designated recipient only and may contain privileged, proprietary, or otherwise confidential information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the e-mail by you is prohibited. Where all
Re: NoSuchMethodError: writing spark-streaming data to cassandra
You're using two conflicting versions of the connector: the Scala version at 1.1.0 and the Java version at 1.0.4. I don't use Java, but I guess you only need the java dependency for your job - and with the version fixed. com.datastax.spark spark-cassandra-connector_2.10 *1.1.0* com.datastax.spark spark-cassandra-connector-java_2.10 *1.0.4* On Tue, Dec 9, 2014 at 11:16 AM, wrote: > > Hi, > > I am intending to save the streaming data from kafka into Cassandra, using > spark-streaming: > But there seems to be problem with line > javaFunctions(data).writerBuilder("testkeyspace", "test_table", > mapToRow(TestTable.class)).saveToCassandra(); > I am getting NoSuchMethodError. > The code, the error-log and POM.xml dependencies are listed below: > Please help me find the reason as to why is this happening. > > > public class SparkStream { > static int key=0; > public static void main(String args[]) throws Exception > { > if(args.length != 3) > { > System.out.println("SparkStream > "); > System.exit(1); > } > > Logger.getLogger("org").setLevel(Level.OFF); > Logger.getLogger("akka").setLevel(Level.OFF); > Map topicMap = new > HashMap(); > String[] topic = args[2].split(","); > for(String t: topic) > { > topicMap.put(t, new Integer(3)); > } > > /* Connection to Spark */ > SparkConf conf = new SparkConf(); > JavaSparkContext sc = new JavaSparkContext("local[4]", > "SparkStream",conf); > JavaStreamingContext jssc = new > JavaStreamingContext(sc, new Duration(3000)); > > > /* Receive Kafka streaming inputs */ > JavaPairReceiverInputDStream messages = > KafkaUtils.createStream(jssc, args[0], args[1], topicMap ); > > > /* Create DStream */ > JavaDStream data = messages.map(new > Function, TestTable >() > { > public TestTable call(Tuple2 > message) > { > return new TestTable(new Integer(++key), > message._2() ); > } > } > ); > > /* Write to cassandra */ > > javaFunctions(data,TestTable.class).saveToCassandra("testkeyspace","test_table"); > // data.print(); //creates console output stream. > > > jssc.start(); > jssc.awaitTermination(); > > } > } > > class TestTable implements Serializable > { > Integer key; > String value; > > public TestTable() {} > > public TestTable(Integer k, String v) > { > key=k; > value=v; > } > > public Integer getKey(){ > return key; > } > > public void setKey(Integer k){ > key=k; > } > > public String getValue(){ > return value; > } > > public void setValue(String v){ > value=v; > } > > public String toString(){ > return > MessageFormat.format("TestTable'{'key={0},value={1}'}'", key, value); > } > } > > The output log is: > Exception in thread "main" java.lang.NoSuchMethodError: > com.datastax.spark.connector.streaming.DStreamFunctions.(Lorg/apache/spark/streaming/dstream/DStream;Lscala/reflect/ClassTag;)V > at > com.datastax.spark.connector.DStreamJavaFunctions.(DStreamJavaFunctions.java:17) > at > com.datastax.spark.connector.CassandraJavaUtil.javaFunctions(CassandraJavaUtil.java:89) > at com.spark.SparkStream.main(SparkStream.java:83) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:483) > at > org.apache.spark.deploy.SparkSubmit$.launch(SparkSubmit.scala:331) > at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:75) > at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala) > > > And the POM dependencies are: > > > org.apache.spark > spark-streaming-kafka_2.10 > 1.1.0 > > > > org.apache.spark > spark-streaming_2.10 > 1.1.0 > > > > com.datastax.spark > spark-cassandra-connector_2.10 > 1.1.0 > > > com.datastax.spark > spark-cassandr
Re: NoSuchMethodError: writing spark-streaming data to cassandra
Hi, @Gerard- Thanks, i added one more dependency for conf.set("spark.cassandra.connection.host", "localhost"). But now, i am able to create a connection, but the data is not getting inserted into the cassandra table. and the logs show its getting connected and the next second getting disconnected. the full code and the logs and dependencies are below: public class SparkStream { static int key=0; public static void main(String args[]) throws Exception { if(args.length != 3) { System.out.println("parameters not given properly"); System.exit(1); } Logger.getLogger("org").setLevel(Level.OFF); Logger.getLogger("akka").setLevel(Level.OFF); Map topicMap = new HashMap(); String[] topic = args[2].split(","); for(String t: topic) { topicMap.put(t, new Integer(3)); } /* Connection to Spark */ SparkConf conf = new SparkConf(); conf.set("spark.cassandra.connection.host", "localhost"); JavaSparkContext sc = new JavaSparkContext("local[4]", "SparkStream",conf); JavaStreamingContext jssc = new JavaStreamingContext(sc, new Duration(5000)); /* connection to cassandra */ CassandraConnector connector = CassandraConnector.apply(sc.getConf()); System.out.println("+++cassandra connector created"); /* Receive Kafka streaming inputs */ JavaPairReceiverInputDStream messages = KafkaUtils.createStream(jssc, args[0], args[1], topicMap ); System.out.println("+streaming Connection done!+++"); /* Create DStream */ JavaDStream data = messages.map(new Function< Tuple2, TestTable >() { public TestTable call(Tuple2 message) { return new TestTable(new Integer(++key), message._2() ); } } ); System.out.println("JavaDStream created"); /* Write to cassandra */ javaFunctions(data).writerBuilder("testkeyspace", "test_table", mapToRow(TestTable.class)).saveToCassandra(); jssc.start(); jssc.awaitTermination(); } } class TestTable implements Serializable { Integer key; String value; public TestTable() {} public TestTable(Integer k, String v) { key=k; value=v; } public Integer getKey(){ return key; } public void setKey(Integer k){ key=k; } public String getValue(){ return value; } public void setValue(String v){ value=v; } public String toString(){ return MessageFormat.format("TestTable'{'key={0}, value={1}'}'", key, value); } } The log is: +++cassandra connector created +streaming Connection done!+++ JavaDStream created 14/12/09 12:07:33 INFO core.Cluster: New Cassandra host localhost/127.0.0.1:9042 added 14/12/09 12:07:33 INFO cql.CassandraConnector: Connected to Cassandra cluster: Test Cluster 14/12/09 12:07:33 INFO cql.LocalNodeFirstLoadBalancingPolicy: Adding host 127.0.0.1 (datacenter1) 14/12/09 12:07:33 INFO cql.LocalNodeFirstLoadBalancingPolicy: Adding host 127.0.0.1 (datacenter1) 14/12/09 12:07:34 INFO cql.CassandraConnector: Disconnected from Cassandra cluster: Test Cluster 14/12/09 12:07:45 INFO core.Cluster: New Cassandra host localhost/127.0.0.1:9042 added 14/12/09 12:07:45 INFO cql.CassandraConnector: Connected to Cassandra cluster: Test Cluster 14/12/09 12:07:45 INFO cql.LocalNodeFirstLoadBalancingPolicy: Adding host 127.0.0.1 (datacenter1) 14/12/09 12:07:45 INFO cql.LocalNodeFirstLoadBalancingPolicy: Adding host 127.0.0.1 (datacenter1) 14/12/09 12:07:46 INFO cql.CassandraConnector: Disconnected from Cassandra cluster: Test Cluster The POM.xml dependencies are: org.apache.spark spark-streaming-kafka_2.10 1.1.0 org.apache.spark spark-streaming_2.10 1.1.0 com.datastax.spark spark-cassandra-connector_2.10 1.1.0 com.datastax.spark spark-cassandra-connector-java_2.10 1.1.0 org.apache.spark spark-core_2.10 1.1.1 com.msiops.footing footing-tuple 0.2 com.datastax.cassandra cassandra-driver-core 2.1.3 Thanks and Regards, Md. Aiman Sarosh. Accenture Services Pvt. Ltd. Mob #: (+91) - 9836112841. ____ From: Gerard Maas Sent: Tuesday, December 9, 2014 4:39 PM To: Sarosh, M. Cc: spark users Subject: Re: NoSuchMethodError: writing spark-streaming data to cassandra You're using two conflicting versions of the connector: the Scala version at 1.1.0 and the Java version at 1.0.4. I don't use Java, but I guess you only need the java dependency for your job - and with the version fixed. com.datastax.spark spark-cassandra-connector_2.10 1.1.0 com.datastax.spark spark-cassandra-connector-java_2.10