【发布时间】:2017-06-08 21:18:47
【问题描述】:
我正在尝试使用以下代码从 spark 中删除 hive 阶段文件。此代码可以删除目录中的文件,但我想删除所有以 '.hive-staging_hive' 开头的文件。
我能知道删除以某些文本开头的目录的方法吗?
Configuration conf = new Configuration();
System.out.println("560");
Path output = new Path("hdfs://abcd/apps/hive/warehouse/mytest.db/cdri/.hive-staging_hive_2017-06-08_20-45-20_776_7391890064363958834-1/");
FileSystem hdfs = FileSystem.get(conf);
System.out.println("564");
// delete existing directory
if (hdfs.exists(output)) {
System.out.println("568");
hdfs.delete(output, true);
System.out.println("570");
}
【问题讨论】:
-
我认为您可以使用 shell 脚本轻松完成此操作。你愿意接受 bash 解决方案吗?
标签: hadoop apache-spark hdfs