|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
[DELETE] Duplicate Field |
« View previous topic :: View next topic » |
Author |
Message
|
anon_kb |
Posted: Fri Feb 19, 2016 3:38 am Post subject: [DELETE] Duplicate Field |
|
|
Acolyte
Joined: 13 Nov 2014 Posts: 74
|
Hi all,
I just want to ask about deletion of duplicate field and retain one only. Anyway I have this structure
Code: |
[b]Input[/b]
<detail>
<LineNumber>1</LineNumber>
</detail>
<detail>
<LineNumber>1</LineNumber>
</detail>
<detail>
<LineNumber>1</LineNumber>
</detail>
<detail>
<LineNumber>2</LineNumber>
</detail>
[b]Output[/b]
<detail>
<LineNumber>1</LineNumber>
</detail>
<detail>
<LineNumber>2</LineNumber>
</detail> |
So far I've used this code
Code: |
For source AS Environment.Variables.Temp[] DO
IF source.LineNumber = Input.Detail[count] THEN
DELETE FIELD Input.Detail
END IF
SET count = count + 1
END FOR; |
Code above deletes all Details with same LineNumber
Tried to use this
Code: |
For source AS Environment.Variables.Temp[] DO
IF source.LineNumber = Input.Detail[count] THEN
DELETE FIELD Input.Detail[count]
END IF
SET count = count + 1
END FOR; |
It retain 1 Detail on the duplicates but it deleted the detail with no Duplicate.
Note: No debugging option here. I'm just doing this trial - comment - error debugging.
Thanks |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Feb 19, 2016 5:21 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
instead of using a counter, use 2 references.
Assuming that your list is sorted...
Compare the references:
- Check for 1st row, move current row ref to start at row 2. Enter loop.
- check current row with previous row ref. If the references are the same delete current row. Move current row reference to next sibling of previous row. Loop.
- current row ref does not match previous row ref. Move previous row to current row, move current row to next sibling. Loop
Happy coding  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Feb 19, 2016 7:13 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
There's a quicksort in esql implementation here somewhere, in case your tree is not sorted, either. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
anon_kb |
Posted: Tue Feb 23, 2016 4:14 am Post subject: |
|
|
Acolyte
Joined: 13 Nov 2014 Posts: 74
|
fjb_saper wrote: |
instead of using a counter, use 2 references.
Assuming that your list is sorted...
Compare the references:
- Check for 1st row, move current row ref to start at row 2. Enter loop.
- check current row with previous row ref. If the references are the same delete current row. Move current row reference to next sibling of previous row. Loop.
- current row ref does not match previous row ref. Move previous row to current row, move current row to next sibling. Loop
Happy coding  |
My tree is not sorted after I build it. So do i have to sort it first? |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Feb 23, 2016 6:04 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
It would help if it were, but there are techniques that will allow you to do this on an unsorted tree... The algorithm just gets a little bit more complicated because it will now involve a lookup function to determine whether you already have the tag, with a corollary to save the tag in a lookup environment if it is the first time you encounter it...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|