Kettle7中使用Java脚本进行数据清洗

1.首先,Kettle7.1下载li链接:https://sourceforge.net/projects/pentaho/files/Data%20Integration/7.1/pdi-ce-7.1.0.0-12.zip/download

2.打开这个文件:Spoon.bat

3.假设就这三个步骤:

4.其中组件“Java代码”的内容如下:


import java.text.SimpleDateFormat;
public boolean processRow(StepMetaInterface smi,StepDataInterface sdi) throws Exception{
	   Object[] r=getRow();
 
  	   if(r==null)
       {
            setOutputDone();
            return false;
       }
       r=createOutputRow(r,data.outputRowMeta.size());
	   String HANDSET_NUM_ = get(Fields.In, "HANDSET_NUM_").getString(r);
		String TO_ACCOUNT_ = get(Fields.In, "TO_ACCOUNT_").getString(r);
		String FROM_ACCOUNT_ = get(Fields.In, "FROM_ACCOUNT_").getString(r);
      
	   logBasic("---> HANDSET_NUM_: "+HANDSET_NUM_);
		logBasic("TO_ACCOUNT_: "+TO_ACCOUNT_);
		logBasic("FROM_ACCOUNT_: "+FROM_ACCOUNT_);

	   if(HANDSET_NUM_!=null)
       {
            String format = HANDSET_NUM_.replace("+86", "").replace("+85", "").replaceAll("-", "").replaceAll("\\+", "");
			get(Fields.In, "HANDSET_NUM_").setValue(r, format.trim());
            logBasic("format1: "+format);
            //putRow(data.outputRowMeta,r);
       }
       if(TO_ACCOUNT_!=null)
       {
            String format = TO_ACCOUNT_.replace("+86", "").replace("+85", "").replaceAll("-", "").replaceAll("\\+", "");
		
       	    get(Fields.In, "TO_ACCOUNT_").setValue(r, format.trim());
            logBasic("format2: "+format);
            //putRow(data.outputRowMeta,r);
       }
       
		if(FROM_ACCOUNT_!=null)
       {
            String format = FROM_ACCOUNT_.replace("+86", "").replace("+85", "").replaceAll("-", "").replaceAll("\\+", "");
       	    get(Fields.In, "FROM_ACCOUNT_").setValue(r, format.trim());
            logBasic("format3: "+format);
           // putRow(data.outputRowMeta,r);
       }

	   putRow(data.outputRowMeta,r);
       return true;
}

5.转换demo下载链接:https://download.csdn.net/download/bastriver/11072483

  直接用Kettle打开就可以了。

 

注:

1. kettle7.1的资源库配置变为灰色,且没有了Connect按钮,应该是repository.xml文件出现了乱码问题。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值