cancel
Showing results for 
Search instead for 
Did you mean: 

Need UDF to concatenate using delimiter @

Former Member
0 Kudos

Hi All,

I have below requirement

source structure

Node ( 0 to unbound)

  Field (0 to 1)            this field my come max 6 times i need to concatenate these values using delimiter @ and need to put into single target field.

guys if any one have idea please share it to me.

Thanks in advance.

Regards,

AS

Accepted Solutions (1)

Accepted Solutions (1)

former_member182412
Active Contributor

Hi AS,

You can use below UDF.

Execution type: All values of context.


public void concat(String[] input, ResultList result, Container container) throws StreamTransformationException {

  String output = "";

  boolean first = true;

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

  if (first) {

  output = output + input[i];

  first = false;

  } else {

  output = output + "@" + input[i];

  }

  }

  result.addValue(output);

  }

Mapping is like below:

Field------->removeContexts------>UDF------>Target

Regards,

Praveen.

Former Member
0 Kudos

Hi Praveen,

'class' or 'interface' expected public void init(GlobalContainer container) throws StreamTransformationException{ ^

while using this UDF above above error is getting.

Thanks & Regards,

AS

former_member184720
Active Contributor
0 Kudos

How did you create the UDF. <<Graphical version of praveen's suggestion>>

Former Member
0 Kudos

Thanks a lot Praveen its working

0 Kudos

hi Praveen Gandepalli,

May i know why we have to use this code. and what is the purpose

if(first){output=output+input[i];first= false;}
former_member190293
Active Contributor
0 Kudos

Hi Saikiran!

This code fragment is used to avoid adding delimeter before the first element of the queue.

Regards, Evgeniy.

Answers (1)

Answers (1)

Former Member
0 Kudos

try to use text -> concat function multiple times to achieve the same result.