Data Integration (kettle) 7.0 连接Hive

背景

最近需要将mysql的数据库的数据导入到hive里,期间遇到了很多坑,这次来总结一下。

步骤

1.启动hiveServer2

kettle 是通过jdbc 来连接hive的,而jdbc 方式连接hive需要启动hiveServer2(thrift接口程序),执行如下命令来启动hiveServer2
./hive --service hiveserver2 --hiveconf hive.server2.thrift.port=10001 --hiveconf hive.server2.thrift.bind.host=[SERVER_IP]

2. 修改plugin.properties 文件

文件位置:KETTLE_HOME/plugins/pentaho-big-data-plugin/plugin.properties
修改active.hadoop.configuration=hdp25(我使用的是apache hadoop,其他版本的hadoop选择相应的版本)

《Data Integration (kettle) 7.0 连接Hive》 image.png

3. 下载对应的hive jar包

从服务器下载hive jar文件到之前的hdp25/lib文件夹下,主要注意hive-开头的:

《Data Integration (kettle) 7.0 连接Hive》 image.png

4.kettle里创建数据库连接

选择连接类型为hadoop hive2,填写好主机名称、数据库名称,以及之前hiveServer2的端口号,以及用户名和密码,如下:

《Data Integration (kettle) 7.0 连接Hive》 image.png

问题汇总

1. no suitable driver exception

    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at org.pentaho.di.core.database.Database.connectUsingClass(Database.java:567)
    ... 48 more```
如果出现上面的错误一般是步骤2中配置不正确,这个问题我纠结了好久,可能因为KETTLE_HOME/lib目录下添加了一些jar包,导致后来不管怎么修改都不生效,期间还重新解压了kettle。
#### 2.Required field 'client_protocol' is unset! 
```org.pentaho.di.core.exception.KettleDatabaseException: 
Error occurred while trying to connect to the database

Error connecting to database: (using class org.apache.hive.jdbc.HiveDriver)
Could not establish connection to jdbc:hive2://xxx.xxx.xx.xx:10001/testing: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=testing})```
如果是出现上面的错,一般是kettle 的hive jar包和服务器的hive的jar包版本不匹配,解决的办法就是步骤3,从服务器下载相应的hive jar文件,确保两端版本一致。
#### 3.Connection refused: connect
``` org.pentaho.di.core.exception.KettleDatabaseException: 
Error occurred while trying to connect to the database

Error connecting to database: (using class org.apache.hive.jdbc.HiveDriver)
Could not open client transport with JDBC Uri: jdbc:hive2:///xxx.xxx.xx.xx:10001/testing: java.net.ConnectException: Connection refused: connect

出现上面的错,一般是两端连接出错,确保hiveServer2已启动,以及用户名和密码正确。

4. hive 的insert into values 1.4版本以下不支持

在使用hive做表输出,插入到hive数据库的时候,insert into 会有问题

2017/06/26 15:00:51 - 表输出.0 -   at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:121)
2017/06/26 15:00:51 - 表输出.0 -   at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:109)
2017/06/26 15:00:51 - 表输出.0 -   at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:231)
2017/06/26 15:00:51 - 表输出.0 -   at org.apache.hive.jdbc.HiveStatement.executeUpdate(HiveStatement.java:369)
2017/06/26 15:00:51 - 表输出.0 -   at org.apache.hive.jdbc.HivePreparedStatement.executeUpdate(HivePreparedStatement.java:117)
2017/06/26 15:00:51 - 表输出.0 -   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2017/06/26 15:00:51 - 表输出.0 -   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ...

那么,1.4版本以下如何导入数据到hive呢,请参考我的另外一篇文章kettle 将mysql 导入到hive(借助Hadoop File Output组件)。主要思想是将数据文件导入到hdfs,然后再通过lhive 的load 语法来将hdfs的数据文件导入的hive。

欢迎大家赞赏、转载、点赞、评论。

    原文作者:data_haozi
    原文地址: https://www.jianshu.com/p/ec45c21a977f
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞