gpt4 book ai didi

java - spark与kafka集成,Spark异常-提交jar

转载 作者:可可西里 更新时间:2023-11-01 16:27:42 25 4
gpt4 key购买 nike

在提交 在 ubuntu 下将 kafka 与 spark 集成jar 文件时出现 NullPointerException。我正在尝试在 https://github.com/apache/spark/tree/v2.1.1/examples 处运行代码

我尝试检查在 Ubuntu 下安装 spark 是否需要设置 HADOOP_HOME;但是,没有设置 HADOOP_HOME,仔细检查了 jar 的参数。

./bin/spark-submit --class "org.apache.spark.examples.streaming.JavaKafkaWordCount" --packages org.apache.spark:spark-streaming-kafka-0-10_2.11:2.1.0 --master local[*] --jars ~/software/JavaKafkaWordCount.jar localhost:2181 test-consumer-group streams-plaintext-input 1

Exception in thread "main" java.lang.NullPointerException at org.apache.hadoop.fs.Path.getName(Path.java:337) at org.apache.spark.deploy.DependencyUtils$.downloadFile(DependencyUtils.scala:136) at org.apache.spark.deploy.SparkSubmit$$anonfun$prepareSubmitEnvironment$7.apply(SparkSubmit.scala:367) at org.apache.spark.deploy.SparkSubmit$$anonfun$prepareSubmitEnvironment$7.apply(SparkSubmit.scala:367) at scala.Option.map(Option.scala:146) at org.apache.spark.deploy.SparkSubmit.prepareSubmitEnvironment(SparkSubmit.scala:366) at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:143) at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:86) at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:924) at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:933) at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

最佳答案

您的路径 uri jar 不可理解,请参阅 this DependencyUtils.scala#L136

 /**
* Download a file from the remote to a local temporary directory. If the input path points to
* a local path, returns it with no operation.
*
* @param path A file path from where the files will be downloaded.
* @param targetDir A temporary directory for which downloaded files.
* @param sparkConf Spark configuration.
* @param hadoopConf Hadoop configuration.
* @param secMgr Spark security manager.
* @return Path to the local file.
*/
def downloadFile(
path: String,
targetDir: File,
sparkConf: SparkConf,
hadoopConf: Configuration,
secMgr: SecurityManager): String = {
require(path != null, "path cannot be null.")
val uri = Utils.resolveURI(path)

uri.getScheme match {
case "file" | "local" => path
case "http" | "https" | "ftp" if Utils.isTesting =>
// This is only used for SparkSubmitSuite unit test. Instead of downloading file remotely,
// return a dummy local path instead.
val file = new File(uri.getPath)
new File(targetDir, file.getName).toURI.toString
case _ =>
val fname = new Path(uri).getName()
val localFile = Utils.doFetchFile(uri.toString(), targetDir, fname, sparkConf, secMgr,
hadoopConf)
localFile.toURI().toString()
}
}

在你的 spark-submit 中像这样更改参数

--jars/fullpath/JavaKafkaWordCount.jar 而不是 --jars ~/software/JavaKafkaWordCount.jar

关于java - spark与kafka集成,Spark异常-提交jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56603460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com