2014-12-31 304 views

回答

57

要加载的火花外壳的外部文件根本就

:load PATH_TO_FILE 

这将调用文件的一切。

我没有因为虽然对不起:-)

+1

嗨,这个命令工作,如果我有一个文件在本地机器,但是有可能将此位置作为hdfs路径。即:加载hdfs://本地主机:9000 /文件 –

+0

它不适合我。我正在使用CDH 5.7快速启动虚拟机 –

7

您可以使用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> 

在运行火花命令的文件的方式:你可以简单地这样做:

echo" 
    import org.apache.spark.sql.* 
    ssc = new SQLContext(sc) 
    ssc.sql("select * from mytable").collect 
" > spark.input 

现在运行命令脚本:

cat spark.input | spark-shell 
+0

Downvoting上显然是有用的答案会至少应该为你的担忧作出解释。 – javadba

83

在命令行中,您的SBT问题的解决方案,你可以使用

spark-shell -i file.scala 

运行这是写在file.scala

+4

谢谢,因为这不是在'火星壳-h' – hbogert

+4

我试过了命令,但它不运行代码从文件,而不是启动scala shell –

+1

@AlexRajKaliamoorthy我可能会迟到。只是想帮助你的评论/问题。它确实执行,但是你需要在脚本的末尾包含System.exit(0)以退出spark-shell – letsBeePolite

1

代码只是为了给予更多的回答

火星壳是斯卡拉排斥

您可以键入:帮助看到了可能的斯卡拉壳内操作的列表

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 

:负载诠释线在文件