San*_*aka 1 hadoop scala hdfs apache-spark spark-streaming
我使用dstream.saveAsObjectFiles("/temObj")它在 hdfs 中显示多个文件的方法在火花流中保留了对象文件。
temObj-1506338844000
temObj-1506338848000
temObj-1506338852000
temObj-1506338856000
temObj-1506338860000
Run Code Online (Sandbox Code Playgroud)
阅读完所有文件后,我想删除所有 temObj 文件。在火花中做到这一点的最佳方式是什么?我试过
val hdfs = org.apache.hadoop.fs.FileSystem.get(new java.net.URI("hdfs://localhost:9000"), hadoopConf)
hdfs.delete(new org.apache.hadoop.fs.Path(Path), true)
Run Code Online (Sandbox Code Playgroud)
但它一次只能删除一个文件夹
不幸的是,delete 不支持 globs。
您可以globStatus一一使用和迭代文件/目录并删除它们。
val hdfs = FileSystem.get(sc.hadoopConfiguration)
val deletePaths = hdfs.globStatus(new Path("/tempObj-*") ).map(_.getPath)
deletePaths.foreach{ path => hdfs.delete(path, true) }
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用sys.process来执行 shell 命令
import scala.sys.process._
"hdfs dfs -rm -r /tempObj*" !
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4157 次 |
| 最近记录: |