Mindmajix

Talend – Printing your Input and Output Query

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 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.

Getting ready

Open the job jo_cook_ch07_0050_printOutputSQL, which is a copy of the job from the previous recipe.

How to do it…

The steps to be performed are as follows:

  • Add tJavaRow and link it to tMysqlOutput.
  • Add the following code:
System.out.println(((String)globalMap.get("tMysqlOutput_1_QUERY") ));
  • Run the job. You will see that the output is all null.
  • Open the tMysqlOutput component and click on the Advanced settings
  • Click the field Enable debug mode as shown in the following screenshot:

printing input query

  • Run the job, and you will see the individual SQL statements that were executed.

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.

 


0 Responses on Talend – Printing your Input and Output Query"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.
Course Adviser

Fill your details, course adviser will reach you.