【问题标题】:pySpark local mode - loading text file with file:/// vs relative pathpySpark 本地模式 - 使用 file:/// 与相对路径加载文本文件
【发布时间】:2017-11-29 16:49:05
【问题描述】:

我刚刚开始使用 spark,我正在尝试本地模式下的示例... 我注意到,在创建 RDD 的某些示例中,使用了文件的相对路径,而在其他示例中,路径以“file:///”开头。第二个选项对我根本不起作用 - “输入路径不存在”

谁能解释一下使用文件路径和把'file:///'放在它前面有什么区别?

我在本地模式下运行的 Mac 上使用 Spark 2.2

from pyspark import SparkConf, SparkContext
conf = SparkConf().setMaster("local").setAppName("test")
sc = SparkContext(conf = conf)

#This will work providing the relative path
lines = sc.textFile("code/test.csv")

#This will not work
lines = sc.textFile("file:///code/test.csv")

【问题讨论】:

  • 不会file:///code/test.csv 意味着你的路径是/code/test.csv 吗?
  • 如果我把 file:// 我得到一个错误 "expected: file:///"
  • file:// 需要本地文件系统的完整路径。由于你是在本地模式下运行,如果你提供了一个不带file://的相对路径,spark会在内部自动生成完整路径。

标签: apache-spark pyspark


【解决方案1】:

sc.textFile("code/test.csv") 表示 HDFS 上 /<hive.metastore.warehouse.dir>/code/test.csv 中的 test.csv

sc.textFile("hdfs:///<hive.metastore.warehouse.dir>/code/test.csv") 等于上面。

sc.textFile("file:///code/test.csv") 表示本地文件系统上/code/test.csv 中的 test.csv

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 2013-09-09
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    相关资源
    最近更新 更多