• 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})
    
    • 1
    • 2
    • 3

    分析一下:

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

     <fb303.version>0.9.2fb303.version>
     <thrift.version>0.9.2thrift.version>
    
    • 1
    • 2

    继续分析

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

    查看TOpenSessionReq源码

      public TOpenSessionReq() {
        this.client_protocol = org.apache.hive.service.rpc.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10;
    
      }
    
      public TOpenSessionReq(
        TProtocolVersion client_protocol)
      {
        this();
        this.client_protocol = client_protocol;
      }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    发现他的构造方法中有这两个,第一个默认指定client_protocol 协议版本为V10, 第二个构造方法就可以自定义协议版本。
    于是我查看了一下hive 服务端的源码,发现协议版本是TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V7 也就是客户端的版本协议默认为V10 但是hive-1.1.0服务端的仅仅可以支持到V7,那么降低协议版本就可以了。

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

    TOpenSessionReq openReq = new TOpenSessionReq(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V7);
    
    • 1

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

  • 相关阅读:
    Wampserver64
    一场深刻的开源聚会:KCC@北京 9.2 活动回顾
    PXE高效批量网络装机
    android桌面插件每秒刷新
    eyb:Redis学习(4)
    【云原生】-MySQL压测神器HammerDB的部署及使用
    uniapp 底部导航 点击刷新当前页
    现代 CSS 解决方案:Modern CSS Reset
    沃创云|让客户更精准的AI外呼客户初筛系统
    【Transformer从零开始代码实现】(一)输入部件:embedding+positionalEncoding
  • 原文地址:https://blog.csdn.net/sinat_35045195/article/details/126300302