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选择相应的版本)

 

image.png

3. 下载对应的hive jar包

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

 

image.png

4.kettle里创建数据库连接

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

 

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
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值