如何在 HDInsight 中添加外部 jar 以激发火花?

Ani*_*oui 5 java azure apache-spark pyspark azure-hdinsight

我正在尝试在 Azure 上的 HDInsight Spark 群集中安装 Azure CosmosDB Spark 连接器。( GitHub )

我是 spark 环境的新手,我无法找到将连接器 jar 添加到 spark 配置的正确方法。

我使用的方法:

方法 1 我将 jars 上传到与 HDInsight 群集关联的 Azure Blob 存储容器上。(到example/jars/)我与spark集群头节点建立了ssh连接并运行了以下命令:

spark-shell --master yarn --conf "spark.executor.extraClassPath="wasb:///example/jars/azure-cosmosdb-spark_2.0.2_2.11-0.0.3.jar" --conf "spar.driver.extraClassPath= "wasb:///example/jar/azure-cosmosdb-spark_2.0.2_2.11-0.0.3.jar"
Run Code Online (Sandbox Code Playgroud)

spark-shell 返回以下内容:

SPARK_MAJOR_VERSION is set to 2, using Spark2
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel).
17/10/19 15:10:48 WARN SparkContext: Use an existing SparkContext, some configuration may not take effect.
Spark context Web UI available at http://10.0.0.20:4040
Spark context available as 'sc' (master = yarn, app id = application_1508418631913_0014).
Spark session available as 'spark'.
Run Code Online (Sandbox Code Playgroud)

我认为这里的问题是

SparkContext: Use an existing SparkContext, some configuration may not take effect.
Run Code Online (Sandbox Code Playgroud)

方法二

上传到 /examples/jars 后与第一种方法相同。我打开了 Ambari UI,并使用方法 1 中提到的相同值将 spark.executor.extraClassPath 和 spark.driver.extraClassPath 添加到 spark-Custom-Defaults。

这两种方法1方法2对我的开发环境没有影响。我试图导入 com.microsoft.azure.cosmosdb 并且解释器找不到它。

方法 3 我创建了一个 HDInsight 3.6 Spark 集群(不推荐用于我的情况,因为连接器在 HDInsight 3.5 上进行了测试)并且我使用 Zeppelin 将配置添加到 Livy Interpreter。我尝试了在此处找到的示例代码,但出现此错误:

java.lang.NoSuchMethodError: org.apache.spark.sql.catalyst.analysis.TypeCoercion$.findTightestCommonType()Lscala/Function2;
Run Code Online (Sandbox Code Playgroud)

经过一些谷歌搜索后,我认为这是一个类版本问题,所以我回到了 HDInsight 3.5,但仍然没有结果。

我的问题是:

Spark-Shell --conf 是应用持久配置还是仅适用于 shell 会话?

知道将来我将使用 Livy REST API 来执行可能包含此包的远程 PySpark 作业,并且我不想在每次提交远程作业时在配置上运行,我如何才能实现正确的配置?

Tho*_*Nys 1

您可以添加额外的依赖项来启动 Spark-Shell:

spark-shell --packages maven-coordinates of the package
Run Code Online (Sandbox Code Playgroud)

在你的情况下:

    spark-shell --packages com.microsoft.azure:azure-cosmosdb-spark_2.1.0_2.11:jar:1.1.2
Run Code Online (Sandbox Code Playgroud)

一个好的做法是将您的应用程序及其所有依赖项打包:

https://spark.apache.org/docs/latest/submitting-applications.html#bundling-your-applications-dependency

这也应该适用于李维。