Ich versuche, DataFrame mit Spark sqlContext zu erstellen. Ich habe Spark 1.6.3 und Scala 2.10.5 verwendet. Unten ist mein Code zum Erstellen von DataFrames.Spark: Erstellen von DataFrame gibt Ausnahme
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
import org.apache.spark.sql.SQLContext
import com.knoldus.pipeline.KMeansPipeLine
object SimpleApp{
def main(args:Array[String]){
val conf = new SparkConf().setAppName("Simple Application")
val sc = new SparkContext(conf)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
import sqlContext.implicits._
val kMeans = new KMeansPipeLine()
val df = sqlContext.createDataFrame(Seq(
("[email protected]", 12000,"M"),
("[email protected]", 43000,"M"),
("[email protected]", 5000,"F"),
("[email protected]", 60000,"M")
)).toDF("email", "income","gender")
val categoricalFeatures = List("gender","email")
val numberOfClusters = 2
val iterations = 10
val predictionResult = kMeans.predict(sqlContext,df,categoricalFeatures,numberOfClusters,iterations)
}
}
Es gibt mir die folgende Ausnahme. Welchen Fehler mache ich? Kann mir jemand helfen, das zu lösen?
Exception in thread "main" java.lang.NoSuchMethodError:
org.apache.spark.sql.SQLContext.createDataFrame(Lscala/collection/Seq;Lscala/ref lect/api/TypeTags$TypeTag;)Lorg/apache/spark/sql/Dataset;
at SimpleApp$.main(SimpleApp.scala:24)
at SimpleApp.main(SimpleApp.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Die Abhängigkeiten ich verwendet habe, sind:
scalaVersion := "2.10.5"
libraryDependencies ++= Seq(
"org.apache.spark" % "spark-core_2.10" % "2.0.0" % "provided",
"org.apache.spark" % "spark-sql_2.10" % "2.0.0" % "provided",
"org.apache.spark" % "spark-mllib_2.10" % "2.0.0" % "provided",
"knoldus" % "k-means-pipeline" % "0.0.1")
Ihr Code funktioniert gut für mich. Ich nehme an, dass Ihre Spark-Binärdateien mit Scala 2.11 kompiliert wurden, so dass sie nicht mit Ihrem Code mit Spark 2.10 laufen können, das umgekehrte Problem des hier beschriebenen: http://stackoverflow.com/questions/27728731/scala-code- throw-exception-in-spark –
@TzachZohar Wie kann ich das beheben? – Balkrushn
Erstens - Ihre Abhängigkeiten zeigen, dass Sie Spark 2.0.0 nicht 1.6.3 verwenden, wie Sie oben angeben. Spark 2.0.0 verwendet Scala 2.11 standardmäßig, soweit ich weiß, wenn Sie es mit Scala 2.10 verwenden möchten, müssen Sie es selbst erstellen, siehe http://spark.apache.org/docs/latest/building- spark.html # Gebäude-für-Scala-210. Verwenden Sie also entweder Scala 2.11 oder verwenden Sie eine Spark-Version, die gemäß dieser Anleitung kompiliert wurde. –