2014-12-31 350 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 

:負載詮釋線在文件