Tmap and context variable value

Seven Stars

Tmap and context variable value

Hi,

 

I have a job in which I assign a value to two context variable of integer type. I am using tDBInput to retrieve the value from database and tJavaRow to assign it to my context variable . My job is something like this:

 

tDBInput --> tJavaRow1-->tDBInput --> tJavaRow2-->tFileList--->tFileInputPositional-->tMap-->tDBOutput.

 

in tJavaRow1: context.myVar1=input_row.value;

in tJavaRow2: context.myVa2r=input_row.value;

 

In tJavaRow I put a System.out.println(context.myVar1) to verify the value retrieved and it exist. 

The problem is that in tMap I assign context.myVar1 to myColumn, but the result is null. I do not understand the reason. My TMap:

tMap.png

 

 

Does anyone could help me?

Thank you in advance! 

Tags (1)

Accepted Solutions
Community Manager

Re: Tmap and context variable value

This is a timing issue. You need to use a tFlowToIterate in place (or after) your tJavaRow1 and iterate over the next tDBInput calls. For every row the first tDBInput returns, you can guarantee that the rest of the flow will run and finish before the next row is processed. If you are simply assigning a context variable in the first tJavaRow, just replace it with the tFlowToIterate. This will store the whole row as globalMap values. You can use the globalMap value in your tMap at the end

Seven Stars

Re: Tmap and context variable value

I solved it! I was doing integer cast in my ATTR_PROG_ELAB. I retrieved the value I needed a String (without casting) and then in tMap I put ((int)globalMap.get("attr_prog_elab")).


All Replies
Community Manager

Re: Tmap and context variable value

This is a timing issue. You need to use a tFlowToIterate in place (or after) your tJavaRow1 and iterate over the next tDBInput calls. For every row the first tDBInput returns, you can guarantee that the rest of the flow will run and finish before the next row is processed. If you are simply assigning a context variable in the first tJavaRow, just replace it with the tFlowToIterate. This will store the whole row as globalMap values. You can use the globalMap value in your tMap at the end

Seven Stars

Re: Tmap and context variable value

I tried this technique and it is working for the first tFlowTolterate, but not for the 2nd one. I attached my job below:

 

job.pngI got an exception in tMap:

Exception in component tMap_1 (mainImpA_Prodotto_Fasce)
java.lang.NullPointerException

 

Moreover, the value I retrieve from ATTR_PROG_ELAB is of type of String. I need to convert it in integer type. I actually put in tMap ((int)globalMap.get("attr_prog_elab")).

 

How can I solve this?

Seven Stars

Re: Tmap and context variable value

I solved it! I was doing integer cast in my ATTR_PROG_ELAB. I retrieved the value I needed a String (without casting) and then in tMap I put ((int)globalMap.get("attr_prog_elab")).

Community Manager

Re: Tmap and context variable value

Glad you solved it your second issue. Sorry, I wasn't at my machine earlier. You have to be really careful with casting correctly when using the globalMap. Would you mind also accepting my solution to this (you can accept more than one solution) since it was the solution to the initial problem :-)

Cloud Free Trial

Try Talend Cloud free for 30 days.

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.