Ich bin ziemlich neu in der funktionalen Programmierung und habe keine imperative Programmierung Hintergrund. Durch einige grundlegende Scala/Spark-Tutorials online gehen und einige Schwierigkeiten haben, eine Scala-Bewerbung durch Spark-Submission einzureichen.Problem Übergabe Anwendungsargument zu Spark-Submit mit Scala
Insbesondere bekomme ich eine java.lang.ArrayIndexOutOfBounds 0 Exception, die ich erforscht habe und festgestellt, dass das Array-Element an Position 0 der Schuldige ist. Wenn ich genauer hinsehe, sah ich, dass ein grundlegendes Debugging mir sagen könnte, ob die Main-Anwendung tatsächlich das Argument zur Laufzeit aufgriff - was nicht der Fall war. Hier ist der Code:
import org.apache.spark.{SparkConf, SparkContext}
object SparkMeApp {
def main(args: Array[String]) {
try {
//program works fine if path to file is hardcoded
//val logfile = "C:\\Users\\garveyj\\Desktop\\NetSetup.log"
val logfile = args(0)
val conf = new SparkConf().setAppName("SparkMe Application").setMaster("local[*]")
val sc = new SparkContext(conf)
val logdata = sc.textFile(logfile, 2).cache()
val numFound = logdata.filter(line => line.contains("found")).count()
val numData = logdata.filter(line => line.contains("data")).count()
println("")
println("Lines with found: %s, Lines with data: %s".format(numFound, numData))
println("")
}
catch {
case aoub: ArrayIndexOutOfBoundsException => println(args.length)
}
}
}
Um den Antrag mit Funken einreichen Ich benutze:
spark-submit --class SparkMeApp --master "local[*]" --jars target\scala-2.10\firstsparkapplication_2.10-1.0.jar NetSetup.log
... wo Netsetup.log im selben Verzeichnis wie, wo ich die Anwendung bin einreichen . Die Ausgabe der Anwendung ist einfach: 0. Wenn ich die try/catch zu entfernen, ist der Ausgang:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at SparkMeApp$.main(SparkMeApp.scala:12)
at SparkMeApp.main(SparkMeApp.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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)
Es ist erwähnenswert, dass die Anwendung fein läuft, wenn ich das Argument und hart Code den Pfad zu dem Entfernen Logdatei. Ich weiß nicht wirklich, was ich hier vermisse. Jede Richtung würde geschätzt werden. Danke im Voraus!
Fußnote: Ich habe versucht, den Dateinamen in einfache und doppelte Anführungszeichen in der Befehlszeile setzen, ohne Erfolg. – Jonathan