difin commented on code in PR #5729: URL: https://github.com/apache/hive/pull/5729#discussion_r2029409919
########## common/src/java/org/apache/hive/common/IPStackUtils.java: ########## @@ -219,4 +219,94 @@ public static String transformToIPv6(String ipv4, int port) { return ipv4; } } + + /** + * Splits a given input string representing a Hostname or an IP address and port into an `HostPort` object. + * The input string must be in the format of IPv4/IPv6/[IPv6]/hostname:port. + * + * @param input The input string containing the Hostname/IP address and port, in the format + * "IPv4:port", "[IPv6]:port", "IPv6:port", or "hostname:port". + * @return A {@link HostPort} object containing the parsed IP address and port number. + * @throws IllegalArgumentException If the input format is invalid, if the host is null or empty, + * or if the port number is invalid. + */ + public static HostPort splitHostPort(String input) { + + String host; + int port; + + if (input == null || input.isEmpty()) { + throw new IllegalArgumentException("Input string is null or empty"); + } + + // Check if the input contains a colon, which separates the host and port + int colonIndex = input.lastIndexOf(':'); + if (colonIndex == -1) { + throw new IllegalArgumentException("Input does not contain a port."); + } + + // Extract the host and port parts + host = input.substring(0, colonIndex); + String portStr = input.substring(colonIndex + 1); + + // Check if the port is valid + if (!isValidPort(portStr)) { + throw new IllegalArgumentException("Port number out of range (1-65535)."); Review Comment: We have cases in Hive where we specify port 0, so I think we shouldn't prevent it. In` MiniCluster.java#82-83` Was: ``` m_conf.set("dfs.datanode.address", "0.0.0.0:0"); m_conf.set("dfs.datanode.http.address", "0.0.0.0:0"); ``` I changed it as below in previous IPv6 related PR: ``` m_conf.set("dfs.datanode.address", IPStackUtils.concatWildcardAddressPort(0)); m_conf.set("dfs.datanode.http.address", IPStackUtils.concatWildcardAddressPort(0)); ``` Besides that: _Port 0 is not used for communication. It is typically used when a program wants the operating system to automatically assign a free, dynamic port._ I'll fix the error message to "Port number out of range (0-65535)". Good catch. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org