【发布时间】:2020-06-02 02:06:20
【问题描述】:
在给定基本路径的情况下,如何检查文件是否存在。我正在为该方法提供一个文件列表,例如: file1.snappy, file2,snappy,...
我需要检查文件是否存在于任一给定路径中,例如:hdfs://a/b/c/source/file1.snappy 或文件是否存在于hdfs://a/b/c/target/file1.snappy。如何更新/修改以下方法以接受 /a/b/c/target/ 或 /a/b/c/source/ 作为基本路径并检查文件是否存在?如果它存在于源中,则添加到源列表中,如果它在目标中,则添加到目标列表中。
val fs = FileSystem.get(sprk.sparkContext.hadoopConfiguration)
def fileExists(fileList:Array[String]) : Boolean = {
var fileNotFound = 0
fileList.foreach{
file => {
if(!fs.exists(new Path(file))) fileNotFound+=1
print("fileList",file)
}
}
if(fileNotFound > 0) {
println(fileNotFound + ": number of files not found probably moved")
false
}
else
true
}
【问题讨论】:
-
你的预期输出是什么?
-
布尔值 true 或 false,取决于文件是否存在于源或目标中。我可以调用该方法两次,这不是问题。 @Srinivas
-
@coderWorld 根据我的经验,它完全符合您的 s3 要求。和测试用例