我有一个简单的 MR 作业,需要根据时间戳在 hdfs 中创建一个目录。我很难找到正确的 api(在 hadoop 2.0.3 中查找状态并在不存在时创建目录)。有人可以提出正确的做法吗?这是现有的代码:
FileSystem fileSystem = FileSystem.get(new Configuration());
Calendar c = Calendar.getInstance();
String basepath = "/dev/group/data/json/";
for ( Record record: records){
c.setTimeInMillis(record.timestamp );
Path path = new Path(basepath + c.get(Calendar.YEAR) + "/" + c.get(Calendar.MONTH));
// Check if the path is valid and create hdfs folder if not
FileStatus[] status = filesystem.???
context.write(key, new Text(mapper.writeValueAsString(record)));
}
谢谢