diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java index eaf71cfa1bf..8d8922ee7ff 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java @@ -27,8 +27,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.security.*; @@ -835,11 +833,7 @@ private void openSession() throws SQLException { "set:hiveconf:hive.server2.thrift.resultset.default.fetch.size", Integer.toString(fetchSize)); } - try { - openConf.put("kyuubi.client.ipAddress", InetAddress.getLocalHost().getHostAddress()); - } catch (UnknownHostException e) { - LOG.debug("Error getting Kyuubi session local client ip address", e); - } + openConf.put("kyuubi.client.ipAddress", Utils.CLIENT_IP_ADDRESS); openConf.put(Utils.KYUUBI_CLIENT_VERSION_KEY, Utils.getVersion()); openReq.setConfiguration(openConf); diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java index b9f256f69bf..86b397437e0 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java @@ -68,6 +68,21 @@ public class Utils { public static final Pattern KYUUBI_OPERATION_HINT_PATTERN = Pattern.compile("^__kyuubi_operation_result_(.*)__=(.*)", Pattern.CASE_INSENSITIVE); + public static final String CLIENT_IP_ADDRESS; + + static { + String localIpAddress = null; + try { + localIpAddress = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + LOG.warn("Error getting Kyuubi local client IP address", e); + } + if (StringUtils.isBlank(localIpAddress)) { + localIpAddress = "unknown"; + } + CLIENT_IP_ADDRESS = localIpAddress; + } + static String getMatchedUrlPrefix(String uri) throws JdbcUriParseException { for (String urlPrefix : URL_PREFIX_LIST) { if (uri.startsWith(urlPrefix)) {