java - Hadoop get relative path from absolute path and base path -
i want relative path absolute path, given absolute base path. there hadoop java api this?
for example, if absolute hdfs path abs_path = hdfs://name-node/level1/level2/level3 , absolute base path abs_base_path = hdfs://name-node/level1, extract relative path abs_path, rel_path = level2/level3. familiar using path constructor combine 2 paths.
for example, if have rel_path , abs_base_path, can use 1 of overloaded constructors in path class http://hadoop.apache.org/docs/current/api/org/apache/hadoop/fs/path build abs_path cannot find api reverse.
this done in fileoutputcommitter's source code. relevant function is
/** * find final name of given output file, given job output directory * , work directory. * @param joboutputdir job's output directory * @param taskoutput specific task output file * @param taskoutputpath job's work directory * @return final path specific output file * @throws ioexception */ private path getfinalpath(path joboutputdir, path taskoutput, path taskoutputpath) throws ioexception { uri taskoutputuri = taskoutput.touri(); uri relativepath = taskoutputpath.touri().relativize(taskoutputuri); if (taskoutputuri == relativepath) { throw new ioexception("can not relative path: base = " + taskoutputpath + " child = " + taskoutput); } if (relativepath.getpath().length() > 0) { return new path(joboutputdir, relativepath.getpath()); } else { return joboutputdir; } } the idea create uri base directory , create new path new, relativized uri.
hope helps.
Comments
Post a Comment