One Star

Java version how to use tHash

Hello ,

How to use the tHash component in Java version of talend. I have a thash which get filled up and the name is tHash_1. How can I use this in a later component say a tJavaRow or a tJavaMap. When I use tHash_1.containsKey() it gives me compilation error saying tHash_1 is not defined.
With Best regards

Re: Java version how to use tHash

If you want to access data of a tHash component, use this syntax before accessing it :

java.util.Map myTHash = (java.util.Map) globalMap.get( "myTHash" );
boolean containsKey = tHash_1.containsKey(myKey);

In order to use our product, we don't advise to use this above code because the internal architecture can change again.
Therefore, in the tMap, the lookups are hidden tHash, so adding a tHash to a lookup tMap could be redundant.

One Star

Re: Java version how to use tHash

Hello . I tried this. But is not working. My THash name was THash_2 and tried to get from global map but was not working. Looked at the code generated and saw that it was tHash_row6 that was being put in to global map. Tried to get that and process but still was not working. I need to use the THash for the following reason
I have a table where I have the prfixes and the id defined. For example
9845 1
9846 2
98451 3
995 4

Now when I read a file I will get a phone number of the form 98451234 . I will have to decide which id it belongs to. I will have to get the most appropriate suffix and get the ID for that. Here the most appropriate prefix is 98451 and hence the ID will be 3. If the phone number was 984501234 the ID would have been 1. So for getting this done I will need a tHash where I put the data and check for the appropriate prefix. If there is any other way of doing it please tell me.
With Best Regards