Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
WSyahirah21
Creator
Creator

Iterate the result from tSYstem in tJava

I am currently trying to loop the result i fetched from tSystem using tJava. My workflow is:

0695b00000SsjB4AAJ.png 

Result from tSystem (Note : The result is much more than in example below) :

 

Ingestion table_202207

{'Destination TblName': u'table_202207', Execution time': 112.25, 'Ingested rows': 0}

End_table_202207

 

Ingestion table_202208

{'Destination TblName': u'table_2022078, Execution time': 2.20, 'Ingested rows': 764}

End_table_202208

....

 

In tJava:

String output=((String)globalMap.get("tSystem_3_OUTPUT"));

System.out.println("OUTPUT FROM TSYSTEM_3: "+output);

String json_output=StringUtils.substringBetween(output,"ngestion table, "End_table");

System.out.println(json_output);

//for (String i : json_output) {

//  System.out.println(i);

//}

 

 

I am quite confused how should I get the value from tSystem and and loop for between string Ingestion-somedate and End_table_somedate.n

Labels (2)
4 Replies
Anonymous
Not applicable

Hi

What's the output of ((String)globalMap.get("tSystem_3_OUTPUT"))? can you show an example?

what are your expect result?

 

Regards

Shong

WSyahirah21
Creator
Creator
Author

Hi Shong,

 

Currently im trying to get the data value for multiple table using loop function using tJavaFlex in talend. The result of variable string ingestTbl in below command is:

 

{'Source rows': 818113, 'Destination rows': 548940}

{'Source rows': 224, 'Destination rows': 5445}

{'Source rows': 57675, 'Destination rows': 57567}

 

tJavaFlex command:

 

for (int i = 0,; i< strArray.length; i++){  

  String ingestTbl=StringUtils.substringBetween(output,"Ingestion Stats for Table "+strArray[i], "End_"+strArray[i]);   

  System.out.println(ingestTbl);

 

JSONObject jsonObject = new JSONObject(ingestTbl);

 

String sourceRowCount=(jsonObject.getString("Source rows"));

String destinationRowCount=(jsonObject.getString("Destination rows"));

 

globalMap.put("source_row",sourceRowCount);

globalMap.put("destination_row",destinationRowCount.trim());

}  

 

However, in code JSONObject jsonObject = new JSONObject(ingestTbl);, i received error:

0695b00000SsrszAAB.png 

What should I do to loop the result from ingestTbl to jsonObject so that I can bring the result for further process?

 

Anonymous
Not applicable

It is a compilation error, output cannot be resolved to a variable in this line:

​String ingestTbl=StringUtils.substringBetween(output,"Ingestion Stats for Table "+strArray[i], "End_"+strArray[i]);  

Why don't you use tWriteJsonField if you want to generate a Json string?

 

WSyahirah21
Creator
Creator
Author

Hi,

 

I dont think that issue come from that variable. as if I run that line itself, it outputs.

table 1 {'Source rows': 818113, 'Destination rows': 548940} - for all table with respective result.

 

Next step is to convert the string result to jsonObj and use globalMap to fetch the result.

From ingestTbl result, is there any way to use substringBetween?