public static Path resolveSymlinks(Path path, Configuration conf) throws IOException {
    if (path == null) {
      throw new IllegalArgumentException("Cannot resolve symlink for a null Path");
    }

    URI uri = path.toUri();
    String scheme = uri.getScheme();

    /*
     * If you're about to extend this method to e.g. HDFS, simply remove this check.
     * There is a known exception reproduced by whroot_external1.q, which can be referred to,
     * which is because java.nio is not prepared by default for other schemes like "hdfs".
     */
    if (scheme != null && !"file".equalsIgnoreCase(scheme)) {
      LOG.debug("scheme '{}' is not supported for resolving symlinks", scheme);
      return path;
    }

    // we're expecting 'file' scheme, so if scheme == null, we need to add it to path before resolving,
    // otherwise Paths.get will fail with java.lang.IllegalArgumentException: Missing scheme
    if (scheme == null) {
      try {
        uri =  new URI("file", uri.getAuthority(), uri.toString(), null, null);
      } catch (URISyntaxException e) {
        // e.g. in case of relative URI, we cannot create a new URI
        LOG.debug("URISyntaxException while creating uri from path without scheme {}", path, e);
        return path;
      }
    }

    try {
      java.nio.file.Path srcPath = Paths.get(uri);
      URI targetUri = srcPath.toRealPath().toUri();
      // stick to the original scheme
      return new Path(scheme, targetUri.getAuthority(),
          Path.getPathWithoutSchemeAndAuthority(new Path(targetUri)).toString());
    } catch (Exception e) {
      LOG.debug("Exception while calling toRealPath of {}", path, e);
      return path;
    }
  }
Resolves a symlink on a local filesystem. In case of any exceptions or scheme other than "file"
it simply returns the original path. Refer to DEBUG level logs for further details.
@param path input path to be resolved
@param conf a Configuration instance to be used while e.g. resolving the FileSystem if necessary
@return the resolved target Path or the original if the input Path is not a symlink
@throws IOException
common/src/java/org/apache/hadoop/hive/common/FileUtils.java