0


Required field ‘client_protocol‘ is unset 原因探究

Required field ‘client_protocol’ is unset! 原因探究

最新在做基于Thrift协议的hive客户端,但是遇到了

Required field 'client_protocol' is unset!

问题,具体一点的异常如下

org.apache.thrift.TApplicationException:Required field 'client_protocol' is unset!Struct:TOpenSessionReq(client_protocol:null, configuration:{set:hiveconf:hive.server2.thrift.resultset.default.fetch.size=1000, use:database=xxx})

分析一下:

client_protocol is unset! 说的是客户端协议未配置,起初的原因我以为是Thrift协议不兼容问题,于是查看hive-1.1.0 依赖,发现它使用的依赖thrift协议版本比较低,于是我将thrift协议版本降级.排除兼容性问题虽然最后发现不是这个问题导致的,但是类似问题很容易是依赖冲突导致

<fb303.version>0.9.2</fb303.version><thrift.version>0.9.2</thrift.version>

继续分析

降低thrift协议版本并没有修复bug,但是网上好多说是兼容性问题,也就是hive线上服务版本和本地JDBC客户端版本没有统一,但是我就是要自己做一个hive thrift客户端,根本没有引入依赖。那么具体的是什么版本呢。 然后通过报错异常发现 我的请求为

TOpenSessionReq

这个请求的client_protocol is unset! 那么事情就简单了。

查看

TOpenSessionReq

源码

publicTOpenSessionReq(){this.client_protocol =org.apache.hive.service.rpc.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10;}publicTOpenSessionReq(TProtocolVersion client_protocol){this();this.client_protocol = client_protocol;}

发现他的构造方法中有这两个,第一个默认指定client_protocol 协议版本为V10, 第二个构造方法就可以自定义协议版本。
于是我查看了一下hive 服务端的源码,发现协议版本是

TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V7

也就是客户端的版本协议默认为V10 但是hive-1.1.0服务端的仅仅可以支持到V7,那么降低协议版本就可以了。

因此在openSession的时候使用如下代码即可

TOpenSessionReq openReq =newTOpenSessionReq(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V7);

总结: 本质原因就是客户端使用的hive 协议版本和服务端的协议版本不统一, 客户端的协议版本必须不高于服务端,即使你是使用hive提供的jdbc也是一样,这时候你就要降低一下hive jdbc的版本


本文转载自: https://blog.csdn.net/sinat_35045195/article/details/126300302
版权归原作者 天心有情 所有, 如有侵权,请联系我们删除。

“Required field ‘client_protocol‘ is unset 原因探究”的评论:

还没有评论