Hi all,
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,
Hi Dave, you can set the count value in a context variable, ------if((Integer)globalMap.get(row1.count)==1)---->job1 tOracleInput-- ------if((Integer)globalMap.get(row1.count)>1)------>job2
where row1 is the rowname and count should be the schema variable (result from the query).
Thanks Lijo do I put the if statements you listed below into a tMap or a tJavaRow or some other component? Also will I get two row link options from this componet once I have these if statements listed? regards,
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.
Hi you can do like tPostgreeInput-->tJavaRow---if a context variable can be decleared and pass the result into the context variable i.e in tJavaRow Context.count=input_row.column1; 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.
connecting to socket on port 3718
connected
Exception in component tJavaRow_1
java.lang.NullPointerException
at ripping_files.mbp_010_upload_staging_0_1.mbp_010_upload_staging.tPostgresqlInput_1Process(mbp_010_upload_staging.java:1051)
at ripping_files.mbp_010_upload_staging_0_1.mbp_010_upload_staging$2.run(mbp_010_upload_staging.java:5397)
disconnected
Job mbp_010_upload_staging ended at 12:11 08/03/2011.
Hi 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
((Integer)globalMap.get(context.counter)>0)
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
((Integer)globalMap.get(context.counter)==0)
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.
regards,