报错 Bad URL format. Hostname not found in authority part of the url “xxxxx” . Are you missing a '/' after the hostname ?
背景:用dbeaver连接kerberos认证的hive,之前都是好好的,今天手贱点了下重置结果按照以前的死活连不上报上面的错误,其实这个错以前也遇到过忘了怎么解决的。今天有时间就研究下。
首先我们找到源码。怎么找源码?这个是连接hive报错的 大概率就是hiveConnection 和hiveDriver里解析hive url 和hive -d xxx=xxx这种时候出错了。详细过程不叙述了
org.apache.hive.jdbc.Utils类 526行左右
这里显示是host为null。 我这里贴出之前的hive 模板url
jdbc:hive2://{host}[:{port}][/{database}]/;AuthMech=1;KrbRealm=CDH.COM;KrbHostFQDN={host};KrbServiceName=hive;KrbAuthType=2
解析后的就是如下
jdbc:hive2://cdp-node05.data.com:10000;AuthMech=1;KrbRealm=CDH.COM;KrbHostFQDN=cdp-node05.data.com;KrbServiceName=hive;KrbAuthType=2
明明显示了host为啥是null。 说实话吧这个源码有点难搞,最近刚好我还在学习如何debug hive源码,还没学会咋办????
注意上面的截图。
URI jdbcURI = URI.create(URI_HIVE_PREFIX + "//" + authority);
String host = jdbcURI.getHost();
其实也很简单我自己new一个uri然后gethost不就好了?
public class HiveUrlTest {
public static void main(String[] args) {
String auth="cdp-node05.data.com:10000;KrbHostFQDN=cdp-node05.data.com;KrbServiceName=hive;KrbAuthType=2"
URI jdbcURI = URI.create("hive2:" + "//" +auth);
System.out.println(jdbcURI.getHost());
}
}
看了下uri的源码,说实话吧也能看,但很烦,不想看。
试了其他数据库的url,发现原因是少加了一个 /....
jdbc:hive2://{host}[:{port}][/{database}]/;principal=hive/{host}@CDP.COM;AuthMech=1;KrbRealm=CDH.COM;KrbHostFQDN={host};KrbServiceName=hive;KrbAuthType=2