Kettle 使用JS脚本 增加UUID输出列

Kettle 使用JS脚本 增加UUID输出列_第1张图片
image.png
Kettle 使用JS脚本 增加UUID输出列_第2张图片
image.png
####JavaScript 脚本如下####################################################

//Script here
//Script here

function UUID(){  
    this.id = this.createUUID();  
}  
  
UUID.prototype.valueOf = function(){ return this.id; }  
UUID.prototype.toString = function(){ return this.id; }  
  
UUID.prototype.createUUID = function(){  
    var dg = new Date(1582, 10, 15, 0, 0, 0, 0);  
    var dc = new Date();  
    var t = dc.getTime() - dg.getTime();  
    var h = '';  
    var tl = UUID.getIntegerBits(t,0,31);  
    var tm = UUID.getIntegerBits(t,32,47);  
    var thv = UUID.getIntegerBits(t,48,59) + '1';  
    var csar = UUID.getIntegerBits(UUID.rand(4095),0,7);  
    var csl = UUID.getIntegerBits(UUID.rand(4095),0,7);  
  
    var n = UUID.getIntegerBits(UUID.rand(8191),0,7) +   
            UUID.getIntegerBits(UUID.rand(8191),8,15) +   
            UUID.getIntegerBits(UUID.rand(8191),0,7) +   
            UUID.getIntegerBits(UUID.rand(8191),8,15) +   
            UUID.getIntegerBits(UUID.rand(8191),0,15);   
    return tl + h + tm + h + thv + h + csar + csl + h + n;   
}  
  
UUID.getIntegerBits = function(val,start,end){  
    var base16 = UUID.returnBase(val,16);  
    var quadArray = new Array();  
    var quadString = '';  
    var i = 0;  
    for(i=0;i= base) var output = this.returnBase(MSD,base) + convert[LSD];  
        else var output = convert[MSD] + convert[LSD];  
    }  
    return output;  
}  
  
UUID.rand = function(max){  
    return Math.floor(Math.random() * max);  
}  
  
var ID=new UUID().id;  

##############################################################

测试数据如下:

Kettle 使用JS脚本 增加UUID输出列_第3张图片
image.png

你可能感兴趣的:(Kettle 使用JS脚本 增加UUID输出列)