public void extractParametersWithURL()

in flink-vvp-connector-adbpg/src/main/java/org/apache/flink/connector/jdbc/table/sink/AdbpgOutputFormat.java [1153:1182]


    public void extractParametersWithURL(String jdbcUrl) {
        // check if jdbcUrl is empty
        if (jdbcUrl == null || jdbcUrl.isEmpty()) {
            throw new RuntimeException("Invalid jdbc url, can't extract hostname and port with empty url");
        }

        // extract database with the given url
        String[] parts = jdbcUrl.split("/");
        if (parts.length > 0) {                         // database name should be the last part
            String lastPart = parts[parts.length - 1];
            int paramsIndex = lastPart.indexOf('?');    // if there are parameters in url like '?', then these should be removed
            if (paramsIndex != -1) {
                database =  lastPart.substring(0, paramsIndex);
            } else {
                database = lastPart;
            }
        }

        // extract hostname and port with the given url
        parts = jdbcUrl.split("//");                // assume that URL follow a regular format:jdbc:database_type://hostname:port/database_name
        String hostAndPort = parts[1].split("/")[0];
        String[] hostPortParts = hostAndPort.split(":");
        // normally the length of hostPortParts should only be 2
        if (hostPortParts.length != 2) {
            throw new RuntimeException("Invalid jdbc url, can't extract hostname and port with url: " + jdbcUrl);
        }
        // extract hostname
        hostname = hostAndPort.split(":")[0];
        port = Integer.parseInt(hostAndPort.split(":")[1]);
    }