Newbie to spark and scala. I'm trying to execute a very simple spark program via intellij-idea. All it is doing is:
- Connect to a mongodb database to a specific collection
- Load data
- print the first record.
It was working fine, but now it is throwing the error:
org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.lang.Class.
Here is my code:
import org.apache.spark.{SparkConf, SparkContext}
import com.mongodb.spark._
import com.mongodb.spark.rdd.MongoRDD
import org.bson.Document
import com.mongodb.spark.config._
import org.apache.spark.sql.SQLContext
import com.mongodb.spark.sql._
import scala.reflect.runtime.universe._
object Analytics1 {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Analytics1").setMaster("local").
set("spark.mongodb.input.uri","mongodb://192.168.56.1:27017/events.entEvent")
.set("spark.mongodb.output.uri", "mongodb://192.168.56.1:27017/events..entResult")
val sc = new SparkContext(conf)
val rdd = sc.loadFromMongoDB()
println(rdd.first())
sc.stop()
}
}
Here is my .sbt. If i use the latest version of spark, then it throws this error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/sql/DataFrame
so I'm using 1.6.1, which was working fine until a few days ago, but now it is throwing the
java.lang.class
error. Someone please help so that I can get moving. Since this is very basic, i'm hopeful that someone will throw some advise and get me unblocked.
Thanks.
name := "Simple Project"
version := "1.0"
scalaVersion := "2.11.7"
// libraryDependencies += "org.apache.spark" %% "spark-core" % "1.6.1"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.6.1"
//libraryDependencies += "org.apache.spark" % "spark-mllib_2.11" % "1.6.1"
libraryDependencies += "org.apache.spark" %% "spark-mllib" % "1.6.1"
//libraryDependencies += "org.mongodb.spark" % "mongo-spark-connector_2.10" % "1.1.0"
libraryDependencies += "org.mongodb.spark" %% "mongo-spark-connector" % "1.1.0"
libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "1.2.1"
libraryDependencies += "org.apache.spark" %% "spark-sql" % "1.6.1"
resolvers += "Akka Repository" at "http://repo.akka.io/releases/"
resolvers += "snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/ "
resolvers += "releases" at "https://oss.sonatype.org/content/repositories/releases/"