cancel
Showing results for 
Search instead for 
Did you mean: 

Grouping nodes

Former Member
0 Kudos

All,

i have this requirement, grouping and producing one subnode if it has same data in it.

My data is

above is the subnode data: is with 0:n occurence

the 1st set is with 1st occurence of parent node, 2nd is 2nd occurence of parent node so forth 4 nodes.

I want the ouput as:

1 occurence: NPWNH, NSTRA, WSTRV  (3 subnodes to be created)

2 occurence: CSTRS  (1 subnode to be created)

3 occurence : NPWNH, NSTRPS, IPWH, NPRLP, NTROWF  (5 subnodes to be created)

4 occurence: CSTRS (1 subnode to be created)

This is not working:

Thank you.

Prema Boodi

Accepted Solutions (1)

Accepted Solutions (1)

former_member184681
Active Contributor
0 Kudos

Hi,

This can be achieved with a simple UDF (assuming input is your input parameters list of type string):

List list = Collections.synchronizedList(new ArrayList());
for (String s : input){
  if (!list.contains(s)) list.add(s);
}
for (int i = 0; i < list.size(); i++) result.addValue(list.get(i));

Then just use: source -> UDF -> target. Most important thing: set the Execution Type of the UDF to "All Values of Context".

Hope this helps,
Greg

Former Member
0 Kudos

Thanks Greg let me try this.

Former Member
0 Kudos

thanks greg.. this helped me to create those nodes.. i want to mark this answered.. but i have one more  rather many more query realted to this..


my requirement now is

INPUT:


buildingGroup1
  leasedeatil
        Building ID= NPWNH

buildingGroup2

  leasedeatil

        Building ID= NPWNH

---------------------------------------

OUPUT should be

buildingGroup

  leasedeatil1

   Building ID= NPWNH

  leasedeatil2

   Building ID= NPWNH


in the below image I'm able to create BuildingGroup if the values(building ID) inside the leasedetails are same . now i want to create as many leasedetails within one buildinggroup if they have same builingID..

former_member184681
Active Contributor
0 Kudos

Hi,

I hope I understood the requirement correctly. I believe here is how you should build the mapping rule for LeaseDetail node:

BuildingGroup -> sortByKey(BuildingID) -> splitByValue(Value Change) -> LeaseDetail

Field -> sortByKey(BuildingID) -> splitByValue(Each Value) -> Field

The rule for "Field" should be applied to each field under LeaseDetail node that you want to map from source to target.

In addition to that, make a small change to the mapping for the initial field. Instead of: BuildingID -> UDF -> target, use BuildingID -> sort -> UDF -> target. So sort function is what you need to add there to have it working fine all together.

Hope this helps,

Greg

Former Member
0 Kudos

Thanks so much for your help! I appreciate your time.

this resolved all my issues with combination of your java UDF above.

Answers (4)

Answers (4)

Former Member
0 Kudos

Dear Prema

Before sort have a remove context also.

Regards

Monika

former_member184681
Active Contributor
0 Kudos

Hi Ankit Soni, solasu bhavanisankar,

I believe none of your suggestions will work as required. As Prema Boodi said, it is required to have 4 separate contexts, each of them having only unique values. I think this is only possible with a UDF, like the one I provided.

Regards,
Greg

Former Member
0 Kudos

y try below one:

field -> remove context -> sort -> splitByVAlue(Value change)-> collapse ontext -> Target field

Former Member
0 Kudos

this also gave me all values for only one parent node. rest parent nodes are blank

Former Member
0 Kudos

Dear Prema

I did something like this some time back

Former Member
0 Kudos

Hi,

I guess you should remove Split by value(each value) after collapse context and instead use remove context there if you want all the subnodes together or don't use anything after collapse context. Directly map Collapse context to target node. It should work as per your requirement.

Hope this helps,

Ankit

Former Member
0 Kudos

no i dont want everything under same node..  these are with respect to each parent node, needs to be treated different.