欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

kettle使用

程序员文章站 2022-04-10 23:40:33
...

1.如果发现表输入乱码,把这里的打勾去掉试一下:

kettle使用

2.kettle使用java脚本加载缓存代码

2.1 读取数据库,放入缓存代码:

import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
// 注意导包
import com.ywhz.framework.cache.KettleCacheMap;
import com.ywhz.framework.cache.CacheDto;
import org.pentaho.di.core.database.Database;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.core.Const;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
    if (first){
      first = false;
    }

    Object[] r = getRow();

    if (r == null) {
      setOutputDone();
      return false;
    }
    //获取要翻译字典的代码
	String TYPE = get(Fields.In, "TYPE").getString(r);
	String RES_CODE = get(Fields.In, "RES_CODE").getString(r);
	String CODE = get(Fields.In, "CODE").getString(r);
	String NAME = get(Fields.In, "NAME").getString(r);
	String DATAKEY = get(Fields.In, "DATAKEY").getString(r);
	String ARRCODE = get(Fields.In, "ARRCODE").getString(r);
   
    // It is always safest to call createOutputRow() to ensure that your output row's Object[] is large
    // enough to handle any new fields you are creating in this step.
    r = createOutputRow(r, data.outputRowMeta.size());
	
	CacheDto dto = new CacheDto();
   	dto.setType(TYPE);
	dto.setResCode(RES_CODE);
	dto.setCode(CODE);
	dto.setName(NAME);
	dto.setDatakey(DATAKEY);
	dto.setArrcode(ARRCODE);
	KettleCacheMap.kettleCacheMap.put(TYPE+"_"+RES_CODE,dto);
   
    putRow(data.outputRowMeta, r);

    return true;
}

public boolean init(StepMetaInterface stepMetaInterface, StepDataInterface stepDataInterface)
{
    return parent.initImpl(stepMetaInterface, stepDataInterface);
    
}

2.2 读取缓存并转换输入流的内容代码:

import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.ywhz.framework.cache.KettleCacheMap;
import com.ywhz.framework.cache.CacheDto;
import org.pentaho.di.core.database.Database;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.core.Const;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
  if (first) {
    first = false;

  }

  Object[] r = getRow();

  if (r == null) {
    setOutputDone();
    return false;
  }

  // It is always safest to call createOutputRow() to ensure that your output row's Object[] is large
  // enough to handle any new fields you are creating in this step.
  r = createOutputRow(r, data.outputRowMeta.size());

  /* TODO: Your code here. (See Sample)

  // Get the value from an input field
  String foobar = get(Fields.In, "a_fieldname").getString(r);

  foobar += "bar";
    
  // Set a value in a new output field
  get(Fields.Out, "output_fieldname").setValue(r, foobar);

  */
	String UNIT_CODE = get(Fields.In, "UNIT_CODE").getString(r);//单位编码
	CacheDto unit = (CacheDto)KettleCacheMap.kettleCacheMap.get("AGENCY_MAP_"+UNIT_CODE);

	if(null != unit){
		get(Fields.Out, "UNIT_ID").setValue(r, unit.getDatakey());//单位ID
		get(Fields.Out, "UNIT_NAME").setValue(r, unit.getName());//单位名称
		get(Fields.Out, "ARRCODE").setValue(r, unit.getArrcode());//单位arrcode
	}

  // Send the row on to the next step.
  putRow(data.outputRowMeta, r);

  return true;
}

相关标签: kettle