apache-spark - 如何处理在火花中读取不存在的文件
问题描述
我正在尝试使用 spark 从 HDFS 读取一些文件sc.wholeTextFiles
,我传递了所需文件的列表,但工作一直在抛出
py4j.protocol.Py4JJavaError: An error occurred while calling o98.showString.
: org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist:
如果其中一个文件不存在。
如何绕过未找到的文件而只读取找到的文件?
解决方案
要知道文件是否存在(并在我的情况下将其删除),我执行以下操作:
import org.apache.hadoop.fs.{FileSystem, Path}
val fs = FileSystem.get(spark.sparkContext.hadoopConfiguration)
if (fs.exists(new Path(fullPath))) {
println("Output directory already exists. Deleting it...")
fs.delete(new Path(fullPath), true)
}
推荐阅读
- python - 为什么我不能跳出我的循环?(Python)
- ionic-framework - Ionic 3:忽略给定 div 内的“后退”滑动
- ios - Chat TableView Cell:一个 UIView,其大小应取决于较大的包含标签
- javascript - Chrome 性能监视器中每种颜色的含义是什么?
- docker - docker-compose 容器上的卷为空或有奇怪的内容
- db2 - Db2 zos 更新表中的值集
- c# - C# 正则表达式将捕获多组字符之间的选择
- machine-learning - WEKA 更改预测中的小数位数
- laravel - 按相关表结果的计数对数组进行排序
- java - 如何将 vaadin 8 网格导出到 csv