kettle将postgresql数据导入cassandra提示InvalidQueryException: UUID should be 16 or 0 bytes (36)

在使用Kettle 9.1版本从postgresql-12迁移数据到cassandra3.x时,遇到uuid字段类型不匹配的问题。由于Kettle将postgresql的uuid字段解析为字符串,导致导入cassandra时抛出InvalidQueryException。解决方法是在流程中添加Java代码节点,通过Java代码将字符串转换为UUID类型,从而成功进行数据传输。
摘要由CSDN通过智能技术生成

本文使用的postgresql-12,cassandra 3.x,pentaho kettle为9.1版本,转换图如下图所示:

最初的转换只有pg的表输入节点以及Cassandra output输出节点组成,但是postgresql表中的uuid字段到了kettle时却成了字符串类型,导致

kettle将postgresql数据导入cassandra提示错误: 字段 "id" 的类型为 uuid, 但表达式的类型为 character varying,com.datastax.driver.core.exceptions.InvalidQueryException: UUID should be 16 or 0 bytes (36)的异常而导致数据传输失败,解决这个问题加入一个“JavaDaima“节点即可,具体转换如下所示:

其中“Java代码”节点脚本内容如下所示:

代码为:

import java.util.*;
 
private String str1;
 
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException 
{
        Object[] r = getRow();
    	// If the row object is null, we are done processing.
		if (r == null) {
			setOutputDone();
			return false;
		}
 
		//获取id列
		str1 = get(Fields.In, "id").getString(r);
 
		// 创建输出行,
		Object[] outputRow = createOutputRow(r, data.outputRowMeta.size());
        //将字符串转换为uuid
        UUID one = UUID.fromString(str1);
        //更新id列为uuid类型
		get(Fields.Out, "id").setValue(outputRow, one);
 
		putRow(data.outputRowMeta, outputRow); // 输出行
		
		return true;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值