我试图从hdfs读取一个文件,但是我在这里遇到了一个问题。文件无法存在,因此我必须检查是否存在。如果文件存在,我读取该文件,否则我读取一个空的df。
所以我要尝试的是:
val fs: FilySystem = FileSystem.get(new URI(path), new Configuration())
if (fs.exists(new org.apache.hadoop.fs.Path(s"$Path"))) {
val df6 = spark.read.parquet(path)
} else {
val df6 = df1.limit(0)
}
val df6.show()
但是我在jupyter上发现了以下错误:
Message: <console>:28: error: not found: type FileSystem
我做错了什么?
1条答案
按热度按时间roejwanj1#
试试这样的方法(调整一下)-