我刚刚开始使用 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")
最佳答案
sc.textFile("code/test.csv")
表示 /<hive.metastore.warehouse.dir>/code/test.csv
中的 test.csv在 HDFS 上。
sc.textFile("hdfs:///<hive.metastore.warehouse.dir>/code/test.csv")
等于上面。
sc.textFile("file:///code/test.csv")
表示 /code/test.csv
中的 test.csv在本地文件系统上。
关于apache-spark - pySpark 本地模式 - 使用文件 :///vs relative path 加载文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47546434/