1
我有一個簡單的MR作業,需要根據時間戳在hdfs中創建一個目錄。我很難找到正確的api(在hadoop 2.0.3中查找狀態並創建一個不存在的目錄)。有人可以提出正確的做法嗎?這裏是現有代碼:hadoop檢查路徑是否有效,如果不是,則創建
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)));
}
THX
太棒了,我正在嘗試它。謝謝 – Kiran