Skip to Content
avatar image
Former Member

Looking for a help to write UDF for sort and group records from the source

I would like to generate a target structure based on the source. in the source two records with the first 4 fields are same then considered to be header and then remaining are details.in the target two DeviceItems should be generated.the below will be the output.

Could you please provide suggestions for the below udf?

List<String> list = new ArrayList<String>();
StringBuilder sb = new StringBuilder();
String key = "";
for (int i = 0; i < var1.length; i++) {
if (!var1[i].equals(ResultList.CC)) {
sb.setLength(0);
if (key.equals(""))
{
result1.addValue("");
result1.addValue(ResultList.CC);
result2.addValue(var1[i]);
result2.addValue(ResultList.CC);
result3.addValue(var2[i]);
result3.addValue(ResultList.CC);
result4.addValue(var3[i]);
result4.addValue(ResultList.CC);
result5.addValue(var4[i]);
result5.addValue(ResultList.CC);
result6.addValue("");
result7.addValue(var5[i]);
result7.addValue(ResultList.CC);
result8.addValue(var6[i]);
result8.addValue(ResultList.CC);
result9.addValue(var7[i]);
result9.addValue(ResultList.CC);
result10.addValue(var8[i]);
result10.addValue(ResultList.CC);
}
key = sb.append(var1[i]).append(var2[i]).append(var3[i]).append(var5[i]).toString();

if (list.contains(key))
{
//result6.addValue("");
result7.addValue(var5[i]);
result7.addValue(ResultList.CC);
result8.addValue(var6[i]);
result8.addValue(ResultList.CC);
result9.addValue(var7[i]);
result9.addValue(ResultList.CC);
result10.addValue(var8[i]);
result10.addValue(ResultList.CC);

}
else {
list.add(key);
result1.addValue("");
result1.addValue(ResultList.CC);
result2.addValue(var1[i]);
result2.addValue(ResultList.CC);
result3.addValue(var2[i]);
result3.addValue(ResultList.CC);
result4.addValue(var3[i]);
result4.addValue(ResultList.CC);
result5.addValue(var4[i]);
result5.addValue(ResultList.CC);
result6.addValue("");
result7.addValue(var5[i]);
result7.addValue(ResultList.CC);
result8.addValue(var6[i]);
result8.addValue(ResultList.CC);
result9.addValue(var7[i]);
result9.addValue(ResultList.CC);
result10.addValue(var8[i]);
result10.addValue(ResultList.CC);
}
}
}

Thank you

Praveen

hwrwf.png (28.5 kB)
emyxz.png (8.6 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Mar 15 at 09:55 AM

    Hi Praveen!

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Ok, Thank you... How to create a target based on values maintained in the fixed values? this should be happened to the mapping you have mentioned earlier. I tried above , I am unable to do it in the same mapping.

      Thanks

      Praveen

  • Mar 14 at 07:10 AM

    Hi Praveen,

    As per my understanding , it can be achieved using Graphical Mapping only with proper context handling.

    Regards,

    Vivek Jain

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Vivek,

      Thank you, yes I tied with Graphical mapping . in the mapping I have to sort records with first 4 fields, if the 2 records or 3 are same then first 4 fields considered as header and remaining are details.so I have written UDF. can you share your views ? how to sort with combination of 4 fields with Graphical mapping.

      Thank you

      Praveen

  • Mar 14 at 05:46 AM

    Hi Praveen!

    Are you sure that you need UDF to fulfill your requirement?

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Evgeniy,

      Thank you... I am not sure , I have tried with Graphical mapping and then used UDF . I have to sort the records with combination of first 4 fields and then it requires grouping.

      Thanks

      Praveen