name是变量,value 值也是变量
我需要把name作为变量名,value作为变量值;
在kettle中,使用javascript脚本
key与lastVsxzl都是变量
- //Script here
- setVariable(key,lastVsxzl,'r');
-
- var r=getVariable(key,'r');
1、从记事本里面获取机头号name
2、根据机头号从redis中获取相应的vsxzl值
3、name与vsxzl 成为一个变量,name是变量名,vsxzl是变量值
成功的截图如下




- import redis.clients.jedis.Jedis;
-
- public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
- if (first) {
- first = false;
-
- }
-
- Object[] r = getRow();
-
- if (r == null) {
- setOutputDone();
- return false;
- }
-
- r = createOutputRow(r, data.outputRowMeta.size());
- //1、连接redis
- Jedis jedis = new Jedis("10.20.1.17", 6379);
- //2、获取key值
- String name = get(Fields.In, "name").getString(r);
- boolean exists = jedis.exists(name);
- //2.1、获取上一次的机米长度
- String lastVsxzl = "0";
- if (!exists) {
- jedis.hset(name, "vsxzl", "0");
- } else {
- if (!jedis.hexists(name, "vsxzl")) {
- jedis.hset(name, "vsxzl", "0");
- }
- lastVsxzl = jedis.hget(name, "vsxzl");
- }
- //3、输出key值
- get(Fields.Out, "lastVsxzl").setValue(r, lastVsxzl);
- get(Fields.Out, "key").setValue(r, name+"vsxzl");
- // 关闭连接
- jedis.close();
- // Send the row on to the next step.
- putRow(data.outputRowMeta, r);
-
- return true;
- }

