apache-spark - pySpark 本地模式 - 使用文件 :///vs relative path 加载文本文件

标签 apache-spark pyspark

我刚刚开始使用 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/

相关文章:

python - Pyspark sc.textFile() 没有完全加载文件

apache-spark - pyspark createdataframe : string interpreted as timestamp,模式混合列

python - 如何加入 Pyspark 中的多个列?

scala - 如何在 MLlib 中编写自定义 Transformer?

hadoop - 如何访问 s3a ://files from Apache Spark?

python - Pyspark 替换 Spark 数据框列中的字符串

python - pyspark:返回不完整的 URI 错误

apache-spark - YARN 如何在集群模式下了解 Apache Spark 中的数据位置

scala - 使用 yarn-cluster 模式初始化 SparkContext 时出错

python - 创建合并其他两个列的 Pyspark DataFrame 列,为什么我收到 'unicode' 对象没有属性 isNull 的错误?