背景
用jdbc连接hiveserver2报错,主要内容如下:
Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{set:hiveconf:hive.server2.thrift.resultset.default.fetch.size=1000, use:database=default})
解决方法
不要直接依赖本地hive里的lib文件夹,在客户端编写pom.xml文件,填写如下内容:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.szc</groupId>
<artifactId>java-hive</artifactId>
<version>1.0.0</version>
<name>java-hive</name>
<dependencies>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.1.0</version>
<classifier>standalone</classifier>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-service-rpc</artifactId>
<version>2.3.5</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-service</artifactId>
<version>2.3.5</version>
</dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.9.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6.0</version>
<systemPath>D:/ProgramCoding/apache-hive-2.3.5-bin/lib/commons-lang-2.6.jar</systemPath>
</dependency>
</dependencies>
<repositories>
<repository>
<id>cloudera</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>-->
</repository>
</repositories>
</project>
<project>标签下的<groupId><artifactId><name><version>自己随便写,别的直接复制
然后运行客户端就可以连上hiveserver2了
结语
这个client_protocol真是巨坑,本来我客户端直接依赖hiveHome\lib文件夹,hive-jdbc的版本不可能和服务端不一致,而且换成pom后,把hive-jdbc版本写成服务端的2.3.5、写成1.1.2、0.1.1都报错,真他娘的新鲜,最后搜了一文章,说改成1.1.0+standalone就可以,一试,还真灵,特记录下来。