【问题标题】:Spark read file from each node similar to Hadoop's DistribuitedCacheSpark 从每个节点读取文件,类似于 Hadoop 的 DistribuitedCache
【发布时间】:2017-04-12 16:35:30
【问题描述】:

我在主节点中有一个文件应该由每个节点读取。我怎样才能做到这一点?在 Hadoop 的 MapReduce 中,我使用了

DistribuitedCache.getLocalCacheFiles(context.getConfiguration())

Spark 如何在节点之间共享文件?我必须在 RAM 和广播变量中加载文件吗?还是我只能在 SparkContext 配置中指明(绝对?)文件路径,然后它立即可用于所有节点?

【问题讨论】:

    标签: file apache-spark slave


    【解决方案1】:

    您可以使用 SparkFiles 从分布式缓存中读取文件。

    import org.apache.spark.SparkFiles
    import org.apache.hadoop.fs.Path
    
    sc.addFile("/path/to/file.txt")
    val pathOnWorkerNode = new Path(SparkFiles.get("file.txt"))
    

    【讨论】:

      【解决方案2】:

      查看 spark-submit "files" 参数,例如这里:

      Running Spark jobs on a YARN cluster with additional files

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-03-09
        • 1970-01-01
        • 1970-01-01
        • 2012-01-04
        • 2013-05-15
        • 1970-01-01
        • 2020-12-12
        相关资源
        最近更新 更多