cancel
Showing results for 
Search instead for 
Did you mean: 

Need UDF for concatnating three fields

Former Member
0 Kudos
114

hi all,

need java coding concatnating three fields , please help me as i dont know java

thanking you

Sridhar

Accepted Solutions (0)

Answers (4)

Answers (4)

sunil_singh13
Active Contributor
0 Kudos

Hi Sridhar,

use following code

public void calculate(String[] var1, ResultList result, String[] var2, String[] var3, String[] var4, String[] var5, String[] var6, String[] var7, String[] var8, String[] var9, String[] var10, String[] var11, Container container) throws StreamTransformationException{

for(int i = 0 ; i < var1.length;i++)

{

if (var1<i>.equals("true"))

result.addValue(var11<i>+ var2<i>var3<i>var4<i>var5<i>var6<i>var7<i>var8<i>var9<i>var10<i>);

else

result.addValue(ResultList.SUPPRESS);

}

}

while creating this UDF:

Select Execution Type as "All values of Queue" (you will see this option when you go for creating UDF)

In signature Variable Declare 11 variable 1st will hold true or false and rest will be for concatination

First input is output of comaparison ("WE")

Now var1 will hold the output of comaparison. if it is true it will concate 10 value if false it will pass suppress (Same as if withoutelse)

Thanks

Sunil Singh

Former Member
0 Kudos

Here I have used it for checking 3 nodes. The logic behind the code is that if all the 3 nodes exist, then it will concatenate all the three fields and produce the result node, if any one of them doesnt exist, then it will concatenate only the remaining fields.

try{

if(a.length != 0 && b.length != 0 && c.length != 0)

result.addValue (a[0] + b[0] + +c[0]);

else {

if(a.length == 0 && b.length != 0 && c.length != 0)

result.addValue( b[0] + c[0]);

if(a.length != 0 && b.length == 0 && c.length != 0)

result.addValue(a[0] + c[0]);

if(a.length != 0 && b.length != 0 && c.length == 0)

result.addValue(a[0] + b[0]);

}

}catch (ArrayIndexOutOfBoundsException e)

{

result.addSuppress();

}

Edited by: Sainath Chutke on Jan 29, 2009 10:36 AM

Former Member
0 Kudos

Refer your previous thread, I have given the UDF for same. But if you want something else then provide your exacat porblem with a good example to get the solution.

Why are you not using Standard Function?

Regards,

Sarvesh

SudhirT
Active Contributor
0 Kudos

Why do you want to use java UDF just for concatenating. Use standard concat function in Graphical mapping Text function.

Thanks!

Former Member
0 Kudos

no i have 10 fields to concatenate , and i am getting value suppressed , due to context

so only using UDF to by pass this one

Former Member
0 Kudos

> no i have 10 fields to concatenate , and i am getting value suppressed , due to context

> so only using UDF to by pass this one

Have you tried the UDF to concatenate 10 fields. (Since you don't know java, plz don't be confuse with pluse sign in the given udf it is used for conactenate the values). See the below thread

Regards,

Sarvesh

SudhirT
Active Contributor
0 Kudos

For all the 10 fields you can use mapWithDefault function after each fields and then pass the output as input to concat function. like

field1---->mapwithDefault--->
                                        Concat----------------------------------------------------------->Concat
Field2--->MapwithDefault---->                   field3-->mapwithdefault-------------->

try this till all 10 fields.

Thanks!