Kyuubi客户端使用 Java SDK 接口 可以使用kyuubi 的 jdbc 进行开发,也可以使用 hive 的 jdbc 进行开发。 使用kyuubi 的 jdbc 进行开发,pom 里需要加入如下依赖: plaintext org.apache.kyuubi kyuubihivejdbcshaded 1.8.2 说明 这个版本号根据自己集群的具体kyuubi 版本选择。 连接代码示例如下(url 中的 zkhostname、EXAMPLE.COM 等请替换为实际集群信息): plaintext package cn.com.chinatelecom; import java.security.PrivilegedAction; import java.security.PrivilegedExceptionAction; import java.sql.; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.UserGroupInformation; public class TestKyuubi { //kyuubi驱动 private static String driverName "org.apache.kyuubi.jdbc.KyuubiHiveDriver"; //kyuubi连接串 private static String url "jdbc:hive2://zkhostname1:2181,zkhostname2:2181,zkhostname3:2181/;principalhive/HOST@EXAMPLE.COM;serviceDiscoveryModezooKeeper;zooKeeperNamespacekyuubi"; private static Connection conn null; private static Statement state null; private static ResultSet rs null; private static String principal null;//执行这个jdbc的使用的keytab的principal private static String keytab null;//执行这个jdbc的keytab文件路径 private static String user null; private static String useType null;//使用类型,包括ldap和kerberos两种 private static String passwd null;//使用ldap时的密码 public static void getConnect() throws Exception { Configuration conf new Configuration(); //kyuubi只使用了Kerberos时走如下代码 if (useType.equalsIgnoreCase("kerberos")) { conf.set("hadoop.security.authentication","kerberos"); System.out.println("use: " + user + " url: " + url + "keytab:" + keytab + "principal: " + principal); UserGroupInformation.setConfiguration(conf); UserGroupInformation.loginUserFromKeytab(principal,keytab);//keytab内容 Class.forName(driverName); UserGroupInformation ugi UserGroupInformation.getLoginUser(); conn ugi.doAs(new PrivilegedExceptionAction () { @Override public Connection run() throws SQLException { return DriverManager.getConnection(url,user,""); } }); } else if (useType.equalsIgnoreCase("ldap")) {//kyuubi使用了Kerberos同时有集成了ldap就走如下代码 Class.forName(driverName); conn DriverManager.getConnection(url,user,passwd); } else { System.out.println("please input authentication type(kerberos or ldap)"); return; } state conn.createStatement(); } public static void showDatabases() throws SQLException { System.out.println("show databases "); rs state.executeQuery("show databases"); while (rs.next()) { System.out.println(rs.getString(1)); } } public static void close() throws SQLException { if (rs ! null) state.close(); if (state ! null) state.close(); if (conn !null) conn.close(); } public static void main(String args[]) throws Exception { if (args.length > 4) { if (args[0]!null && !args[0].isEmpty()) { url args [0]; } if (args[1]!null && !args[1].isEmpty()) { useType args [1]; } if (args[2]!null && !args[2].isEmpty()) { user args [2]; } if (useType.equalsIgnoreCase("ldap") && args[3]!null && !args[3].isEmpty()) { passwd args [3]; } else if (useType.equalsIgnoreCase("kerberos")) { if (args[3]!null && !args[3].isEmpty()) { keytab args [3]; } if (args[4]!null && !args[4].isEmpty()) { principal args [4]; } } } getConnect(); showDatabases(); close(); } } 使用hive 的 jdbc 进行开发,pom 里需要加入如下依赖: plaintext org.apache.hive hivejdbc 3.1.2 注意 这个hivejdbc 包必须使用翼MR提供的,不能使用社区的(由于集群集成了 ranger,会在 ZK 上增加 ranger 的 znode 节点,导致出现连接失败的情况,自研版本解决了这个问题)。