2016-03-03 106 views
1

我是Talend的新手,感謝任何幫助。我有一個mysql輸入(tMSSqlInput)與語句:select count(*) as row_count from app.ImportFile a where 1; 從count sql語句設置上下文變量

我想要做的事:做數據庫中的計數語句並分配給變量。

是否設置上下文變量這一下右:

tMSSqlInput ----> if語句(不知道是什麼,包括在這裏)----> tSetGlobalVar

我已閱讀: Setting a database value to context variable in talendHow to set context variable from database但它們是關於具有列名稱的select語句的SQL語句。

謝謝大家。

回答

0
what you can do is below 
tMSSqlInput-->tJavaRow (here you can populate your global variable...lets say your schema column name was row_count then here you can put logic as 
globalMap.put("row_count_received",input_row.row_count); 
and then you can use if conditional subjob trigger 

tMSSQLInput--->tJavaRow 
| 
|if condition --- (((Integer)globalMap.get("row_count_receive"))==1 
V 
do your operation 

similarly you can fork another if statement and where count=0 like above.. 
+0

感謝您的回答,增加了:globalMap.put(「row_count_received」,row3.row_count); System.out.println(「test:」+ row3.row_count);但打印出來是 - >測試:null –

+0

什麼是row3 ...你可以顯示你的工作post image ...也可以在tJavaRow中使用input_row.row_count ... input_row是你可以在tJavarow裏面使用的,不管是什麼傳入的連接名稱。 – garpitmzn

1

相反的tJavaRow,我更喜歡使用tSetGlobalVar代替。這使得它更加清楚你到底想要做什麼:使用來自tMSSQLInput的輸入設置一個全局變量。

tMSSQLInput---main--->tSetGlobalVar 

tSetGlobalVar第一列中,添加你想要的世界地圖變量的名稱,例如「rowCount時」

tSetGlobalVar第二列,你把rown.count,其中「 rown「是來自tMSSQLInput的行的名稱,」count「是在您的tMSQLInput模式中指定的字段的名稱。