One Star

[resolved] How to take the value from tHashInput component ?

Hi,
which options we have when we want to fetch value (one db table record fetched using tMysqlInput) from tHashInput component when Talend Job is started in Java application?
I know that we can store that record in some CSV file for example using tFileOutputDelimited and parse the file later, but is there any other options how can fetch this value in Java application without writing record in the file first?
If it is possible, providing small Java snippet of fetching DB record which is stored in tHashInput would be very helpful.
Thanks,
Nenad
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] How to take the value from tHashInput component ?

Hi all,
I found the way to store values from tHashInput component to globalMap object and to fetch these values in Java application.
So after tHashInput component I put tJavaRow component. In tJavaRow component I created new HashMap and inside that map I put db table record. After that I put that HashMap instance to globalMap in the same jJavaRow component.
//Instantiate metadata Map

java.util.Map<java.lang.String, java.lang.Object> docMetadata = new java.util.HashMap<java.lang.String, java.lang.Object>();


//Fetch document metadata and put it in the Map

docMetadata.put("documentID", metadata1.DocumentID);

docMetadata.put("documentName", metadata1.DocumentName);

docMetadata.put("creator", metadata1.Creator);


//Put metadata in global Map

globalMap.put("docMetadata", docMetadata);
metadata1 is connection name from tHashInput component to tJava component.
When I started job in Java application I fetched globalMap using Java reflection.
12 REPLIES
Moderator

Re: [resolved] How to take the value from tHashInput component ?

Hi,
but is there any other options how can fetch this value in Java application without writing record in the file first?

Do you want the Data write model as "Cache in Memory" mentioned in component TalendHelpCenter:/tHashOutput?

Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: [resolved] How to take the value from tHashInput component ?

Hi Sabrina,
thank you for your answer. 
I am already using tHashOutput component to store data in memory and after that tHashInput to read data from memory. This job I started from Java application. But missing part for me is how I can fetch that data from tHashInput component in Java application, is there any method on job object that I can use to fetch that data?
Please note that I am new in Talend and this is my first Talend job. Basically I am reading record from MySQL DB using tMysqlInput , store that result in memory using tHashOutput, fetching that using tHashInput and loging result using tLogRow component. I will attach my job to this post. If you see something that is not logical in design please let me know.
So the question is how I can read tHashInput data in Java application? Please give me example if it is possible.



Thanks,
Nenad
One Star

Re: [resolved] How to take the value from tHashInput component ?

Hi all,
does anybody has solution for this case?
Thanks,
Nenad
One Star

Re: [resolved] How to take the value from tHashInput component ?

What problems are you having with your job?
One Star

Re: [resolved] How to take the value from tHashInput component ?

Hi janhess,
I can start job and in the logs I see results, but how I can take these records in Java application?
I want to take db record and place it in some Map to be able to process it later? What is the right way to do it?
Thanks,
Nenad
One Star

Re: [resolved] How to take the value from tHashInput component ?

just join the tHashInput to a tMap but it would be easier to link the dbinput to a tMap
One Star

Re: [resolved] How to take the value from tHashInput component ?

After tHashInput connection to tMap, how I can fetch that Map in Java code?
I am starting job like this:
FetchDocuments mySQLConnectorJob = new FetchDocuments(); 
mySQLConnectorJob.runJob(new String[]{});
One Star

Re: [resolved] How to take the value from tHashInput component ?

Why not just get the data in the java code?
One Star

Re: [resolved] How to take the value from tHashInput component ?

Client asked Talend to be included in architecture. They want to be able to change some things, so I have to use Talend.
Do you know maybe how I can take values from tMap in Java application? Is there any way to do it?
I just tried to find some getter of tMap in Talend object but without success.
One Star

Re: [resolved] How to take the value from tHashInput component ?

Hi all,
I found the way to store values from tHashInput component to globalMap object and to fetch these values in Java application.
So after tHashInput component I put tJavaRow component. In tJavaRow component I created new HashMap and inside that map I put db table record. After that I put that HashMap instance to globalMap in the same jJavaRow component.
//Instantiate metadata Map

java.util.Map<java.lang.String, java.lang.Object> docMetadata = new java.util.HashMap<java.lang.String, java.lang.Object>();


//Fetch document metadata and put it in the Map

docMetadata.put("documentID", metadata1.DocumentID);

docMetadata.put("documentName", metadata1.DocumentName);

docMetadata.put("creator", metadata1.Creator);


//Put metadata in global Map

globalMap.put("docMetadata", docMetadata);
metadata1 is connection name from tHashInput component to tJava component.
When I started job in Java application I fetched globalMap using Java reflection.
Moderator

Re: [resolved] How to take the value from tHashInput component ?

Hi,
Thanks for posting that you resolved it by yourself.


Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: [resolved] How to take the value from tHashInput component ?

Hi all,
I found the way to store values from tHashInput component to globalMap object and to fetch these values in Java application.
So after tHashInput component I put tJavaRow component. In tJavaRow component I created new HashMap and inside that map I put db table record. After that I put that HashMap instance to globalMap in the same jJavaRow component.
//Instantiate metadata Map

java.util.Map<java.lang.String, java.lang.Object> docMetadata = new java.util.HashMap<java.lang.String, java.lang.Object>();


//Fetch document metadata and put it in the Map

docMetadata.put("documentID", metadata1.DocumentID);

docMetadata.put("documentName", metadata1.DocumentName);

docMetadata.put("creator", metadata1.Creator);


//Put metadata in global Map

globalMap.put("docMetadata", docMetadata);
metadata1 is connection name from tHashInput component to tJava component.
When I started job in Java application I fetched globalMap using Java reflection.

could you explain step by step the procedure that you used with screenshot please?