on 03-14-2018 4:18 AM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Evgeniy,
Oh! my good, Thanks for your efforts. you are one of the best developers, I used to read each thread answered by you from SCN.I have done mapping my own. Could you please check and provide your valuable comments?
I would like to just learn myself rather copied. Thank you very much.
Look forward for your comments.
Thanks
Praveen
Step 3: As you could see, I've used one design area to implement the mappings for all target nodes. If you take a look at your Step 1, you'll see that SplitByValue step produces the queue with exactly the same elements count and context changes you need to map to DeviceItems node. So, why not to use it instead of reproducing the same mapping again? 🙂
Regards, Evgeniy.
Hi Evgeniy,
Thank you very much for your time. I have two more things need to added in the mapping.
1.Delete duplicates.
2 Drop records where status are not on the fixed values.
For the above I have created two separate mapping but I would like to create a single mapping and that too give no exception when there are no records.
a) Delete logic
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);
key = sb.append(var1[i]).append(var2[i]).append(var3[i]).append(var4[i]).append(var5[i]).append(var6[i]).append(var7[i]).append(var8[i]).toString();
if (list.contains(key))
result.addSuppress();
else {
list.add(key);
result.addValue("");
}
}
}
a) Drop the records of the statuses not in fixed values.
For the above I have created two separate mappings, Could you please suggest me ? How do I include it into single a mapping?
Thanks
Praveen
Hi Praveen,
As per my understanding , it can be achieved using Graphical Mapping only with proper context handling.
Regards,
Vivek Jain
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Hi Praveen!
Are you sure that you need UDF to fulfill your requirement?
Regards, Evgeniy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.