Construct the absolute path from the file location and the current directory. The current directory is either of the form {code}hdfs:// : / {code} in Hadoop MapReduce mode, or of the form {code}file:/// {code} in Hadoop local mode. @param location the location
(String location, Path curDir)
| 225 | * with the scheme of the file system |
| 226 | */ |
| 227 | public static String getAbsolutePath(String location, Path curDir) |
| 228 | throws FrontendException { |
| 229 | |
| 230 | if (location == null || curDir == null) { |
| 231 | throw new FrontendException( |
| 232 | "location: " + location + " curDir: " + curDir); |
| 233 | } |
| 234 | |
| 235 | URI fsUri = curDir.toUri(); |
| 236 | String fsScheme = fsUri.getScheme(); |
| 237 | if (fsScheme == null) { |
| 238 | throw new FrontendException("curDir: " + curDir); |
| 239 | } |
| 240 | |
| 241 | fsScheme = fsScheme.toLowerCase(); |
| 242 | String authority = fsUri.getAuthority(); |
| 243 | if(authority == null) { |
| 244 | authority = ""; |
| 245 | } |
| 246 | Path rootDir = new Path(fsScheme, authority, "/"); |
| 247 | |
| 248 | ArrayList<String> pathStrings = new ArrayList<String>(); |
| 249 | |
| 250 | String[] fnames = getPathStrings(location); |
| 251 | for (String fname: fnames) { |
| 252 | // remove leading/trailing whitespace(s) |
| 253 | fname = fname.trim(); |
| 254 | Path p = new Path(fname); |
| 255 | URI uri = p.toUri(); |
| 256 | // if the supplied location has a scheme (i.e. uri is absolute) or |
| 257 | // an absolute path, just use it. |
| 258 | if(! (uri.isAbsolute() || p.isAbsolute())) { |
| 259 | String scheme = uri.getScheme(); |
| 260 | if (scheme != null) { |
| 261 | scheme = scheme.toLowerCase(); |
| 262 | } |
| 263 | |
| 264 | if (scheme != null && !scheme.equals(fsScheme)) { |
| 265 | throw new FrontendException("Incompatible file URI scheme: " |
| 266 | + scheme + " : " + fsScheme); |
| 267 | } |
| 268 | String path = uri.getPath(); |
| 269 | |
| 270 | fname = (p.isAbsolute()) ? |
| 271 | new Path(rootDir, path).toString() : |
| 272 | new Path(curDir, path).toString(); |
| 273 | } |
| 274 | fname = fname.replaceFirst("^file:/([^/])", "file:///$1"); |
| 275 | // remove the trailing / |
| 276 | fname = fname.replaceFirst("/$", ""); |
| 277 | pathStrings.add(fname); |
| 278 | } |
| 279 | |
| 280 | return join(pathStrings, ","); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * This method will be called by Pig both in the front end and back end to |