這些例子在(\data-integration\samples\transformations目錄下)
1 JavaScript - Access database connection metadata.ktr(通路資料庫連接配接)
var db = _step_.getTransMeta().findDatabase("db_mysql_etltest_repository_4.2");//db_mysql_etltest_repository_4.2,是自己起的名字,是在資料庫連接配接的時候連接配接名 var url = db.getURL(); var hostname = db.getHostname(); |
文本檔案中的輸出:
url:jdbc:mysql://localhost:3306/etltest_repository4_2?defaultFetchSize=500&useCursorFetch=true hostname:localhost |
2 JavaScript - Access environment variables.ktr(通路環境變量,參數與變量相同)
var v1 = getVariable("VAR1", "啊啊啊啊");//第二個參數表示為空時預設取值 var v2 = getVariable("java.io.tmpdir", ""); |
文本檔案輸出
[email protected] 呵呵@C:\Users\ADMINI~1\AppData\Local\Temp\ |
3 JavaScript - Add 2 and a half seconds to a Date.ktr(時間相加)
var thenInt = now.getInteger()+2500;//ms var then = newjava.util.Date( thenInt ); |
文本檔案輸出:
[email protected]@then 2014/09/23 14:09:40.653@ [email protected]/09/23 14:09:43.153 |
4 JavaScript - Base64 Decoder and Encoder.ktr(64位解碼、編碼)
var bytes = Packages.org.apache.commons.codec.binary.Base64.decodeBase64( F1.getString().getBytes() ); var decString =new Packages.java.lang.String( bytes );//64位解碼器 //編碼器 var encString =new Packages.java.lang.String( Packages.org.apache.commons.codec.binary.Base64.encodeBase64( decString.getBytes() ) ); |
文本檔案輸出:
[email protected]@[email protected] VGV4dCBmaWxlIGlucHV0 @Text file input @"[[email protected]"@VGV4dCBmaWxlIGlucHV0 |
5 (重)JavaScript -create new rows.ktr(建立新的行)
if (groupsField!=null) { var groups = groupsField.split(","); for (i=0;i<groups.length;i++) { newRow = createRowCopy(getOutputRowMeta().size());//新的一行,輸出的列數 var rowIndex = getInputRowMeta().size();//輸入的列數 newRow[rowIndex++] = trim( groups[i] );//對應列的值 newRow[rowIndex++] = "N"; putRow(newRow);//輸出該行 } } var subgroup = "";//對應上面的列名 var ignore = "Y";//對應上面的列名 |
文本檔案輸出:
[email protected]@[email protected] Member 2 @Group1, Group2 @[email protected] Member 2 @Group1, Group2 @[email protected] Member 1 @Group1, Group2, Group3, Group4 @[email protected] Member 1 @Group1, Group2, Group3, Group4 @[email protected] Member 1 @Group1, Group2, Group3, Group4 @[email protected] Member 1 @Group1, Group2, Group3, Group4 @[email protected] |
6 JavaScript - date to string conversion.ktr(日期->字元串)
var datString =date2str(datOriginal, "yyyy**MM**dd hh&&mm&&ss#SSS"); // other date formats can be found in the manual searching for "date formats" // remeber to change to length below of datString if you change the format |
文本檔案輸出:
[email protected] 2007/01/27 00:00:[email protected]**01**27 12&&00&&00#000 |