You are not logged in.
Can anyone direct me as how to create an if/esle statement using Talend.
I have an SQL statement that gets the count of the number of fields across several tables and based on this output I want to go 1 of 2 ways.
if count = 0
then proceed with job - loading data into DB
if count > 1
then send message to say DB is not empty.
Getting the counter values if fine and generating the two options is fine however getting it to go down route 1 Vs. route 2 based on a certain values is the problem.
thanks in advance guys,
you can set the count value in a context variable,
where row1 is the rowname and count should be the schema variable (result from the query).
Sorry Lijo I'm sure i'm missing something very obvious but I don't seem to follow what you're telling me. Please see screen shot below to see what I have set up.
I'm not sure what row link option I should be entering in. I've tried a few to no avail, I'm assuming I've left out a component.......or 2
thanks for you help with this.
you can do like
a context variable can be decleared and pass the result into the context variable i.e in tJavaRow
and in the if (context.count==1)
thanks for the extra detail Lijo, unfortunately I still seem to be getting an error. see below.
I have the result of the postgresqlInput being assigned to the context variable that I set up (as an int) and I've also played around with removing the output schema and leaving it in. I don't think the context variable is picking up the output of the SQL query though.
the full error I'm getting is
Starting job mbp_010_upload_staging at 12:08 08/03/2011.
[statistics] connecting to socket on port 3718
Exception in component tJavaRow_1
Job mbp_010_upload_staging ended at 12:11 08/03/2011. [exit code=1]
There are null values coming from your SQL query. Have you declared the counter variable as int
similary the count value coming sql output as int
Can you put the what have you written in the if statement.
I've run the query from the postgresqlInput and it returns 0 if the table is emtpty or the a row count if it's not. I've output this to a tlog to make sure it's pulling back the correct value and it is, it also has no null values being returned.
the output schema of the postgresqlInput is one value called - table_count and it's an integer value
the input schema of the tjava row is - table_count and it's an integer value
I have disabled the output schema of the tjavarow as there is not meant to be any input........is this correct?
I right click on the tjava row and selected the "run if" option. right clicked again and went to settings and entered
I repeated this step, right click on the tjava row and selected the "run if" option. right clicked again and went to settings and entered
I've uploaded 7 images below
1. the output of tPostgresqlInput to the log
2. the schema of tPostgresqlInput
3. the schema and code of the tjavaRow
4. the settings for one of the "run if" statements
5. the context variable declaration
6. the default value assigned to the context variable
7. the error message
thanks for your time with this Lijo, any help is greatly appreciated.
I found out whats the problem, Please remover the ((Integer)globalMap.get(context.counter)==0) and make it to
context.counter==0, no need to give globalmap in case of context variables.
Please correct and let me know any problem.
Last edited by lijolawrance (2011-03-08 16:59:07)