Printing your input query
If your result set isn’t as expected and you are struggling to understand why, then it is really useful to be able to see the QUERY that was executed to give you the result. This recipe shows how this can be done.
Open the job jo_cook_ch07_0030_printInputQuery, which is a copy of the job from the previous recipe.
How to do it…
The steps to be performed are as follows:
Add a tJava component.
Add OnSubjobOk from tMysqlInput to tJava.
Open tJava and add the following line:
System.out.println("nExecuted query: n"+ ((String)globalMap.get("tMysqlInput_1_QUERY")));
Run the job, and you will see the query as it was sent to the database.
How it works…
Many of the Talend components will drop information to globalMap, for use by downstream components/subjobs.
In the case of tMysqlInput, one of the values written to globalMap is the query that was used to produce the result set, which is what we printed in the tJava component.
Printing your output QUERY
This recipe shows how to achieve an update, delete, or insert, which are all functions available through tMysqlOutput.
Open the job jo_cook_ch07_0050_printOutputSQL, which is a copy of the job from the previous recipe.
Add tJavaRow and link it to tMysqlOutput.
Add the following code:
Run the job. You will see that the output is all null.
Open the tMysqlOutput component and click on the Advanced settings
How it works…
Before using a tMysqlOutput component, you must first set the Mode to Debug in the Advanced tab for the component. This will allow you to capture the query for every row written to the table.
Click here for related Article: https://goo.gl/4ACAqL
RememberTo make recommendations or participate please Sign In and post a message.