feat(hive): add Kerberos connection options

This commit is contained in:
t8y2 committed 2026-07-08 13:23:21 +08:00
1 parent 5b70626cf7
commit 2929b1c035
30 files changed
+639 -23

No files matched your search

@@ -169,8 +169,30 @@ public final class HiveAgent extends AbstractJdbcAgent {
return result;
}
private static String buildUrl(ConnectParams params) {
return "jdbc:hive2://" + params.getHost() + ":" + params.getPort() + "/" + params.getDatabase();
static String buildUrl(ConnectParams params) {
String connectionString = trimToEmpty(params.getConnection_string());
if (!connectionString.isEmpty()) {
return connectionString;
}
String url = "jdbc:hive2://" + params.getHost() + ":" + params.getPort() + "/" + params.getDatabase();
return appendHiveUrlParams(url, params.getUrl_params());
}
private static String appendHiveUrlParams(String url, String urlParams) {
String params = trimHiveUrlParams(urlParams);
if (params.isEmpty()) {
return url;
}
// Hive JDBC authentication options use semicolon-separated URL properties.
return url + (url.endsWith(";") ? "" : ";") + params;
}
private static String trimHiveUrlParams(String urlParams) {
String value = trimToEmpty(urlParams);
while (value.startsWith("?") || value.startsWith("&") || value.startsWith(";")) {
value = value.substring(1);
}
return value;
}
private static String trimToNull(String value) {
@@ -1,11 +1,42 @@
package com.dbx.agent.hive;
import com.dbx.agent.ConnectParams;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class HiveAgentTest {
@Test
void hiveJdbcStandaloneRuntimeClassesAreAvailable() throws ClassNotFoundException {
Class.forName("org.apache.hive.jdbc.HiveDriver");
Class.forName("org.apache.hive.org.apache.thrift.protocol.TProtocol");
}
@Test
void buildUrlAppendsKerberosUrlParams() {
ConnectParams params = new ConnectParams();
params.setHost("hive.example.com");
params.setPort(10000);
params.setDatabase("default");
params.setUrl_params(";principal=hive/hive.example.com@EXAMPLE.COM;auth=kerberos");
assertEquals(
"jdbc:hive2://hive.example.com:10000/default;principal=hive/hive.example.com@EXAMPLE.COM;auth=kerberos",
HiveAgent.buildUrl(params)
);
}
@Test
void buildUrlUsesCustomJdbcUrlAsIs() {
ConnectParams params = new ConnectParams();
params.setConnection_string(
"jdbc:hive2://zk1.example.com,zk2.example.com/default;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2;principal=hive/_HOST@EXAMPLE.COM"
);
params.setUrl_params("principal=hive/ignored@EXAMPLE.COM");
assertEquals(
"jdbc:hive2://zk1.example.com,zk2.example.com/default;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2;principal=hive/_HOST@EXAMPLE.COM",
HiveAgent.buildUrl(params)
);
}
}