• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Assigning values to context variables

#1 2011-03-04 12:55:08

FACE
Guest

Assigning values to context variables

Hi all,

Just wondering if you can help me.

I have a DB with 2 columns in it, "filename" & "sql_statement".

I am reading one row from this DB and I want to assign the output to context variables I have created "con_filename" & "con_contents".

I want to then create a file using the value I have stored in "con_filename" and the file being created should be populated with "con_contents".

At the moment I'm selecting the data from the DB fine using a tPostgresqlInput
I am trying to assign the output to context variables here too using a tJavaRow. tJavaRow contains the following.
//Code generated according to input schema and output schema
output_row.filename = input_row.filename;
output_row.sql_statement = input_row.sql_statement;
context.filename = input_row.filename;
context.sql_statement = input_row.sql_statement;

I am then outputting directly to a tFileOutput but I'm getting both values into the file and a null file name. It appears that the context variables never get set.

How do you assign values to context variables.

Thanks in advance,


Dave

#2 2011-03-04 13:48:53

lijolawrance
Member
Registered: 2010-01-27
Posts: 364

Re: Assigning values to context variables

Hi Dave

how many records are fetched from your DB select query?

If its more than 1, check if the last record gives a null or blank values.

The reason is that you are assigning the values to context in a flow. So for each record processed, the values of context changes.

Hope it helps you.

It will be better if you put a screen shot.


Regards
Lijo Lawrance

Offline

#3 2011-03-05 21:19:22

kzone
Member
Company: Synotis
Registered: 2008-07-06
Posts: 911
Website

Re: Assigning values to context variables

hi,

If you are using context variable to store some value from flow is not a 'best practices' even if it can work wink
as lijolawrance said in fact the only value that you have is the lasted one into your context

For that use globalMap and a flowToIterate to catch value from the flow (have a look into codeViewer to be sure about the name (key map) of globalMap var).
It's always 'rowName.fieldName' (ex : row1.firstName)

hope it help


Uploaded Images


do Svg your graphical language !!!

Offline

#4 2011-03-07 10:47:55

FACE
Guest

Re: Assigning values to context variables

Cheers for getting back to me on it guys.

I'll try using the global variables and will let you know how I get on.


Face

#5 2011-03-07 10:54:38

dgarrigan
Member
Registered: 2011-02-15
Posts: 10

Re: Assigning values to context variables

In reply to your question though LijoLawrance, I am reading in just the one row does this help my cause in making it easier. The value that is being read in is a dynamically changing filename that is created in postgresql.

regards,


Face

Offline

#6 2011-03-07 11:34:24

lijolawrance
Member
Registered: 2010-01-27
Posts: 364

Re: Assigning values to context variables

Hi Face,

You can change to what kzone has told.

In what i have told earlier will fail, if there is any null value (Sorry, i missed it).

But i still feel that u need to have a null check.

Last edited by lijolawrance (2011-03-07 11:53:03)


Regards
Lijo Lawrance

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Assigning values to context variables

Board footer

Powered by FluxBB