Error accessing cassandra from a spark in java: cannot import CassandraJavaUtil

I am using the following blog in setup to access Cassandra from an apache spark.

" http://www.datastax.com/dev/blog/accessing-cassandra-from-spark-in-java " " https://gist.github.com/jacek-lewandowski/278bfc936ca990bee35a#file-javademo-java- L177 "

However, I cannot import the dependency of the CassandraJavaUtil class, and the error message "Import cannot be resolved" appears in my eclipse.

import static com.datastax.spark.connector.CassandraJavaUtil.*; 

Please help me fix this error.

Many thanks.

+7
cassandra apache-spark datastax
source share
2 answers

I also followed the example in the first document that you linked. You will notice that in the Prerequisites section, step # 2 requires you to create an example as a Maven project. Step 3 lists the four dependencies that you need to add to the project. Two of these dependencies are specific to the Spark Connector:

  • com.datastax.spark: spark Cassandra-connector_2.10: 1.0.0-RC4
  • com.datastax.spark: spark Cassandra-connector-java_2.10: 1.0.0-RC4

Basically, the pom.xml "dependencies" pom.xml for my Spark projects is as follows:

  <dependencies> <dependency> <groupId>com.datastax.spark</groupId> <artifactId>spark-cassandra-connector_2.10</artifactId> <version>1.1.0-alpha2</version> </dependency> <dependency> <groupId>com.datastax.spark</groupId> <artifactId>spark-cassandra-connector-java_2.10</artifactId> <version>1.1.0-alpha2</version> </dependency> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-core_2.10</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-streaming_2.10</artifactId> <version>1.1.0</version> </dependency> </dependencies> 

Double check that your pom.xml has these dependencies and then call Maven to distribute the Spark Connector libraries locally. This worked for me:

 cd workspace/sparkTest2 mvn package 
+8
source share

The CassandraJavaUtil class is now moved to the japi package in com.datastax.spark.connector

So try using: -

 import static com.datastax.spark.connector.japi.CassandraJavaUtil.*; 

Note: According to this document:

https://github.com/datastax/spark-cassandra-connector/blob/master/doc/7_java_api.md

Starting with version 1.1.x, the Java API comes with several useful factory methods that can be used to create factories for line readers of two main types: based on a type converter and based on columns.

Also note that the syntax for using CassandraJavaUtil.javaFunctions() also changed. Read the link above carefully.

+3
source share

All Articles