大數據工程師必會spark-shell

介紹一下Spark-shell。 在工作中,無論是數據分析師,還是數據工程師, sparkshell 都是他們必不可少的一項強大的武器。除了批量任務使用spark-submit 提交以外,平時很多工作都要使用spark-shell來完成。

大數據工程師必會spark-shell

大數據工程師必會spark-shell

1.啟動spark-shell

在Spark-shell 中,有一個專有的SparkContext和SqlContext 已經為你創建好。在變量中叫做 sc和sqlContext。你自己創建的 SparkContext 將無法工作。可以用 --master 參數來設置 SparkContext 要連接的集群,用 --jars 來設置需要添加到 classpath 中的 JAR 包,如果有多個 JAR 包使用逗號分割符連接它們。例如:在一個擁有 4 核的環境上運行 bin/spark-shell,使用:

spark-shell --master yarn-client \

--queue default \

--driver-memory 2g \

--num-executors 8 \

--executor-memory 10g \

--executor-cores 4 \

--conf spark.sql.shuffle.partitions=1000 \

--jars /home/mcloud/platform3/lib-iplocation-0.0.1.jar

注意:--master只能指定為yarn-client,也就是driver在你執行這臺命令的機器上啟動。

2.查看spark-shell幫助

執行 spark-shell --help 獲取完整的選項列表。

3.配置有用的參數

--conf spark.driver.userClassPathFirst=true \

--conf spark.executor.userClassPathFirst=true \

默認是false,官方說明為:

(Experimental) Whether to give user-added jars precedence over Spark's own jars when loading classes in the the driver. This feature can be used to mitigate conflicts between Spark's dependencies and user dependencies. It is currently an experimental feature. This is used in cluster mode only.

設置為true,表示為spark executor再啟動時優先加載--jars 所設置的jar包中類。在工作中會有用到。


分享到:


相關文章: