Calculated new field

One Star

Calculated new field

I need to create a new field to indicate BUY, New BUY or Sell, New SELL depending on the fields ordtype and liq .
eg. if ordtype = 1 AND liq>0 then "buy" else if ordtype = 1 ANd liq = 0 then "new buy"if ordtype = 2 And liq >0 then = "sell" else if ordtype 2 ANd liq =0 then = "new sell ".
how do this during mapping?
Community Manager

Re: Calculated new field

Hi
The expression look like:
row1.ordtype==1&&row1.liq>0?"buy"Smiley Sadrow1.ordtype==1&&row1.liq==0?"new buy"Smiley Sadrow1.ordtype==2&&row1.liq>0?"sell":"new sell"))
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Calculated new field

oh i got this error Exception in thread "main" java.lang.Error: java.lang.Error: java.lang.Error: Unresolved compilation problems:
Incompatible operand types String and int
Incompatible operand types String and int
Incompatible operand types String and int

i think i because ordtyp is a string and liq is a int
Seven Stars

Re: Calculated new field

Then modify shong's expression to:
row1.ordtype.equals("1")&&row1.liq>0?"buy"Smiley Sadrow1.ordtype.equals("1")&&row1.liq==0?"new buy"Smiley Sadrow1.ordtype.equals("2")&&row1.liq>0?"sell":"new sell"))
although I would use the expression:
(row1.liq==0?"new ":"")+(row1.ordtype.equals("1")?"buy":"sell")
Community Manager

Re: Calculated new field

Hi alevy
although I would use the expression:
(row1.liq==0?"new ":"")+(row1.ordtype.equals("1")?"buy":"sell")

Good expression, it is short and simple.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business