【发布时间】:2015-04-04 11:57:48
【问题描述】:
我有一个简单的文件过滤器,它基本上从特定日期选择文件。
在 Hadoop 中,我将使用setInputPathFilter 将PathFilter 类设置为InputFormat 参数。如何在 Spark 中执行此操作?
public class FilesFilter extends Configured implements PathFilter {
@Override
public boolean accept(Path path) {
try {
if (fs.isDirectory(path))
return true;
} catch (IOException e1) {
e1.printStackTrace();
return false;
}
String file_date = "01.30.2015";
SimpleDateFormat sdf = new SimpleDateFormat("MM.dd.yyyy");
Date date = null;
try {
date = sdf.parse(file_date);
} catch (ParseException e1) {
e1.printStackTrace();
}
long dt = date.getTime()/(1000 * 3600 * 24);
try {
FileStatus file = fs.getFileStatus(path);
long time = file.getModificationTime() / (1000 * 3600 * 24);
return time == dt;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
}
【问题讨论】:
标签: java scala hadoop apache-spark