对于在 YARN(yarn-client)上运行的 Spark 作业,是否可以使用位于 HDFS 中的 jar 来指定类路径
有点像使用 MapReduce 作业可以实现:
DistributedCache.addFileToClassPath(Path file, Configuration conf, FileSystem fs)
最佳答案
来自 SparkContext 文档:
def addJar(path: String): Unit
Adds a JAR dependency for all tasks to be executed on this SparkContext in the future. The path passed can be either a local file, a file in HDFS (or other Hadoop-supported filesystems), an HTTP, HTTPS or FTP URI, or local:/path for a file on every worker node.
所以我认为只需将其添加到 SparkContext 初始化中就足够了:
sc.addJar("hdfs://your/path/to/whatever.jar")
如果您只想添加一个文件,可以使用相关的 addFile()
方法。
参见docs了解更多。
关于hadoop - HDFS 中的 Spark 类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34811502/