gpt4 book ai didi

scala - 必须包含 log4J,但它会导致 Apache Spark shell 出错。如何避免错误?

转载 作者:行者123 更新时间:2023-12-04 09:41:41 24 4
gpt4 key购买 nike

由于我必须将 jar 包含到 Spark 代码中的复杂性,我想寻求帮助找出解决此问题的方法而不删除 log4j 导入。

简单代码如下:

    :cp symjar/log4j-1.2.17.jar
import org.apache.spark.rdd._

val hadoopConf=sc.hadoopConfiguration;
hadoopConf.set("fs.s3n.impl", "org.apache.hadoop.fs.s3native.NativeS3FileSystem")
hadoopConf.set("fs.s3n.awsAccessKeyId","AKEY")
hadoopConf.set("fs.s3n.awsSecretAccessKey","SKEY")
val numOfProcessors = 2
val filePath = "s3n://SOMEFILE.csv"
var rdd = sc.textFile(filePath, numOfProcessors)
def doStuff(rdd: RDD[String]): RDD[String] = {rdd}
doStuff(rdd)

首先,我收到这个错误:

error: error while loading StorageLevel, class file '/root/spark/lib/spark-assembly-1.3.0-hadoop1.0.4.jar(org/apache/spark/storage/StorageLevel.class)' has location not matching its contents: contains class StorageLevel
error: error while loading Partitioner, class file '/root/spark/lib/spark-assembly-1.3.0-hadoop1.0.4.jar(org/apache/spark/Partitioner.class)' has location not matching its contents: contains class Partitioner
error: error while loading BoundedDouble, class file '/root/spark/lib/spark-assembly-1.3.0-hadoop1.0.4.jar(org/apache/spark/partial/BoundedDouble.class)' has location not matching its contents: contains class BoundedDouble
error: error while loading CompressionCodec, class file '/root/spark/lib/spark-assembly-1.3.0-hadoop1.0.4.jar(org/apache/hadoop/io/compress/CompressionCodec.class)' has location not matching its contents: contains class CompressionCodec

然后,我再次运行这一行,错误消失了:

var rdd = sc.textFile(filePath, numOfProcessors)

然而,代码的最终结果是:

error: type mismatch;
found : org.apache.spark.rdd.org.apache.spark.rdd.org.apache.spark.rdd.org.apache.spark.rdd.org.apache.spark.rdd.RDD[String]
required: org.apache.spark.rdd.org.apache.spark.rdd.org.apache.spark.rdd.org.apache.spark.rdd.org.apache.spark.rdd.RDD[String]
doStuff(rdd)
^

如何避免从导入中删除 log4j 而不会出现上述错误? (这很重要,因为我大量使用 log4j 的 jar 与 Spark-Shell 有冲突)。

最佳答案

答案不是只使用 :cp 命令,而是在 export SPARK_SUBMIT_CLASSPATH=".../the/path/to/a.jar"

关于scala - 必须包含 log4J,但它会导致 Apache Spark shell 出错。如何避免错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29375027/

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