10-25-2018 02:25 AM
Like how to get AddressNO group by the same IDs like below?
Solved! Go to Solution.
10-26-2018 09:40 AM
Oh, sorry for the misunderstanding. You want to generate the AddressNO based on the number of elements for each ID?
You’ll have to modify the sort and group by to do so by ID. Then afterwards you’ll need a Mapper snap using the map expression.
$group.map((e, index) => e.extend({'AddressNO': index + 1}))
For each element that was group, this will extend it with the index in the group array.
Finally now that the elements have an AddressNO you can split everything back out using the JSONSplitter snap.
I’ve updated the pipeline so you can try it out yourself.
groupby-example_2018_10_26.slp (8.0 KB)
10-25-2018 07:32 AM
If I understand your question, you’re trying to group your data set by the AddressNO field. That is, the expected output would have all rows with AddressNO equal to one grouped, and all AddressNO equal to two grouped, etc.
If that’s the case, then you’ll need to sort on AddressNO and then use a group by field snap.
Here is the pipeline in my example if you want to upload it and try it out.
groupby-example_2018_10_25.slp (5.1 KB)
10-25-2018 08:25 PM
Yes, I can do a group by, but what I want is to provide the sequence for the rows in one group. The source file only have IDs and address, how to get addressno?
10-26-2018 09:40 AM
Oh, sorry for the misunderstanding. You want to generate the AddressNO based on the number of elements for each ID?
You’ll have to modify the sort and group by to do so by ID. Then afterwards you’ll need a Mapper snap using the map expression.
$group.map((e, index) => e.extend({'AddressNO': index + 1}))
For each element that was group, this will extend it with the index in the group array.
Finally now that the elements have an AddressNO you can split everything back out using the JSONSplitter snap.
I’ve updated the pipeline so you can try it out yourself.
groupby-example_2018_10_26.slp (8.0 KB)
10-29-2018 12:07 AM
Thanks, it’s work