Home  >  Article  >  Database  >  Kettle连接Hive 中文乱码问题解决方案

Kettle连接Hive 中文乱码问题解决方案

WBOY
WBOYOriginal
2016-06-07 16:29:231883browse

刚开始接触Pentaho的 kettle desktop版本。我们这里主要应用其与hadoop及 hive 的关联进行数据处理。 kettle 的版本是4.4,使用的过程还是挺顺利的,顺利的建立好了一个转换任务,将 hive 中的数据提取到了本地文件。但是打开一看,所以 utf8 的 中文 全都是

刚开始接触Pentaho的kettle desktop版本。我们这里主要应用其与hadoop及hive的关联进行数据处理。kettle的版本是4.4,使用的过程还是挺顺利的,顺利的建立好了一个转换任务,将hive中的数据提取到了本地文件。但是打开一看,所以utf8中文全都是乱码。而且kettle现在只支持到了hive0.7版本,还没支持到0.8,所以无法正确提取hive的meta信息,但是不影响HQL的正常运行。

只能先看看kettle是如何使用hive的jdbc连接的。我先将hive-jdbc.0.8.1.ar拷贝到{kettlehome}/libext/JDBC下,直接造成无法正常连接hive。

在该目录下存在jar文件hive-jdbc-0.7.0-pentaho-1.0.2.jar,这个类是一个适配类,不真正实现hive的jdbc连接。

而是通过反射的方式,找到classpath下的hivejdbc类,即存在于{kettlehome}\plugins\pentaho-big-data-plugin\hadoop-configurations\hadoop-20\lib\hive-jdbc-0.7.0-pentaho-1.0.2.jar这个jar文件,该文件用于真实的调用hive。

我们就来看一下这个jar中的实现。可以先从以下url中获取source文件。http://repo.pentaho.org/artifactory/repo/org/apache/hive/hive-jdbc/0.7.0-pentaho-1.0.2/hive-jdbc-0.7.0-pentaho-1.0.2-sources.jar 下载解压后,倒入到你自己的一个新建java工程中,并引入相关的类库,可以使之正常编译。

StructObjectInspector soi = (StructObjectInspector) serde.getObjectInspector();List fieldRefs = soi.getAllStructFieldRefs();//Object data = serde.deserialize(new BytesWritable(rowStr.getBytes()));//我们将该行屏蔽Object data = serde.deserialize(new BytesWritable(rowStr.getBytes("UTF-8")));//使用本行

然后将编译后的class文件加入到hive-jdbc-0.7.0-pentaho-1.0.2.jar
重新启动kettle。
然后再跑一下流程,正常了。当然,如果你的系统环境本身编码就是utf8的,应该不会出现这样的问题。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:MongoDB Tip: Create Short Field NamesNext article:SQL on HBase