public static JdbcConnectionParams extractURLComponents(String uri, Properties info)
      throws JdbcUriParseException {
    JdbcConnectionParams connParams = new JdbcConnectionParams();
    if (!uri.startsWith(URL_PREFIX)) {
      throw new JdbcUriParseException("Bad URL format: Missing prefix " + URL_PREFIX);
    }

    // For URLs with no other configuration
    // Don't parse them, but set embedded mode as true
    if (uri.equalsIgnoreCase(URL_PREFIX)) {
      connParams.setEmbeddedMode(true);
      return connParams;
    }

    // The JDBC URI now supports specifying multiple host:port if dynamic service discovery is
    // configured on HiveServer2 (like: host1:port1,host2:port2,host3:port3)
    // We'll extract the authorities (host:port combo) from the URI, extract session vars, hive
    // confs & hive vars by parsing it as a Java URI.
    String authorityFromClientJdbcURL = getAuthorityFromJdbcURL(uri);
    if ((authorityFromClientJdbcURL == null) || (authorityFromClientJdbcURL.isEmpty())) {
      // Given uri of the form:
      // jdbc:hive2:///dbName;sess_var_list?hive_conf_list#hive_var_list
      connParams.setEmbeddedMode(true);
    } else {
      connParams.setSuppliedURLAuthority(authorityFromClientJdbcURL);
      uri = uri.replace(authorityFromClientJdbcURL, dummyAuthorityString);
    }

    // Now parse the connection uri with dummy authority
    URI jdbcURI = URI.create(uri.substring(URI_JDBC_PREFIX.length()));

    // key=value pattern
    Pattern pattern = Pattern.compile("([^;]*)=([^;]*)[;]?");

    // dbname and session settings
    String sessVars = jdbcURI.getPath();
    if ((sessVars != null) && !sessVars.isEmpty()) {
      String dbName = "";
      // removing leading '/' returned by getPath()
      sessVars = sessVars.substring(1);
      if (!sessVars.contains(";")) {
        // only dbname is provided
        dbName = sessVars;
      } else {
        // we have dbname followed by session parameters
        dbName = sessVars.substring(0, sessVars.indexOf(';'));
        sessVars = sessVars.substring(sessVars.indexOf(';') + 1);
        if (sessVars != null) {
          Matcher sessMatcher = pattern.matcher(sessVars);
          while (sessMatcher.find()) {
            if (connParams.getSessionVars().put(sessMatcher.group(1),
                sessMatcher.group(2)) != null) {
              throw new JdbcUriParseException(
                  "Bad URL format: Multiple values for property " + sessMatcher.group(1));
            }
          }
        }
      }
      if (!dbName.isEmpty()) {
        connParams.setDbName(dbName);
      }
    }

    Pattern fullPasswordPattern = Pattern.compile("(?i)(?<=;|^)password=([^;]+)");
    Matcher fullPwdMatcher = fullPasswordPattern.matcher(uri);
    if (fullPwdMatcher.find()) {
        String fullPassword = fullPwdMatcher.group(1);
        connParams.getSessionVars().put(JdbcConnectionParams.AUTH_PASSWD, fullPassword);
    }

    // parse hive conf settings
    String confStr = jdbcURI.getQuery();
    if (confStr != null) {
      Matcher confMatcher = pattern.matcher(confStr);
      while (confMatcher.find()) {
        connParams.getHiveConfs().put(confMatcher.group(1), confMatcher.group(2));
      }
    }

    // parse hive var settings
    String varStr = jdbcURI.getFragment();
    if (varStr != null) {
      Matcher varMatcher = pattern.matcher(varStr);
      while (varMatcher.find()) {
        connParams.getHiveVars().put(varMatcher.group(1), varMatcher.group(2));
      }
    }

    // Apply configs supplied in the JDBC connection properties object
    for (Map.Entry<Object, Object> kv : info.entrySet()) {
      if ((kv.getKey() instanceof String)) {
        String key = (String) kv.getKey();
        if (key.startsWith(JdbcConnectionParams.HIVE_VAR_PREFIX)) {
          connParams.getHiveVars().put(key.substring(JdbcConnectionParams.HIVE_VAR_PREFIX.length()),
              info.getProperty(key));
        } else if (key.startsWith(JdbcConnectionParams.HIVE_CONF_PREFIX)) {
          connParams.getHiveConfs().put(
              key.substring(JdbcConnectionParams.HIVE_CONF_PREFIX.length()), info.getProperty(key));
        }
      }
    }

    // Extract user/password from JDBC connection properties if its not supplied
    // in the connection URL
    if (!connParams.getSessionVars().containsKey(JdbcConnectionParams.AUTH_USER)) {
      if (info.containsKey(JdbcConnectionParams.AUTH_USER)) {
        connParams.getSessionVars().put(JdbcConnectionParams.AUTH_USER,
            info.getProperty(JdbcConnectionParams.AUTH_USER));
      }
      if (info.containsKey(JdbcConnectionParams.AUTH_PASSWD)) {
        connParams.getSessionVars().put(JdbcConnectionParams.AUTH_PASSWD,
            info.getProperty(JdbcConnectionParams.AUTH_PASSWD));
      }
    }

    if (!connParams.getSessionVars().containsKey(JdbcConnectionParams.AUTH_PASSWD)) {
      if (info.containsKey(JdbcConnectionParams.AUTH_USER)) {
        connParams.getSessionVars().put(JdbcConnectionParams.AUTH_USER,
                info.getProperty(JdbcConnectionParams.AUTH_USER));
      }
      if (info.containsKey(JdbcConnectionParams.AUTH_PASSWD)) {
        connParams.getSessionVars().put(JdbcConnectionParams.AUTH_PASSWD,
                info.getProperty(JdbcConnectionParams.AUTH_PASSWD));
      }
    }

    if (info.containsKey(JdbcConnectionParams.AUTH_TYPE)) {
      connParams.getSessionVars().put(JdbcConnectionParams.AUTH_TYPE,
          info.getProperty(JdbcConnectionParams.AUTH_TYPE));
    }
    // Extract host, port
    if (connParams.isEmbeddedMode()) {
      // In case of embedded mode we were supplied with an empty authority.
      // So we never substituted the authority with a dummy one.
      connParams.setHost(jdbcURI.getHost());
      connParams.setPort(jdbcURI.getPort());
    } else {
      String authorityStr = connParams.getSuppliedURLAuthority();
      // If we're using ZooKeeper, the final host, port will be read from ZooKeeper
      // (in a different method call). Therefore, we put back the original authority string
      // (which basically is the ZooKeeper ensemble) back in the uri
      if (ZooKeeperHiveClientHelper.isZkDynamicDiscoveryMode(connParams.getSessionVars())) {
        uri = uri.replace(dummyAuthorityString, authorityStr);
        // Set ZooKeeper ensemble in connParams for later use
        connParams.setZooKeeperEnsemble(authorityStr);
        ZooKeeperHiveClientHelper.setZkSSLParams(connParams);
      } else {
        URI jdbcBaseURI = URI.create(URI_HIVE_PREFIX + "//" + authorityStr);
        // Check to prevent unintentional use of embedded mode. A missing "/"
        // to separate the 'path' portion of URI can result in this.
        // The missing "/" common typo while using secure mode, eg of such url -
        // jdbc:hive2://localhost:10000;principal=hive/HiveServer2Host@YOUR-REALM.COM
        if (jdbcBaseURI.getAuthority() != null) {
          String host = jdbcBaseURI.getHost();
          int port = jdbcBaseURI.getPort();
          if (host == null) {
            throw new JdbcUriParseException(
                "Bad URL format. Hostname not found " + " in authority part of the url: "
                    + jdbcBaseURI.getAuthority() + ". Are you missing a '/' after the hostname ?");
          }
          // Set the port to default value; we do support jdbc url like:
          // jdbc:hive2://localhost/db
          if (port <= 0) {
            port = Integer.parseInt(Utils.DEFAULT_PORT);
          }
          connParams.setHost(host);
          connParams.setPort(port);
        }
        // We check for invalid host, port while configuring connParams with configureConnParams()
        authorityStr = IPStackUtils.concatHostPort(connParams.getHost(), connParams.getPort());
        LOG.debug("Resolved authority: " + authorityStr);
        uri = uri.replace(dummyAuthorityString, authorityStr);
      }
    }
    connParams.setJdbcUriString(uri);
    return connParams;
  }
This method handles the base parsing of the given jdbc uri. Some of JdbcConnectionParams
returned from this method are updated if ZooKeeper is used for service discovery

@param uri
@param info
@return
@throws JdbcUriParseException
jdbc/src/java/org/apache/hive/jdbc/Utils.java