kettle使用
程序员文章站
2022-04-10 23:40:33
...
1.如果发现表输入乱码,把这里的打勾去掉试一下:
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案例九-----linux使用kettle
下一篇: Linux之大数据集群部署
推荐阅读
-
Android使用TabLayou+fragment+viewpager实现滑动切换页面效果
-
C#使用委托实现的快速排序算法实例
-
Android插件化-RePlugin项目集成与使用详解
-
Android开发中使用外部应用获取SD卡状态的方法
-
Android编程使用光线传感器获取光线强弱的方法【LightSensorManager封装类】
-
SQL Server使用Merge语句当源表数据集为空时,无法进行查询的问题
-
打好"感情牌" 网站设计中如何使用调动用户情绪的好图片?
-
C4D怎么使用FFD效果器变形物体?
-
Java中的OneToMany的使用方法
-
c4d怎么使用刚体标签制作小球体滑落的动画?