• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » tJavaRow Syntax help needed

#1 2010-09-08 16:16:48

mrsocks
Member
Registered: 2009-12-08
Posts: 57

tJavaRow Syntax help needed

Hello,


I have a dbInput -> tJavaRow -> tMap ->dbOutput

In the tJavaRow, I want to check the value of a column and if it's value is 3 or 4, replace that with NULL.

Here is what I am trying, bet getting a NullPointerException:

if (input_row.fromUserId.equals(null)) {
    output_row.fromUserId = null;
} else if (input_row.fromUserId.equals(3)) {
    output_row.fromUserId = null;
} else if (input_row.fromUserId.equals(4)) {
    output_row.fromUserId = null;
} else {
    output_row.fromUserId = input_row.fromUserId;
}

This does not seem to be working as expected, does this look correct?
Thanks.

Offline

#2 2010-09-08 17:43:04

emaxt6
Member
Registered: 2008-08-04
Posts: 325

Re: tJavaRow Syntax help needed

if (input_row.fromUserId == null) {
...

Offline

#3 2010-09-09 14:28:43

Diego
New member
Registered: 2010-09-09
Posts: 6

Re: tJavaRow Syntax help needed

Hello, mrsocks.
No, this is not correct.
If "input_row.fromUserId" is String, you have to use "" in the param. Like this:

if(input.equals("null")||input.equals("3")||input.equals("4"))
       {
           input = "null";
       }
       else
       {
           input = input;
       }

Try it!

Offline

#4 2010-09-09 14:45:30

mrsocks
Member
Registered: 2009-12-08
Posts: 57

Re: tJavaRow Syntax help needed

Thanks, I will give it a shot!

Offline

#5 2010-09-09 15:14:48

mrsocks
Member
Registered: 2009-12-08
Posts: 57

Re: tJavaRow Syntax help needed

Diego wrote:

Hello, mrsocks.
No, this is not correct.
If "input_row.fromUserId" is String, you have to use "" in the param. Like this:

if(input.equals("null")||input.equals("3")||input.equals("4"))
       {
           input = "null";
       }
       else
       {
           input = input;
       }

Try it!

the input is an Integer, so I will leave out the double quotes, correct?

Also,
you have 'input = input;' as the result. Is that correct? I would expect it to be 'output = input;' OR 'output = null;'
Which would actually be correct? If yours, then do I still include:
'output_row.fromUserId  = input_row.fromUserId'; after this IF ELSE ?

Thanks.

Offline

#6 2010-09-10 13:53:10

Diego
New member
Registered: 2010-09-09
Posts: 6

Re: tJavaRow Syntax help needed

No, if the input is an Integer, You will haven't the double quotes. Double quotes You will use when the param is  a string.
Check the input default in dbInput is a null value or  ""   (empty) and post it.
About my code, the result is wrong. The correct is output = input.

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » tJavaRow Syntax help needed

Board footer

Powered by FluxBB