Expert Consultancy from Yellow Pelican

Talend globalMap Reference

A site about Talend

Talend globalMap Reference

Talend provides the globalMap Object where both Talend and you can store and retrieve data. This is a great place to create your global variables as well as retrieving important information about your executing Job.

globalMap is my preference for storing global data that is specific to a particular Job. This is in preference to Context Variables. This removes any blurring of global variables versus parameters that may be passed to your Job at runtime.

Talend defines globalMap as: -

private final java.util.Map globalMap = new java.util.HashMap();

A Simple Example of Using globalMap

As your Job runs, information is collected about the execution of the various Components. Talend makes this information available through globalMap. A crude but easy way to see this information is to add a tJava component to the end of your job and to add the following line of code.

System.out.println(globalMap.toString().replaceAll(",", "\n"));

The component tFileExists is used to find out if a file exists; but how do you interrogate it for the answer? As is often the case, you do this through globalMap.

(Boolean) globalMap.get("tFileExist_1_EXISTS")

Using globalMap for Global Storage

We've just introduced the get method. You get an object from globlMap and cast it to the correct Type. You can, of course, also put your own objects on globalMap.

globalMap.put("myObject", "Hello World!");
System.out.println((String) globalMap.get("myObject"));

You may also use the component tSetGlobalVar for setting Global Variables - that is, adding values to globalMap.

Further Reading

For more information on the Java Map Interface, visit Java Map Interface.

Expert Consultancy from Yellow Pelican
comments powered by Disqus