【pentaho】kettle读取Hive表不支持bigint和timstamp类型解决。

一、bigint类型

报错:

Unable to get value 'BigNumber(16)' from database resultset

显示kettle认为此应该是decimal类型(kettle中是TYPE_BIGNUMBER或称BigNumber),但实际hive数据库中是big类型。
修改kettle源码解决:

kettle中java.sql.Types到kettle类型转换的方法是org.pentaho.di.core.row.value.ValueMetaBase#getValueFromSQLType
类在data-integration中的data-integration-9.2.0.4-R\lib\kettle-core-***.jar包中。

        case java.sql.Types.BIGINT:
          // verify Unsigned BIGINT overflow!
          // TODO:fix kettle read hudi bigint: Unable to get value 'BigNumber(16)' from database resultset
          // force to be unsigned bigint type!!!
/*          if ( signed ) {
            valtype = ValueMetaInterface.TYPE_INTEGER;
            precision = 0; // Max 9.223.372.036.854.775.807
            length = 15;
          } else {
            valtype = ValueMetaInterface.TYPE_BIGNUMBER;
            precision = 0; // Max 18.446.744.073.709.551.615
            length = 16;
          }*/

          // add code
          valtype = ValueMetaInterface.TYPE_INTEGER;
          precision = 0; // Max 9.223.372.036.854.775.807
          length = 15;
          break;

本质就是kettle认为bigint分两种 signedunsigned 的 就是 有正负的和 仅正的。
当是unsigned时候kettle任务jdbc应提供为decimal类型(java 中是bigdecimal类型)的数据。这种仅仅是很难遇到的临界状态场景,其实可以忽略,所以把此判断去除直接让hive的bigint 都转为kettle的TYPE_INTEGER 就可以。

方法一:直接编译:

# 将kettle-core安装本地到mvn仓库中
mvn install:install-file -DgroupId=pentaho-kettle -DartifactId=kettle-core -Dversion=8.2.0.0-342 -Dpackaging=jar -Dfile=kettle-home\lib\kettle-core-*.jar

新建maven项目:

引入依赖,就这一个依赖就够用了:

    <dependency>
      <groupId>pentaho-kettle</groupId>
      <artifactId>kettle-core</artifactId>
      <version>8.2.0.0-342</version>
      <scope>provided</scope>
    </dependency>

新建 路径:org.pentaho.di.core.row.value 并将 kettle-core-*.jar 包中的 ValueMetaBase 反编译源码粘贴到此路径下。
修改case -5: 把 if 啥的删掉替换成如下内容即可。


// java.sql.Types.BIGINT --> -5, 编译的时候java直接用字面值替换了变量了。
        case -5:
          valtype = 5;
          precision = 0;
          length = 15;
          break;

然后直接mvn package。从编译好的包中再取到ValueMetaBase 替换kettle-core-*.jar 包中的类,最后把此包替换会kettle-home/lib包即可。

方法二:编译kettle源码(作废):
2024年1月3日日立的maven仓库已经连不上了,有授权!!
仅处理bigint问题不需要pentaho-hadoop-shims项目的编译!!!这里仅作pentaho-hadoop-shims的记录而已。

# kettle
git clone -b 9.2.0.0-R git@github.com:pentaho/pentaho-kettle.git
# hadoop-plugin
git clone -b 9.2.0.0-R git@github.com:pentaho/pentaho-hadoop-shims.git

登录github直接在pentaho-kettlepentaho-hadoop-shims搜索选择,自己已经在用的版本或者-R release版本即可。

在这里插入图片描述
根据自己的kettle主版本选择hadoop-plugin版本。
在这里插入图片描述

项目根目录的pom.xml需要配置仓库地址:

    <repositories>
    <repository>
      <id>pentaho</id>
      <name>pentaho</name>
      <url>https://repo.orl.eng.hitachivantara.com/artifactory/pnt-mvn/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
    <repository>
      <id>cloudera</id>
      <name>cloudera</name>
      <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>pentaho-plugin</id>
      <name>pentaho-plugin</name>
      <url>https://repo.orl.eng.hitachivantara.com/artifactory/pnt-mvn/</url>
    </pluginRepository>
  </pluginRepositories>

如果依赖都能下载到,那么直接mvn clean install "-DskipTests"即可。我编译比较顺利没什么坑。

二、timestamp类型

修改数据库连接的高级配置即可。
在这里插入图片描述

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值