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.
Getting ready
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
fromtMysqlInput
totJava
.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…
As we have seen in other recipes, 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.