介绍一下Spark-shell。 在工作中,无论是数据分析师,还是数据工程师, sparkshell 都是他们必不可少的一项强大的武器。除了批量任务使用spark-submit 提交以外,平时很多工作都要使用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包中类。在工作中会有用到。
閱讀更多 從大數據說起 的文章