Spark: как запустить файл spark из spark shell
Я использую CDH 5.2. Я могу использовать spark-shell для запуска команд. как запустить файл (file.spark), которые содержат команды spark. Во-вторых, есть ли способ запустить/скомпилировать программы scala в CDH 5.2 без sbt?
заранее спасибо,
4 ответов
чтобы загрузить внешний файл из spark-shell, просто сделайте
:load PATH_TO_FILE
Это все в файл.
У меня нет решения для вашего вопроса SBT, хотя извините : -)
в командной строке, вы можете использовать
spark-shell -i file.scala
для запуска кода, который написан в file.scala
вы можете использовать sbt или maven для компиляции программ spark. Просто добавьте искру как зависимость от maven
<repository>
<id>Spark repository</id>
<url>http://www.sparkjava.com/nexus/content/repositories/spark/</url>
</repository>
а затем зависимость:
<dependency>
<groupId>spark</groupId>
<artifactId>spark</artifactId>
<version>1.2.0</version>
</dependency>
С точки зрения запуска файла с командами spark: вы можете просто сделать это:
echo"
import org.apache.spark.sql.*
ssc = new SQLContext(sc)
ssc.sql("select * from mytable").collect
" > spark.input
теперь запустите скрипт команд:
cat spark.input | spark-shell
просто чтобы дать больше перспективы для ответов
Spark-shell является Scala repl
вы можете :помогите чтобы увидеть список операций, которые возможны внутри оболочки scala
scala> :help
All commands can be abbreviated, e.g., :he instead of :help.
:edit <id>|<line> edit history
:help [command] print this summary or command-specific help
:history [num] show the history (optional num is commands to show)
:h? <string> search the history
:imports [name name ...] show import history, identifying sources of names
:implicits [-v] show the implicits in scope
:javap <path|class> disassemble a file or class name
:line <id>|<line> place line(s) at the end of history
:load <path> interpret lines in a file
:paste [-raw] [path] enter paste mode or paste a file
:power enable power user mode
:quit exit the interpreter
:replay [options] reset the repl and replay all previous commands
:require <path> add a jar to the classpath
:reset [options] reset the repl to its initial state, forgetting all session entries
:save <path> save replayable session to a file
:sh <command line> run a shell command (result is implicitly => List[String])
:settings <options> update compiler options, if possible; see reset
:silent disable/enable automatic printing of results
:type [-v] <expr> display the type of an expression without evaluating it
:kind [-v] <expr> display the kind of expression's type
:warnings show the suppressed warnings from the most recent line which had any
: загрузка строк интерпретации в файл