Printing Your Input and Output Query - TALEND

  • (4.0)
  •   |   802 Ratings

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.

MindMajix Talend Training course is designed to make you an expert in developing ETL solutions using Talend platform. Start Learning! 

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:

Frequently Asked TALEND Interview Questions & Answers

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

Explore TALEND Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

Popular Courses in 2018

Get Updates on Tech posts, Interview & Certification questions and training schedules